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