CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
RxDispatchImpl.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 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
40class OdRxPropDesc : public OdRxObject
41{
42public:
43 virtual OdString name() const = 0;
44 virtual OdRxObjectPtr prop_get(const void* pThis) const = 0;
45 virtual void prop_put(void* pThis, OdRxObject* pVal) = 0;
46};
47
52template <class TBase = OdRxDictionary>
53class OdRxDispatchImpl : public TBase
54{
55 typedef OdRxPropDesc PropDesc;
56protected:
57 class Iterator : public OdRxObjectImpl<OdRxDictionaryIterator>
58 {
59 OdRxDictionaryPtr m_pOwner;
60 OdRxDictionaryIteratorPtr m_pDescIter;
61 public:
63 : m_pOwner(pOwner), m_pDescIter(pDescIter) {}
64
69 OdString getKey() const { return m_pOwner->keyAt(id()); }
70 OdUInt32 id() const { return m_pDescIter->id(); }
71 bool done() const { return m_pDescIter->done(); }
72 bool next() { return m_pDescIter->next(); }
73 OdRxObjectPtr object() const { return m_pOwner->getAt(id()); }
74 };
76 {
79 generatePropMap(pInfo);
80 return pInfo;
81 }
82
83 virtual OdRxDictionary* propertiesInfo() const = 0;
84 virtual void generatePropMap(OdRxDictionary*) const = 0;
85
86 inline PropDesc* descAt(OdUInt32 id) const
87 { return (PropDesc*)propertiesInfo()->getAt(id).get(); }
88public:
89 OdRxObjectPtr getAt(const OdString& key) const
90 { return OdRxDispatchImpl::getAt(idAt(key)); }
91
92 OdRxObjectPtr putAt(const OdString& key, OdRxObject* pObject, OdUInt32* pId = 0)
93 {
94 OdUInt32 id = idAt(key);
95 if (pId)
96 *pId = id;
97 return OdRxDispatchImpl::putAt(id, pObject);
98 }
99
101 {
102 PropDesc* pd = descAt(id);
103 if (!pd)
104 throw OdError(eInvalidInput);
105 return pd->prop_get((TBase*)this);
106 }
107
108 OdRxObjectPtr putAt(OdUInt32 id, OdRxObject* pObject)
109 {
110 if(id < numEntries())
111 {
112 PropDesc* pDesc = descAt(id);
113 OdRxObjectPtr pRes = pDesc->prop_get((TBase*)this);
114 pDesc->prop_put((TBase*)this, pObject);
115 return pRes;
116 }
117 throw OdError(eInvalidInput);
118 }
119
120 bool has(const OdString& entryName) const { return propertiesInfo()->has(entryName); }
121 bool has(OdUInt32 id) const { return propertiesInfo()->has(id); }
122 OdUInt32 idAt(const OdString& key) const { return propertiesInfo()->idAt(key); }
123 OdString keyAt(OdUInt32 id) const { return propertiesInfo()->keyAt(id); }
125 bool isCaseSensitive() const { return propertiesInfo()->isCaseSensitive(); }
126
131
132 // not used
133 bool atKeyAndIdPut(const OdString& , OdUInt32 , OdRxObject* ) {
134 throw OdError(eNotApplicable);
135 return false;
136 }
137
138 bool resetKey(OdUInt32 , const OdString& ) {
139 throw OdError(eNotApplicable);
140 return false;
141 }
143 throw OdError(eNotApplicable);
144 return OdRxObjectPtr();
145 }
147 throw OdError(eNotApplicable);
148 return OdRxObjectPtr();
149 }
150};
151
152#define ODRX_DECLARE_DYNAMIC_PROPERTY_MAP(CLASS) \
153 virtual void generatePropMap(OdRxDictionary*) const;\
154 virtual OdRxDictionary* propertiesInfo() const
155
156#define ODRX_BEGIN_DYNAMIC_PROPERTY_MAP(CLASS) \
157void CLASS::generatePropMap(OdRxDictionary* pInfo) const {
158
159#if (defined(_MSC_VER) && (_MSC_VER > 1800)) || (defined(__cplusplus) && (__cplusplus > 199711L))
160
161#define ODRX_END_DYNAMIC_PROPERTY_MAP(CLASS) }\
162OdRxDictionary* CLASS::propertiesInfo() const\
163{\
164 static OdRxDictionaryPtr pInfo = createPropMap();\
165 return pInfo.get();\
166}
167
168#else
169
170#define ODRX_END_DYNAMIC_PROPERTY_MAP(CLASS) }\
171static OdMutex _##CLASS##PropMapMutex;\
172OdRxDictionary* CLASS::propertiesInfo() const\
173{\
174 TD_AUTOLOCK(_##CLASS##PropMapMutex);\
175 static OdRxDictionaryPtr pInfo = createPropMap();\
176 return pInfo.get();\
177}
178
179#endif
180
181#define ODRX_INHERIT_PROPERTIES(BASE_CLASS) \
182 BASE_CLASS::generatePropMap(pInfo);
183
184
185#define ODRX_DECLARE_PROPERTY(PropName) \
186 class _##PropName##_PropDesc : public OdRxObjectImpl<OdRxPropDesc>\
187 {\
188 public:\
189 static OdRxObjectPtr createObject();\
190 static inline OdString _name();\
191 OdString name() const;\
192 OdRxObjectPtr prop_get(const void* pThis) const;\
193 void prop_put(void* pThis, OdRxObject* pVal);\
194 };
195
196#define ODRX_DECLARE_PROPERTY2(PropName, SrcFileName) \
197 class _##PropName##_##SrcFileName##_PropDesc : public OdRxObjectImpl<OdRxPropDesc>\
198 {\
199 public:\
200 static OdRxObjectPtr createObject();\
201 static inline OdString _name();\
202 OdString name() const;\
203 OdRxObjectPtr prop_get(const void* pThis) const;\
204 void prop_put(void* pThis, OdRxObject* pVal);\
205 };
206
207#define ODRX_DEFINE_PROPERTY_METHODS(PropName, PropHolder, getMethodName, putMethodName, accessFn) \
208 OdRxObjectPtr _##PropName##_PropDesc::createObject()\
209 {\
210 return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
211 }\
212 inline OdString _##PropName##_PropDesc::_name()\
213 {\
214 static OdString sName(OD_T(#PropName));\
215 return sName;\
216 }\
217 OdString _##PropName##_PropDesc::name() const \
218 {\
219 return _name();\
220 }\
221 OdRxObjectPtr _##PropName##_PropDesc::prop_get(const void* pThis) const\
222 {\
223 return (OdRxObject*)OdRxVariantValue((static_cast<PropHolder*>((OdRxDictionary*)pThis))->getMethodName());\
224 }\
225 void _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
226 {\
227 (static_cast<PropHolder*>((OdRxDictionary*)pThis))->putMethodName(OdRxVariantValue(pVal)->accessFn());\
228 }
229
230#define ODRX_DEFINE_PROPERTY_METHODS2(PropName, SrcFileName, PropHolder, getMethodName, putMethodName, accessFn) \
231 OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::createObject()\
232 {\
233 return OdRxObjectPtr(new _##PropName##_##SrcFileName##_PropDesc, kOdRxObjAttach);\
234 }\
235 inline OdString _##PropName##_##SrcFileName##_PropDesc::_name()\
236 {\
237 static OdString sName(OD_T(#PropName));\
238 return sName;\
239 }\
240 OdString _##PropName##_##SrcFileName##_PropDesc::name() const \
241 {\
242 return _name();\
243 }\
244 OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::prop_get(const void* pThis) const\
245 {\
246 return (OdRxObject*)OdRxVariantValue((static_cast<PropHolder*>((OdRxDictionary*)pThis))->getMethodName());\
247 }\
248 void _##PropName##_##SrcFileName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
249 {\
250 (static_cast<PropHolder*>((OdRxDictionary*)pThis))->putMethodName(OdRxVariantValue(pVal)->accessFn());\
251 }
252
253#define ODRX_DEFINE_PROPERTY_METHODS_PREFIX(ClassPrefix, PropName, PropHolder, getMethodName, putMethodName, accessFn) \
254 OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::createObject()\
255 {\
256 return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
257 }\
258 inline OdString ClassPrefix _##PropName##_PropDesc::_name()\
259 {\
260 static OdString sName(OD_T(#PropName));\
261 return sName;\
262 }\
263 OdString ClassPrefix _##PropName##_PropDesc::name() const \
264 {\
265 return _name();\
266 }\
267 OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::prop_get(const void* pThis) const\
268 {\
269 return (OdRxObject*)OdRxVariantValue((static_cast<PropHolder*>((OdRxDictionary*)pThis))->getMethodName());\
270 }\
271 void ClassPrefix _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
272 {\
273 (static_cast<PropHolder*>((OdRxDictionary*)pThis))->putMethodName(OdRxVariantValue(pVal)->accessFn());\
274 }
275
276#define ODRX_GENERATE_PROPERTY(PropName) \
277 pInfo->putAt(_##PropName##_PropDesc::_name(), _##PropName##_PropDesc::createObject());
278
279#define ODRX_GENERATE_PROPERTY2(PropName, SrcFileName) \
280 pInfo->putAt(_##PropName##_##SrcFileName##_PropDesc::_name(), _##PropName##_##SrcFileName##_PropDesc::createObject());
281
282#define ODRX_DEFINE_PROPERTY(PropName, PropHolder, accessFn) ODRX_DEFINE_PROPERTY_METHODS(PropName, PropHolder, get_##PropName, put_##PropName, accessFn)
283
284#define ODRX_DEFINE_PROPERTY2(PropName, SrcFileName, PropHolder, accessFn) ODRX_DEFINE_PROPERTY_METHODS2(PropName, SrcFileName, PropHolder, get_##PropName, put_##PropName, accessFn)
285
286#define ODRX_DEFINE_PROPERTY_PREFIX(ClassPrefix, PropName, PropHolder, accessFn) ODRX_DEFINE_PROPERTY_METHODS_PREFIX(ClassPrefix, PropName, PropHolder, get_##PropName, put_##PropName, accessFn)
287
288
289
290#define ODRX_DEFINE_PROPERTY_OBJECT(PropName, PropHolder, getMethodName, putMethodName, ObjType) \
291 OdRxObjectPtr _##PropName##_PropDesc::createObject()\
292 {\
293 return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
294 }\
295 OdString _##PropName##_PropDesc::_name()\
296 {\
297 static OdString sName(OD_T(#PropName));\
298 return sName;\
299 }\
300 OdString _##PropName##_PropDesc::name() const \
301 {\
302 return _name();\
303 }\
304 OdRxObjectPtr _##PropName##_PropDesc::prop_get(const void* pThis) const\
305 {\
306 return static_cast<PropHolder*>((OdRxDictionary*)pThis)->getMethodName();\
307 }\
308 void _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
309 {\
310 static_cast<PropHolder*>((OdRxDictionary*)pThis)->putMethodName(OdSmartPtr<ObjType>(pVal));\
311 }
312
313#define ODRX_DEFINE_PROPERTY_OBJECT2(PropName, SrcFileName, PropHolder, getMethodName, putMethodName, ObjType) \
314 OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::createObject()\
315 {\
316 return OdRxObjectPtr(new _##PropName##_##SrcFileName##_PropDesc, kOdRxObjAttach);\
317 }\
318 OdString _##PropName##_##SrcFileName##_PropDesc::_name()\
319 {\
320 static OdString sName(OD_T(#PropName));\
321 return sName;\
322 }\
323 OdString _##PropName##_##SrcFileName##_PropDesc::name() const \
324 {\
325 return _name();\
326 }\
327 OdRxObjectPtr _##PropName##_##SrcFileName##_PropDesc::prop_get(const void* pThis) const\
328 {\
329 return static_cast<PropHolder*>((OdRxDictionary*)pThis)->getMethodName();\
330 }\
331 void _##PropName##_##SrcFileName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
332 {\
333 static_cast<PropHolder*>((OdRxDictionary*)pThis)->putMethodName(OdSmartPtr<ObjType>(pVal));\
334 }
335
336#define ODRX_DEFINE_PROPERTY_OBJECT_PREFIX(ClassPrefix, PropName, PropHolder, getMethodName, putMethodName, ObjType) \
337 OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::createObject()\
338 {\
339 return OdRxObjectPtr(new _##PropName##_PropDesc, kOdRxObjAttach);\
340 }\
341 OdString ClassPrefix _##PropName##_PropDesc::_name()\
342 {\
343 static OdString sName(OD_T(#PropName));\
344 return sName;\
345 }\
346 OdString ClassPrefix _##PropName##_PropDesc::name() const \
347 {\
348 return _name();\
349 }\
350 OdRxObjectPtr ClassPrefix _##PropName##_PropDesc::prop_get(const void* pThis) const\
351 {\
352 return static_cast<PropHolder*>((OdRxDictionary*)pThis)->getMethodName();\
353 }\
354 void ClassPrefix _##PropName##_PropDesc::prop_put(void* pThis, OdRxObject* pVal)\
355 {\
356 static_cast<PropHolder*>((OdRxDictionary*)pThis)->putMethodName(OdSmartPtr<ObjType>(pVal));\
357 }
358
359
360//wrapper to use non-Rx classes as an object passed through the properties
361template <class Type>
362class OdRxWrapper : public OdRxObject, public Type
363{
364
365};
366template <class Type>
367class OdRxWrapperValue : public OdSmartPtr<OdRxWrapper<Type> >
368{
369public:
370
372 :OdSmartPtr<OdRxWrapper<Type> >(pObject)
373 {
374 }
375
376 OdRxWrapperValue(const Type& val)
377 {
379 *((Type*)OdSmartPtr<OdRxWrapper<Type> >::get()) = val;
380 }
381 operator const Type&() const
382 {
383 return *((Type*)OdSmartPtr<OdRxWrapper<Type> >::get());
384 }
385};
386
387template<class T>
389{
390 return OdRxWrapperValue<T>(val);
391}
392
393#include "TD_PackPop.h"
394
395#endif // __PROPERTIES_H_INCLUDED_
396
OdSmartPtr< OdRxDictionary > OdRxDictionaryPtr
Definition Gs.h:93
unsigned int OdUInt32
OdSmartPtr< OdRxDictionaryIterator > OdRxDictionaryIteratorPtr
FIRSTDLL_EXPORT OdRxDictionaryPtr odrxCreateRxDictionary()
OdRxWrapperValue< T > createRxWrapper(const T &val)
@ 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
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
OdRxDictionaryPtr createPropMap() const
OdRxObjectPtr remove(const OdString &)
bool resetKey(OdUInt32, const OdString &)
bool atKeyAndIdPut(const OdString &, OdUInt32, OdRxObject *)
virtual void generatePropMap(OdRxDictionary *) const =0
bool has(OdUInt32 id) const
OdRxObjectPtr getAt(OdUInt32 id) const
bool has(const OdString &entryName) const
OdRxObjectPtr remove(OdUInt32)
bool isCaseSensitive() const
OdUInt32 idAt(const OdString &key) const
virtual OdRxDictionary * propertiesInfo() const =0
OdRxObjectPtr putAt(OdUInt32 id, OdRxObject *pObject)
OdString keyAt(OdUInt32 id) const
PropDesc * descAt(OdUInt32 id) const
OdRxObjectPtr putAt(const OdString &key, OdRxObject *pObject, OdUInt32 *pId=0)
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
OdRxWrapperValue(const Type &val)
OdRxWrapperValue(const OdRxObjectPtr &pObject)
const OdRxWrapper< Type > * get() const
Definition SmartPtr.h:315
GLuint GLsizei GLsizei GLint GLenum * type
Definition gles2_ext.h:274
DictIterType
Definition RxDefs.h:38
@ kDictCollated
Definition RxDefs.h:40