CFx SDK Documentation  2022 SP0
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
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 
unsigned int OdUInt32
OdSmartPtr< OdRxDictionaryIterator > OdRxDictionaryIteratorPtr
Definition: RxDictionary.h:85
@ kOdRxObjAttach
Definition: RxObject.h:56
virtual OdUInt32 idAt(const OdString &key) const =0
virtual OdRxObjectPtr getAt(const OdString &key) const =0
virtual bool isCaseSensitive() const =0
virtual OdUInt32 numEntries() const =0
virtual bool has(const OdString &key) const =0
virtual OdString keyAt(OdUInt32 id) const =0
virtual OdUInt32 id() const =0
static OdRxDictionaryIteratorPtr createObject(OdRxDictionary *pOwner, OdRxDictionaryIterator *pDescIter)
Iterator(OdRxDictionary *pOwner, OdRxDictionaryIterator *pDescIter)
OdRxObjectPtr object() const
OdRxObjectPtr getAt(const OdString &key) const
OdRxDictionaryIteratorPtr newIterator(OdRx::DictIterType type=OdRx::kDictCollated)
OdUInt32 numEntries() const
OdRxObjectPtr remove(const OdString &)
bool resetKey(OdUInt32, const OdString &)
OdRxObjectPtr putAt(const OdString &key, OdRxObject *pObject, OdUInt32 *=0)
bool atKeyAndIdPut(const OdString &, OdUInt32, OdRxObject *)
PropDesc * descAt(OdUInt32 id) const
bool has(OdUInt32 id) const
OdRxObjectPtr getAt(OdUInt32 id) const
bool has(const OdString &entryName) const
virtual OdRxDictionary * propertiesInfo() const =0
OdRxObjectPtr remove(OdUInt32)
bool isCaseSensitive() const
OdUInt32 idAt(const OdString &key) const
OdRxObjectPtr putAt(OdUInt32 id, OdRxObject *pObject)
OdString keyAt(OdUInt32 id) const
virtual bool done() const =0
virtual bool next()=0
static OdSmartPtr< OdRxDictionaryIterator > createObject()
Definition: RxObjectImpl.h:107
OdRxObject * get()
Definition: RxObject.h:503
virtual void prop_put(void *pThis, OdRxObject *pVal)=0
virtual OdString name() const =0
virtual OdRxObjectPtr prop_get(const void *pThis) const =0
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
DictIterType
Definition: RxDefs.h:38
@ kDictCollated
Definition: RxDefs.h:40