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