CFx SDK Documentation  2020SP3
RxDispatchImpl.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 
26 
27 #ifndef __PROPERTIES_H_INCLUDED_
28 #define __PROPERTIES_H_INCLUDED_
29 
30 #include "TD_PackPush.h"
31 
32 #include "RxDictionary.h"
33 #include "RxObjectImpl.h"
34 #include "OdString.h"
35 
36 
37 #ifdef _MSC_VER
38 #pragma warning ( disable : 4702 ) // unreachable code
39 #endif
40 
44 class OdRxPropDesc : public OdRxObject
45 {
46 public:
47  virtual OdString name() const = 0;
48  virtual OdRxObjectPtr prop_get(const void* pThis) const = 0;
49  virtual void prop_put(void* pThis, OdRxObject* pVal) = 0;
50 };
51 
56 template <class TBase = OdRxDictionary>
57 class OdRxDispatchImpl : public TBase
58 {
59  typedef OdRxPropDesc PropDesc;
60 protected:
61  class Iterator : public OdRxObjectImpl<OdRxDictionaryIterator>
62  {
63  OdRxDictionaryPtr m_pOwner;
64  OdRxDictionaryIteratorPtr m_pDescIter;
65  public:
67  : m_pOwner(pOwner), m_pDescIter(pDescIter) {}
68 
70  {
72  }
73  OdString getKey() const { return m_pOwner->keyAt(id()); }
74  OdUInt32 id() const { return m_pDescIter->id(); }
75  bool done() const { return m_pDescIter->done(); }
76  bool next() { return m_pDescIter->next(); }
77  OdRxObjectPtr object() const { return m_pOwner->getAt(id()); }
78  };
79  virtual OdRxDictionary* propertiesInfo() const = 0;
80  inline PropDesc* descAt(OdUInt32 id) const
81  { return (PropDesc*)propertiesInfo()->getAt(id).get(); }
82 public:
83  OdRxObjectPtr getAt(const OdString& key) const
84  { return OdRxDispatchImpl::getAt(idAt(key)); }
85 
86  OdRxObjectPtr putAt(const OdString& key, OdRxObject* pObject, OdUInt32* = 0)
87  { return OdRxDispatchImpl::putAt(idAt(key), pObject); }
88 
90  { return descAt(id)->prop_get((TBase*)this); }
91 
93  {
94  if(id < numEntries())
95  {
96  PropDesc* pDesc = descAt(id);
97  OdRxObjectPtr pRes = pDesc->prop_get((TBase*)this);
98  pDesc->prop_put((TBase*)this, pObject);
99  return pRes;
100  }
101  throw OdError(eInvalidInput);
102  }
103 
104  bool has(const OdString& entryName) const { return propertiesInfo()->has(entryName); }
105  bool has(OdUInt32 id) const { return propertiesInfo()->has(id); }
106  OdUInt32 idAt(const OdString& key) const { return propertiesInfo()->idAt(key); }
107  OdString keyAt(OdUInt32 id) const { return propertiesInfo()->keyAt(id); }
108  OdUInt32 numEntries() const { return propertiesInfo()->numEntries(); }
109  bool isCaseSensitive() const { return propertiesInfo()->isCaseSensitive(); }
110 
112  {
114  }
115 
116  // not used
118  throw OdError(eNotApplicable);
119  return false;
120  }
121 
122  bool resetKey(OdUInt32 , const OdString& ) {
123  throw OdError(eNotApplicable);
124  return false;
125  }
127  throw OdError(eNotApplicable);
128  return OdRxObjectPtr();
129  }
131  throw OdError(eNotApplicable);
132  return OdRxObjectPtr();
133  }
134 };
135 
136 #define ODRX_DECLARE_DYNAMIC_PROPERTY_MAP(CLASS) \
137  virtual void generatePropMap(OdRxDictionary*) const;\
138  virtual OdRxDictionary* propertiesInfo() const
139 
140 #define ODRX_BEGIN_DYNAMIC_PROPERTY_MAP(CLASS) \
141 void CLASS::generatePropMap(OdRxDictionary* pInfo) const {
142 
143 #define ODRX_END_DYNAMIC_PROPERTY_MAP(CLASS) }\
144 OdRxDictionary* CLASS::propertiesInfo() const\
145 {\
146  static OdRxDictionaryPtr pInfo;\
147  if(pInfo.isNull())\
148  {\
149  pInfo = ::odrxCreateRxDictionary();\
150  generatePropMap(pInfo);\
151  }\
152  return pInfo.get();\
153 }
154 
155 #define ODRX_INHERIT_PROPERTIES(BASE_CLASS) \
156  BASE_CLASS::generatePropMap(pInfo);
157 
158 
159 #define ODRX_DECLARE_PROPERTY(PropName) \
160  class _##PropName##_PropDesc : public OdRxObjectImpl<OdRxPropDesc>\
161  {\
162  public:\
163  static OdRxObjectPtr createObject();\
164  static inline OdString _name();\
165  OdString name() const;\
166  OdRxObjectPtr prop_get(const void* pThis) const;\
167  void prop_put(void* pThis, OdRxObject* pVal);\
168  };
169 
170 #define ODRX_DECLARE_PROPERTY2(PropName, SrcFileName) \
171  class _##PropName##_##SrcFileName##_PropDesc : public OdRxObjectImpl<OdRxPropDesc>\
172  {\
173  public:\
174  static OdRxObjectPtr createObject();\
175  static inline OdString _name();\
176  OdString name() const;\
177  OdRxObjectPtr prop_get(const void* pThis) const;\
178  void prop_put(void* pThis, OdRxObject* pVal);\
179  };
180 
181 #define ODRX_DEFINE_PROPERTY_METHODS(PropName, PropHolder, getMethodName, putMethodName, accessFn) \
182  OdRxObjectPtr _##PropName##_PropDesc::createObject()\
183  {\
184  return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
185  }\
186  inline OdString _##PropName##_PropDesc::_name()\
187  {\
188  static OdString sName(OD_T(#PropName));\
189  return sName;\
190  }\
191  OdString _##PropName##_PropDesc::name() const \
192  {\
193  return _name();\
194  }\
195  OdRxObjectPtr _##PropName##_PropDesc::prop_get(const void* pThis) const\
196  {\
197  return (OdRxObject*)OdRxVariantValue((static_cast<PropHolder*>((OdRxDictionary*)pThis))->getMethodName());\
198  }\
199  void _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
200  {\
201  (static_cast<PropHolder*>((OdRxDictionary*)pThis))->putMethodName(OdRxVariantValue(pVal)->accessFn());\
202  }
203 
204 #define ODRX_DEFINE_PROPERTY_METHODS2(PropName, SrcFileName, PropHolder, getMethodName, putMethodName, accessFn) \
205  OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::createObject()\
206  {\
207  return OdRxObjectPtr(new _##PropName##_##SrcFileName##_PropDesc, kOdRxObjAttach);\
208  }\
209  inline OdString _##PropName##_##SrcFileName##_PropDesc::_name()\
210  {\
211  static OdString sName(OD_T(#PropName));\
212  return sName;\
213  }\
214  OdString _##PropName##_##SrcFileName##_PropDesc::name() const \
215  {\
216  return _name();\
217  }\
218  OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::prop_get(const void* pThis) const\
219  {\
220  return (OdRxObject*)OdRxVariantValue((static_cast<PropHolder*>((OdRxDictionary*)pThis))->getMethodName());\
221  }\
222  void _##PropName##_##SrcFileName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
223  {\
224  (static_cast<PropHolder*>((OdRxDictionary*)pThis))->putMethodName(OdRxVariantValue(pVal)->accessFn());\
225  }
226 
227 #define ODRX_DEFINE_PROPERTY_METHODS_PREFIX(ClassPrefix, PropName, PropHolder, getMethodName, putMethodName, accessFn) \
228  OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::createObject()\
229  {\
230  return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
231  }\
232  inline OdString ClassPrefix _##PropName##_PropDesc::_name()\
233  {\
234  static OdString sName(OD_T(#PropName));\
235  return sName;\
236  }\
237  OdString ClassPrefix _##PropName##_PropDesc::name() const \
238  {\
239  return _name();\
240  }\
241  OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::prop_get(const void* pThis) const\
242  {\
243  return (OdRxObject*)OdRxVariantValue((static_cast<PropHolder*>((OdRxDictionary*)pThis))->getMethodName());\
244  }\
245  void ClassPrefix _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
246  {\
247  (static_cast<PropHolder*>((OdRxDictionary*)pThis))->putMethodName(OdRxVariantValue(pVal)->accessFn());\
248  }
249 
250 #define ODRX_GENERATE_PROPERTY(PropName) \
251  pInfo->putAt(_##PropName##_PropDesc::_name(), _##PropName##_PropDesc::createObject());
252 
253 #define ODRX_GENERATE_PROPERTY2(PropName, SrcFileName) \
254  pInfo->putAt(_##PropName##_##SrcFileName##_PropDesc::_name(), _##PropName##_##SrcFileName##_PropDesc::createObject());
255 
256 #define ODRX_DEFINE_PROPERTY(PropName, PropHolder, accessFn) ODRX_DEFINE_PROPERTY_METHODS(PropName, PropHolder, get_##PropName, put_##PropName, accessFn)
257 
258 #define ODRX_DEFINE_PROPERTY2(PropName, SrcFileName, PropHolder, accessFn) ODRX_DEFINE_PROPERTY_METHODS2(PropName, SrcFileName, PropHolder, get_##PropName, put_##PropName, accessFn)
259 
260 #define ODRX_DEFINE_PROPERTY_PREFIX(ClassPrefix, PropName, PropHolder, accessFn) ODRX_DEFINE_PROPERTY_METHODS_PREFIX(ClassPrefix, PropName, PropHolder, get_##PropName, put_##PropName, accessFn)
261 
262 
263 
264 #define ODRX_DEFINE_PROPERTY_OBJECT(PropName, PropHolder, getMethodName, putMethodName, ObjType) \
265  OdRxObjectPtr _##PropName##_PropDesc::createObject()\
266  {\
267  return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
268  }\
269  OdString _##PropName##_PropDesc::_name()\
270  {\
271  static OdString sName(OD_T(#PropName));\
272  return sName;\
273  }\
274  OdString _##PropName##_PropDesc::name() const \
275  {\
276  return _name();\
277  }\
278  OdRxObjectPtr _##PropName##_PropDesc::prop_get(const void* pThis) const\
279  {\
280  return static_cast<PropHolder*>((OdRxDictionary*)pThis)->getMethodName();\
281  }\
282  void _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
283  {\
284  static_cast<PropHolder*>((OdRxDictionary*)pThis)->putMethodName(OdSmartPtr<ObjType>(pVal));\
285  }
286 
287 #define ODRX_DEFINE_PROPERTY_OBJECT2(PropName, SrcFileName, PropHolder, getMethodName, putMethodName, ObjType) \
288  OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::createObject()\
289  {\
290  return OdRxObjectPtr(new _##PropName##_##SrcFileName##_PropDesc, kOdRxObjAttach);\
291  }\
292  OdString _##PropName##_##SrcFileName##_PropDesc::_name()\
293  {\
294  static OdString sName(OD_T(#PropName));\
295  return sName;\
296  }\
297  OdString _##PropName##_##SrcFileName##_PropDesc::name() const \
298  {\
299  return _name();\
300  }\
301  OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::prop_get(const void* pThis) const\
302  {\
303  return static_cast<PropHolder*>((OdRxDictionary*)pThis)->getMethodName();\
304  }\
305  void _##PropName##_##SrcFileName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
306  {\
307  static_cast<PropHolder*>((OdRxDictionary*)pThis)->putMethodName(OdSmartPtr<ObjType>(pVal));\
308  }
309 
310 #define ODRX_DEFINE_PROPERTY_OBJECT_PREFIX(ClassPrefix, PropName, PropHolder, getMethodName, putMethodName, ObjType) \
311  OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::createObject()\
312  {\
313  return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
314  }\
315  OdString ClassPrefix _##PropName##_PropDesc::_name()\
316  {\
317  static OdString sName(OD_T(#PropName));\
318  return sName;\
319  }\
320  OdString ClassPrefix _##PropName##_PropDesc::name() const \
321  {\
322  return _name();\
323  }\
324  OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::prop_get(const void* pThis) const\
325  {\
326  return static_cast<PropHolder*>((OdRxDictionary*)pThis)->getMethodName();\
327  }\
328  void ClassPrefix _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
329  {\
330  static_cast<PropHolder*>((OdRxDictionary*)pThis)->putMethodName(OdSmartPtr<ObjType>(pVal));\
331  }
332 
333 #include "TD_PackPop.h"
334 
335 #endif // __PROPERTIES_H_INCLUDED_
336 
OdRxDispatchImpl::Iterator::Iterator
Iterator(OdRxDictionary *pOwner, OdRxDictionaryIterator *pDescIter)
Definition: RxDispatchImpl.h:66
OdRxDictionaryIteratorPtr
OdSmartPtr< OdRxDictionaryIterator > OdRxDictionaryIteratorPtr
Definition: RxDictionary.h:85
OdRxDictionary::isCaseSensitive
virtual bool isCaseSensitive() const =0
OdString
Definition: OdString.h:95
OdRxObjectPtr
Definition: RxObject.h:345
OdRxDictionaryIterator::id
virtual OdUInt32 id() const =0
OdRxDispatchImpl::descAt
PropDesc * descAt(OdUInt32 id) const
Definition: RxDispatchImpl.h:80
OdRxDictionary::has
virtual bool has(const OdString &key) const =0
type
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
OdRxObject
Definition: RxObject.h:564
OdRxDispatchImpl::numEntries
OdUInt32 numEntries() const
Definition: RxDispatchImpl.h:108
OdRxDispatchImpl::Iterator::next
bool next()
Definition: RxDispatchImpl.h:76
TD_PackPop.h
OdRxObjectPtr::get
OdRxObject * get()
Definition: RxObject.h:503
OdRxDispatchImpl::keyAt
OdString keyAt(OdUInt32 id) const
Definition: RxDispatchImpl.h:107
OdRxPropDesc
Definition: RxDispatchImpl.h:45
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdRxDispatchImpl::newIterator
OdRxDictionaryIteratorPtr newIterator(OdRx::DictIterType type=OdRx::kDictCollated)
Definition: RxDispatchImpl.h:111
OdRxPropDesc::prop_put
virtual void prop_put(void *pThis, OdRxObject *pVal)=0
OdRxDispatchImpl::Iterator::object
OdRxObjectPtr object() const
Definition: RxDispatchImpl.h:77
OdRxDictionary::idAt
virtual OdUInt32 idAt(const OdString &key) const =0
OdRxDispatchImpl::resetKey
bool resetKey(OdUInt32, const OdString &)
Definition: RxDispatchImpl.h:122
OdString.h
OdRx::DictIterType
DictIterType
Definition: RxDefs.h:38
OdRxDictionary::getAt
virtual OdRxObjectPtr getAt(const OdString &key) const =0
OdRxDispatchImpl::Iterator
Definition: RxDispatchImpl.h:62
OdRxDispatchImpl
Definition: RxDispatchImpl.h:58
OdSmartPtr< OdRxDictionary >
OdRxDispatchImpl::has
bool has(const OdString &entryName) const
Definition: RxDispatchImpl.h:104
OdRxDispatchImpl::Iterator::done
bool done() const
Definition: RxDispatchImpl.h:75
OdRx::kDictCollated
@ kDictCollated
Definition: RxDefs.h:40
OdRxDispatchImpl::idAt
OdUInt32 idAt(const OdString &key) const
Definition: RxDispatchImpl.h:106
OdRxPropDesc::name
virtual OdString name() const =0
OdRxDictionary
Definition: RxDictionary.h:114
TD_PackPush.h
OdRxDispatchImpl::remove
OdRxObjectPtr remove(OdUInt32)
Definition: RxDispatchImpl.h:130
OdRxDictionary::keyAt
virtual OdString keyAt(OdUInt32 id) const =0
OdRxObjectImpl< OdRxDictionaryIterator >::createObject
static OdSmartPtr< OdRxDictionaryIterator > createObject()
Definition: RxObjectImpl.h:107
OdRxDispatchImpl::isCaseSensitive
bool isCaseSensitive() const
Definition: RxDispatchImpl.h:109
OdRxDispatchImpl::Iterator::createObject
static OdRxDictionaryIteratorPtr createObject(OdRxDictionary *pOwner, OdRxDictionaryIterator *pDescIter)
Definition: RxDispatchImpl.h:69
OdRxIterator::done
virtual bool done() const =0
OdRxDispatchImpl::remove
OdRxObjectPtr remove(const OdString &)
Definition: RxDispatchImpl.h:126
OdRxDictionaryIterator
Definition: RxDictionary.h:61
OdError
Definition: OdError.h:43
kOdRxObjAttach
@ kOdRxObjAttach
Definition: RxObject.h:56
OdRxDispatchImpl::Iterator::id
OdUInt32 id() const
Definition: RxDispatchImpl.h:74
OdRxDispatchImpl::getAt
OdRxObjectPtr getAt(OdUInt32 id) const
Definition: RxDispatchImpl.h:89
OdRxDispatchImpl::has
bool has(OdUInt32 id) const
Definition: RxDispatchImpl.h:105
OdRxIterator::next
virtual bool next()=0
OdRxDispatchImpl::atKeyAndIdPut
bool atKeyAndIdPut(const OdString &, OdUInt32, OdRxObject *)
Definition: RxDispatchImpl.h:117
OdRxObjectImpl
Definition: RxObjectImpl.h:55
OdRxDispatchImpl::putAt
OdRxObjectPtr putAt(OdUInt32 id, OdRxObject *pObject)
Definition: RxDispatchImpl.h:92
OdRxDictionary::numEntries
virtual OdUInt32 numEntries() const =0
OdRxDispatchImpl::propertiesInfo
virtual OdRxDictionary * propertiesInfo() const =0
OdRxPropDesc::prop_get
virtual OdRxObjectPtr prop_get(const void *pThis) const =0
RxDictionary.h
OdRxDispatchImpl::Iterator::getKey
OdString getKey() const
Definition: RxDispatchImpl.h:73
RxObjectImpl.h
OdRxDispatchImpl::getAt
OdRxObjectPtr getAt(const OdString &key) const
Definition: RxDispatchImpl.h:83
OdRxDispatchImpl::putAt
OdRxObjectPtr putAt(const OdString &key, OdRxObject *pObject, OdUInt32 *=0)
Definition: RxDispatchImpl.h:86