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