tilde~
Puredata Qt-based GUI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OOPD.h
Go to the documentation of this file.
1 // License: GPL3
2 //
3 // OOPD.h
4 //
5 //
6 // Created by Alex Nadzharov on 26/03/17.
7 //
8 //
9 
10 #ifndef OOPD_h
11 #define OOPD_h
12 
13 #include "m_pd.h"
14 #include <map>
15 #include <set>
16 
17 
18 //
19 #include <QDebug>
20 #include <QStringList>
21 
22 using namespace std;
23 //using namespace ceammc;
24 
25 namespace tilde {
26 
27 // ------------------------------------------------------------
28 // typedefs
29 
30 class OPClass;
31 class OPInstance;
32 
33 //todo class or move to find section
34 typedef map<t_canvas*, OPClass*> t_OPClassByCanvas;
35 typedef map<t_symbol*, OPClass*> t_OPClassBySymbol;
36 typedef map<string, OPClass*> t_OPClassByName;
37 typedef map<t_canvas*, OPInstance*> t_OPInstanceByCanvas;
38 typedef map<t_symbol*, OPInstance*> t_OPInstanceBySymbol;
39 
40 typedef set<OPInstance*> t_existingInstances;
41 
42 //typedef vector<t_outlet*> OPOutputs; ///< vector of method boxes outputs
43 typedef vector<t_object*> OPProperties;
44 
45 // ------------------------------------------------------------
46 
51 class OOPD {
52 private:
53  t_OPClassByCanvas _classByCanvas;
54  t_OPClassBySymbol _classBySymbol;
55  t_OPClassByName _classByName;
56  t_OPInstanceByCanvas _instanceByCanvas;
57  t_OPInstanceBySymbol _instanceBySymbol;
58  t_existingInstances _existingInstances;
59 
60  OOPD(){};
61 
62 public:
63  static OOPD* inst()
64  {
65  static OOPD* instance;
66 
67  if (!instance)
68  instance = new OOPD;
69 
70  return instance;
71  }
72 
73  void registerClass(OPClass* opClass, string className, t_canvas* canvas, t_symbol* symbol)
74  {
75  qDebug() << "class : OOPD" << (long)this << (long)canvas;
76  _classByCanvas[canvas] = opClass;
77  _classBySymbol[symbol] = opClass;
78  _classByName[className] = opClass;
79  };
80 
81  void registerInstance(OPInstance* opInstance, string className, t_canvas* canvas, t_symbol* symbol)
82  {
83  qDebug() << "inst : OOPD" << (long)this << (long)canvas;
84  _instanceByCanvas[canvas] = opInstance;
85  _instanceBySymbol[symbol] = opInstance;
86 
87  _existingInstances.insert(opInstance);
88  };
89 
90  void unregisterClass(OPClass* opClass, string className, t_canvas* canvas, t_symbol* symbol){
91 
92  };
93  void unregisterInstance(OPInstance* opInstance, string className, t_canvas* canvas, t_symbol* symbol)
94  {
95  _instanceByCanvas[canvas] = 0;
96  _instanceBySymbol[symbol] = 0;
97 
98  // todo remove
99  //_existingInstances.find()
100  };
101 
103  {
104  if (_classByCanvas[canvas])
105  return _classByCanvas[canvas];
106  else
107  return 0;
108  }
109 
111  {
112  if (_classBySymbol[symbol])
113  return _classBySymbol[symbol];
114  else
115  return 0;
116  }
117 
118  OPClass* classByName(string className)
119  {
120  if (_classByName[className])
121  return _classByName[className];
122  else
123  return 0;
124  }
125 
127  {
128  if (_instanceByCanvas[canvas])
129  return _instanceByCanvas[canvas];
130  else
131  return 0;
132  }
133 
135  {
136  if (_instanceBySymbol[symbol])
137  return _instanceBySymbol[symbol];
138  else
139  return 0;
140  }
141 
143  {
144  return (_existingInstances.find(inst) != _existingInstances.end());
145  }
146 
147  bool canvasIsPatch(t_canvas* canvas)
148  {
149  return !(classByCanvas(canvas) || instanceByCanvas(canvas));
150  }
151 };
152 }
153 
154 #endif /* OOPD_h */
OPClass * classBySymbol(t_symbol *symbol)
Definition: OOPD.h:110
void unregisterInstance(OPInstance *opInstance, string className, t_canvas *canvas, t_symbol *symbol)
Definition: OOPD.h:93
void unregisterClass(OPClass *opClass, string className, t_canvas *canvas, t_symbol *symbol)
Definition: OOPD.h:90
OPInstance * instanceByCanvas(t_canvas *canvas)
Definition: OOPD.h:126
map< t_symbol *, OPInstance * > t_OPInstanceBySymbol
Definition: OOPD.h:38
#define t_canvas
Definition: m_pd.h:205
set< OPInstance * > t_existingInstances
Definition: OOPD.h:40
OPClass * classByCanvas(t_canvas *canvas)
Definition: OOPD.h:102
void registerInstance(OPInstance *opInstance, string className, t_canvas *canvas, t_symbol *symbol)
Definition: OOPD.h:81
stores global information about OOPD classes / instances
Definition: OOPD.h:51
bool canvasIsPatch(t_canvas *canvas)
Definition: OOPD.h:147
bool instanceExists(OPInstance *inst)
Definition: OOPD.h:142
map< string, OPClass * > t_OPClassByName
Definition: OOPD.h:36
map< t_symbol *, OPClass * > t_OPClassBySymbol
Definition: OOPD.h:35
static OOPD * inst()
Definition: OOPD.h:63
OOPD * instance
Definition: OOPD.cpp:20
OOPD class structure.
Definition: OPClass.h:38
Definition: oop_common.h:81
Definition: m_pd.h:110
The OOPD class instance.
Definition: OPInstance.h:44
void registerClass(OPClass *opClass, string className, t_canvas *canvas, t_symbol *symbol)
Definition: OOPD.h:73
map< t_canvas *, OPInstance * > t_OPInstanceByCanvas
Definition: OOPD.h:37
vector< t_object * > OPProperties
vector of property boxes
Definition: oop_common.h:72
OPClass * classByName(string className)
Definition: OOPD.h:118
map< t_canvas *, OPClass * > t_OPClassByCanvas
Definition: OOPD.h:31
OPInstance * instanceBySymbol(t_symbol *symbol)
Definition: OOPD.h:134