OpenLexocad  27.1
PropertyMacros.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <string>
5 
6 #define LX__QUOTE(str) #str
7 
8 // FIXME: document. 20000103 mortene.
9 #define LX_NODE_HEADER() \
10 public: \
11  static void lx_field_init(); \
12 \
13 protected: \
14  static const Core::LxFieldData** getFieldDataPtr(void); \
15  virtual const Core::LxFieldData* getFieldData(void) const; \
16  virtual const Core::LxFieldData* getParentFieldData(void) const; \
17 \
18 private: \
19  static const Core::LxFieldData** parentFieldData; \
20  static Core::LxFieldData* fieldData; \
21  static unsigned int classinstances; \
22  static bool lxFieldIsInit;
23 
24 #define LX_NODE_ABSTRACT_SOURCE(_class_) \
25 \
26  unsigned int ::_class_::classinstances = 0; \
27  const Core::LxFieldData** ::_class_::parentFieldData = (const Core::LxFieldData**)0xdeadbeefLL; \
28  Core::LxFieldData* ::_class_::fieldData = NULL; \
29  bool ::_class_::lxFieldIsInit = false; \
30 \
31  const Core::LxFieldData** _class_::getFieldDataPtr(void) { return const_cast<const Core::LxFieldData**>(&::_class_::fieldData); } \
32 \
33  const Core::LxFieldData* _class_::getFieldData(void) const { return ::_class_::fieldData; } \
34 \
35  const Core::LxFieldData* _class_::getParentFieldData(void) const { return *(::_class_::parentFieldData); }
36 
37 #define LX_INIT(_class_, _parentclass_) \
38  void _class_::lx_field_init() \
39  { \
40  ::_class_::parentFieldData = ::_parentclass_::getFieldDataPtr(); \
41  ::_class_::lxFieldIsInit = true; \
42  }
43 
44 #define LX_INIT_NO_PARENT(_class_) \
45  void _class_::lx_field_init() \
46  { \
47  _class_::parentFieldData = 0; \
48  _class_::lxFieldIsInit = true; \
49  }
50 
51 #define LX_NODE_SOURCE(_class_, _parentclass_) \
52  LX_NODE_ABSTRACT_SOURCE(_class_) \
53  LX_INIT(_class_, _parentclass_)
54 
55 #define LX_NODE_SOURCE_NO_PARENT(_class_) \
56  LX_NODE_ABSTRACT_SOURCE(_class_) \
57  LX_INIT_NO_PARENT(_class_)
58 
59 
60 #define LX_NODE_CONSTRUCTOR(_class_) \
61  do \
62  { \
63  ::_class_::classinstances++; \
64  /* Catch attempts to use a node class which has not been initialized. */ \
65  /* assert(_class_::classTypeId != SoType::badType() && "you forgot init()!"); */ \
66  /* Initialize a field data container for the class only once. */ \
67  assert(::_class_::lxFieldIsInit && "\nClass not init!\n"); \
68  assert((::_class_::parentFieldData != (const Core::LxFieldData**)0xdeadbeefLL) && "\nParent-Class not init\n"); \
69  if (!::_class_::fieldData) \
70  { \
71  ::_class_::fieldData = new Core::LxFieldData(::_class_::parentFieldData ? *::_class_::parentFieldData : NULL); \
72  } \
73  /* Extension classes from the application programmers should not be \
74  considered native. This is important to get the export code to do \
75  the Right Thing. */ \
76 \
77  Core::PropertyContainer::isValid(); \
78 \
79  } while (0); \
80  Core::PostInitClass __postInit__(this)
81 
82 
83 #define LX_PRIVATE_COMMON_INIT_CODE(_class_, _parentclass_) \
84  do \
85  { \
86  /* Store parent's field data pointer for later use in the constructor. */ \
87  _class_::parentFieldData = _parentclass_::getFieldDataPtr(); \
88  } while (0)
89 
90 #define LX_NODE_INIT_CLASS_NO_PARENT(_class_) \
91  do \
92  { \
93  _class_::parentFieldData = 0; \
94  _class_::lxFieldIsInit = true; \
95  } while (0)
96 
97 
98 #define LX_NODE_INIT_CLASS(_class_, _parentclass_) \
99  do \
100  { \
101  LX_PRIVATE_COMMON_INIT_CODE(_class_, _parentclass_); \
102  _class_::lxFieldIsInit = true; \
103  } while (0)
104 
105 #define LX_NODE_ADD_FIELD(_field_, _defaultval_) \
106  do \
107  { \
108  fieldData->addField(this, LX__QUOTE(_field_), &this->_field_); \
109  } while (0)
110 
111 #ifndef LXAPI
112 
113 #define CONCATSTR(a, b) a##b
114 
115 #define BUILDCLASS(CLASS, NAME, CTR, CTR2) \
116  class CONCATSTR(NAME, CTR) \
117  { \
118  public: \
119  CONCATSTR(NAME, CTR)() { CLASS::setIfcNameAndID(LX__QUOTE(NAME), LxIfc4::NAME); } \
120  }; \
121  static CONCATSTR(NAME, CTR) CONCATSTR(NAME, CTR2);
122 
123 #ifdef SWIG
124 
125 #define DECLARE_OBJECT_FACTORY_IFC(_factoryName_, _class_, _ifc4Class_, _ifc3Class_)
126 
127 #else
128 
129 #define DECLARE_OBJECT_FACTORY_IFC(_factoryName_, _class_, _ifc4Class_, _ifc3Class_) \
130  class _factoryName_ : public Core::ObjectFactory \
131  { \
132  private: \
133  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
134  { \
135  auto o = new _class_; \
136  o->setDocument(doc); \
137  o->setIfc3EntityType(LxIfc3::_ifc3Class_); \
138  o->setIfc4EntityType(LxIfc4::_ifc4Class_); \
139  return o; \
140  } \
141  }; \
142  BUILDCLASS(_class_, _ifc4Class_, __COUNTER__, __COUNTER__)
143 
144 #endif
145 
146 #else
147 #define DECLARE_OBJECT_FACTORY_IFC(_factoryName_, _class_, _ifc4Class_, _ifc3Class_) \
148  class _factoryName_ : public Core::ObjectFactory \
149  { \
150  private: \
151  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
152  { \
153  auto o = new _class_; \
154  o->setDocument(doc); \
155  return o; \
156  } \
157  };
158 #endif
159 
160 
161 
162 #ifndef LXAPI
163 
164 #ifdef SWIG
165 
166 #define DECLARE_OBJECT_FACTORY(_factoryName_, _class_, _ifcClass_)
167 #define DECLARE_OBJECT_FACTORY_NOIFC(_factoryName_, _class_)
168 
169 #else
170 
171 #define DECLARE_OBJECT_FACTORY(_factoryName_, _class_, _ifcClass_) \
172  class _factoryName_ : public Core::ObjectFactory \
173  { \
174  private: \
175  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
176  { \
177  auto o = new _class_; \
178  o->setDocument(doc); \
179  o->setIfc3EntityType(LxIfc3::_ifcClass_); \
180  o->setIfc4EntityType(LxIfc4::_ifcClass_); \
181  return o; \
182  } \
183  }; \
184  BUILDCLASS(_class_, _ifcClass_, __COUNTER__, __COUNTER__)
185 
186 
187 
188 #define DECLARE_OBJECT_FACTORY_NOIFC(_factoryName_, _class_) \
189  class _factoryName_ : public Core::ObjectFactory \
190  { \
191  private: \
192  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
193  { \
194  auto o = new _class_; \
195  o->setDocument(doc); \
196  return o; \
197  } \
198  }; \
199  //BUILDCLASS(_class_, _ifcClass_, __COUNTER__, __COUNTER__)
200 
201 #endif
202 
203 
204 #else
205 #define DECLARE_OBJECT_FACTORY(_factoryName_, _class_, _ifcClass_) \
206  class _factoryName_ : public Core::ObjectFactory \
207  { \
208  private: \
209  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
210  { \
211  auto o = new _class_; \
212  o->setDocument(doc); \
213  return o; \
214  } \
215  };
216 
217 #define DECLARE_OBJECT_FACTORY_NOIFC(_factoryName_, _class_) \
218  class _factoryName_ : public Core::ObjectFactory \
219  { \
220  private: \
221  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
222  { \
223  auto o = new _class_; \
224  o->setDocument(doc); \
225  return o; \
226  } \
227  };
228 
229 #endif
230 
231 #define DECLARE_TEMPLATE_OBJECT_FACTORY(_factoryName_, _class_, _ifcClass_) \
232  template <class T> \
233  class _factoryName_ : public Core::ObjectFactory \
234  { \
235  private: \
236  virtual Core::DocObject* createByFactory(Core::CoreDocument* doc) \
237  { \
238  auto o = new _class_<T>; \
239  o->setDocument(doc); \
240  o->setIfc3EntityType(LxIfc3::_ifcClass_); \
241  /*o->setLxIfcEntity( std::shared_ptr<LxIfc3::LxIfc3Entity>( LxIfcEntityFactory::createIfc3Entity<_ifcClass_> ) );*/ \
242  return o; \
243  } \
244  };
245 
246 
247 #define REGISTER_OBJECT_FACTORY(_factoryName_, _class_) Core::ObjectFactory::registry[#_class_] = (Core::ObjectFactory*)new _factoryName_();
248 
249 #define INIT_PROPERTY_TEMPLATES(_class_) \
250  Core::PropertyLink<_class_*>::init(qPrintable(QString("PropertyLink[%1]").arg(#_class_))); \
251  Core::PropertyLinkSet<_class_*>::init(qPrintable(QString("PropertyLinkSet[%1]").arg(#_class_))); \
252  Core::PropertyBackLink<_class_*>::init(qPrintable(QString("PropertyBackLink[%1]").arg(#_class_))); \
253  Core::PropertyBackLinkSet<_class_*>::init(qPrintable(QString("PropertyBackLinkSet[%1]").arg(#_class_))); \
254  Core::PropertyTypedLinkList<_class_*>::init(qPrintable(QString("PropertyTypedLinkList[%1]").arg(#_class_)));
255 
256 #define DECLARE_PROPERTY_TEMPLATES(_class_, _export_symbol_) \
257  template class _export_symbol_ Core::PropertyLink<_class_*>; \
258  template class _export_symbol_ Core::PropertyLinkSet<_class_*>; \
259  template class _export_symbol_ Core::PropertyBackLink<_class_*>; \
260  template class _export_symbol_ Core::PropertyBackLinkSet<_class_*>; \
261  template class _export_symbol_ Core::PropertyTypedLinkList<_class_*>;
262 
263 #define CREATE_FOR_TEST(_class_) \
264  do \
265  { \
266  class R : public _class_ \
267  { \
268  public: \
269  R(){}; \
270  virtual ~R(){}; \
271  }; \
272 \
273  auto v = new R(); \
274  v->check_lx(#_class_, __FUNCTION__); \
275  delete v; \
276  } while (false);
277 
278 
279 
280 #define TYPE_FOR_SAVE_IS_PARENT() \
281 private: \
282  Base::Type getTypeForSave() { return getTypeId().getParent(); }
283 
284 
285 
286 #define __INIT_OBJECT(_class_) \
287  _class_::init(); \
288  INIT_PROPERTY_TEMPLATES(_class_)
289 
290 #define LX_INIT_OBJECT(_class_) \
291  _class_::init(); \
292  _class_::lx_field_init(); \
293  CREATE_FOR_TEST(_class_) \
294  INIT_PROPERTY_TEMPLATES(_class_)
295 
296 #define LX_INIT_OBJECT_LINK(_class_) \
297  _class_::init(); \
298  _class_::lx_field_init(); \
299  CREATE_FOR_TEST(_class_) \
300  INIT_PROPERTY_TEMPLATES(_class_)
301 
302 #define LX_INIT_OBJECT_ABSTRACT(_class_) \
303  _class_::init(); \
304  _class_::lx_field_init(); \
305  INIT_PROPERTY_TEMPLATES(_class_)