CFx SDK Documentation  2022 SP0
IfcCommon.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2019, 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-2019 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 #ifndef _IFC_COMMON_H_
25 #define _IFC_COMMON_H_
26 
27 #include "daiCommon.h"
28 
29 #include "RxObject.h"
30 #include "RxObjectImpl.h"
31 #include "SmartPtr.h"
32 #include "RxValue.h"
33 #include "daiValueTypes.h"
34 #include "ModuleNames.h"
35 
36 
37 #define SMARTPTR(classname) class classname; typedef OdSmartPtr<classname> classname##Ptr; typedef OdArray<classname##Ptr> classname##PtrArray;
38 
39 #define OD_IFC_CONS_DEFINE_MEMBERS(ClassName,ParentClass,DOCREATE,ClassType) \
40  \
41 OD_IFC_CONS_DEFINE_MEMBERS_ALTNAME(ClassName,ParentClass,OD_T(#ClassName),DOCREATE,ClassType)
42 
43 #define OD_IFC_CONS_DEFINE_MEMBERS_ALTNAME(ClassName,ParentClass,szClassName,DOCREATE,ClassType) \
44  \
45 OD_IFC_DEFINE_MEMBERS2(ClassName,ParentClass,ClassName::pseudoConstructor,0,0,0,szClassName,OdString::kEmpty,OdString::kEmpty,0,ClassType) \
46  \
47 ODRX_DEFINE_PSEUDOCONSTRUCTOR(ClassName,DOCREATE)
48 
49 #define OD_IFC_DEFINE_MEMBERS2(ClassName,ParentClass,pseudoConsFn,DwgVer,MaintVer,nProxyFlags,szDWGClassName,szDxfName,szAppName,nCustomFlags,ClassType) \
50  \
51 ODRX_DEFINE_RTTI_MEMBERS(ClassName,ParentClass) \
52  \
53 OD_IFC_DEFINE_INIT_MEMBERS(ClassName,ParentClass,pseudoConsFn, \
54  DwgVer,MaintVer,nProxyFlags,szDWGClassName,szDxfName,szAppName,nCustomFlags, ClassType)
55 
56 
57 #define OD_IFC_DEFINE_INIT_MEMBERS(ClassName, ParentClass, pseudoConsFn, DwgVer, \
58  MaintVer, nProxyFlags, szDWGClassName, \
59  szDxfName, szAppName, nCustomFlags, ClassType) \
60  OD_IFC_DEFINE_INIT_MEMBERS_GENERIC( \
61  ClassName, \
62  (::newOdRxClass(szDWGClassName, ParentClass::desc(), pseudoConsFn, DwgVer, \
63  MaintVer, nProxyFlags, szDxfName, szAppName, NULL, nCustomFlags)), \
64  (::newOdRxClass(szDWGClassName, ParentClass::desc(), pseudoConsFn, DwgVer, \
65  MaintVer, nProxyFlags, szDxfName, szAppName, pAppNameChangeCallback, nCustomFlags)), \
66  ClassType)
67 
68 #define OD_IFC_DEFINE_INIT_MEMBERS_GENERIC(ClassName, CREATE_CLASS_INSTANCE, CREATE_CLASS_INSTANCE2, ClassType)\
69 void ClassName::rxInit() \
70 { \
71  if (!ClassName::g_pDesc) { \
72  ClassName::g_pDesc = CREATE_CLASS_INSTANCE; \
73  odIfcClassDictionary().putAt(ClassType, ClassName::desc()); \
74  } else { \
75  ODA_ASSERT(("Class ["#ClassName"] is already initialized.",0)); \
76  throw OdError(eExtendedError); \
77  } \
78 } \
79 void ClassName::rxInit(AppNameChangeFuncPtr pAppNameChangeCallback) \
80 { \
81  if (!ClassName::g_pDesc) { \
82  ClassName::g_pDesc = CREATE_CLASS_INSTANCE2; \
83  odIfcClassDictionary().putAt(ClassType, ClassName::desc()); \
84  } else { \
85  ODA_ASSERT(("Class ["#ClassName"] is already initialized.",0)); \
86  throw OdError(eExtendedError); \
87  } \
88 } \
89  \
90 /* Unregisters this class with ODA Platform. */ \
91 void ClassName::rxUninit() \
92 { \
93  if (ClassName::g_pDesc) { \
94  ::deleteOdRxClass(ClassName::g_pDesc); \
95  ClassName::g_pDesc = 0; \
96  odIfcClassDictionary().remove(ClassType); \
97  } else { \
98  ODA_ASSERT(("Class ["#ClassName"] is not initialized yet.",0)); \
99  throw OdError(eNotInitializedYet); \
100  } \
101 }
102 
103 #define OD_IFC_DECLARE_MEMBERS_GENERIC(ClassType, ClassName) \
104 public: \
105  static OdSmartPtr<ClassName> cast(const OdRxObject* pObj) \
106  { \
107  if (pObj) \
108  return OdSmartPtr<ClassName>(((ClassName*)pObj->queryX(ClassName::desc())), kOdRxObjAttach); \
109  return (ClassName*)0; \
110  } \
111  static ClassType* g_pDesc; \
112  static ClassType* desc(); \
113  virtual ClassType* isA() const; \
114  virtual OdRxObject* queryX(const OdRxClass* protocolClass) const; \
115  static OdRxObjectPtr pseudoConstructor(); \
116  static OdSmartPtr<ClassName> createObject() \
117  { if (!desc()) throw OdError(eNotInitializedYet); return desc()->create(); } \
118  static OdSmartPtr<ClassName> createObject(OdIfcModel* pModel) \
119  { \
120  if (!pModel) \
121  throw OdError(eNoDatabase); \
122  if (!desc()) \
123  throw OdError(eNotInitializedYet); \
124  OdSmartPtr<ClassName> pObj = desc()->create(); \
125  OdIfcEntityPtr pEnt = pModel->createEntityInstance(desc()->name().mid(2)); \
126  if (pEnt.isNull()) \
127  throw OdError(eIllegalEntityType); \
128  pModel->appendEntityInstance(pEnt); \
129  pObj->m_pEntInst = pEnt; \
130  pEnt->resolve(kResCompound, new OdIfcCompoundPtr(pObj)); \
131  return pObj; \
132  } \
133  static void rxInit(); \
134  static void rxInit(AppNameChangeFuncPtr appNameChangeFunc); \
135  \
136  static void rxUninit()
137 
138 #define OD_IFC_DECLARE_MEMBERS(ClassName) \
139  OD_IFC_DECLARE_MEMBERS_GENERIC(OdRxClass, ClassName)
140 
141 #endif // _IFC_COMMON_H_