OpenLexocad  27.0
Base.h
Go to the documentation of this file.
1 #pragma warning(disable : 4251)
2 
3 #ifndef __Base_H__
4 #define __Base_H__
5 
6 // Std. configurations
7 
8 #include <Base/base_defines.h>
9 
10 #pragma warning(push)
11 #pragma warning(disable : 4100)
12 #include <string>
13 #pragma warning(pop)
14 #include <map>
15 
16 #include "Type.h"
17 
18 
19 namespace Core
20 {
21 class CoreDocument;
22 }
23 
24 
25 
27 #define TYPESYSTEM_HEADER() \
28 public: \
29  friend class Core::CoreDocument; \
30  static Base::Type getClassTypeId(void); \
31  virtual Base::Type getTypeId(void) const; \
32  static void setIfcNameAndID(std::string s, int id); \
33  static void init(void); \
34  static void* create(void); \
35 \
36 private: \
37  static Base::Type classTypeId; \
38  static std::string ifcEntityName; \
39  static int ifcEntityID;
40 
41 
43 #define TYPESYSTEM_SOURCE_P(_class_) \
44  Base::Type _class_::getClassTypeId(void) { return ::_class_::classTypeId; } \
45  Base::Type _class_::getTypeId(void) const { return ::_class_::classTypeId; } \
46  void _class_::setIfcNameAndID(std::string s, int id) \
47  { \
48  ifcEntityName = s; \
49  ifcEntityID = id; \
50  } \
51  Base::Type _class_::classTypeId = Base::Type::badType(); \
52  std::string _class_::ifcEntityName; \
53  int _class_::ifcEntityID; \
54  void* _class_::create(void) { return new ::_class_(); }
55 
57 #define TYPESYSTEM_SOURCE_ABSTRACT_P(_class_) \
58  Base::Type _class_::getClassTypeId(void) { return ::_class_::classTypeId; } \
59  Base::Type _class_::getTypeId(void) const { return ::_class_::classTypeId; } \
60  void _class_::setIfcNameAndID(std::string s, int id) \
61  { \
62  ifcEntityName = s; \
63  ifcEntityID = id; \
64  } \
65  Base::Type _class_::classTypeId = Base::Type::badType(); \
66  std::string _class_::ifcEntityName; \
67  int _class_::ifcEntityID; \
68  void* _class_::create(void) { return 0; }
69 
70 
72 #define TYPESYSTEM_SOURCE(_class_, _parentclass_) \
73  TYPESYSTEM_SOURCE_P(_class_); \
74  void _class_::init(void) \
75  { \
76  initSubclass(::_class_::classTypeId, #_class_, #_parentclass_, &(::_class_::create)); \
77  initIfcTypes(::_class_::ifcEntityName, ::_class_::classTypeId, ::_class_::ifcEntityID); \
78  }
79 
81 #define TYPESYSTEM_SOURCE_ABSTRACT(_class_, _parentclass_) \
82  TYPESYSTEM_SOURCE_ABSTRACT_P(_class_); \
83  void _class_::init(void) \
84  { \
85  initSubclass(::_class_::classTypeId, #_class_, #_parentclass_, &(::_class_::create)); \
86  initIfcTypes(::_class_::ifcEntityName, ::_class_::classTypeId, ::_class_::ifcEntityID); \
87  }
88 
89 namespace Base
90 {
93 {
94 public:
96  // //
97  // --------------------- BEGIN API --------------------- //
98  // //
99  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
100  // //
102 
103  static Type getClassTypeId(void);
104  virtual Type getTypeId(void) const;
105  static void init(void);
106 
107  static void* create(void) { return 0; }
108  static void setIfcNameAndID(std::string n, int id);
109 
110 
111 
112 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
113  template <typename T>
114  bool isDerivedFrom() const
115  {
116  return getTypeId().isDerivedFrom(T::getClassTypeId());
117  }
118 #endif
119  // //
121  // ---------------------- END API ---------------------- //
122  // //
124 
125 private:
126  static Type classTypeId;
127  static std::string ifcEntityName;
128  static int ifcEntityID;
129 
130 protected:
131  static void initSubclass(Base::Type& toInit, const char* ClassName, const char* ParentName, Type::instantiationMethod method = 0);
132  static void initIfcTypes(std::string s, Base::Type classTypeId, int id);
133 
134 public:
136  BaseClass();
138  virtual ~BaseClass();
139 
140 private:
141  int getEntityTypeID();
142  std::string getEntityTypeString();
143  static int getEntityTypeIDStatic();
144  static std::string getEntityTypeStringStatic();
145  static std::vector<Base::Type> getLxTypeForIfcEntityTypeID(int id);
146  std::vector<Base::Type> getLxTypeForIfcEntityTypeString(std::string& s);
147  static int getIfcEntityTypeIDForLxType(Base::Type t);
148  static std::map<Base::Type, std::string> getLxTypesMap();
149 
150 };
151 
152 
153 template <typename T>
155 {
156  return dynamic_cast<T*>(b);
157 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
158  if (b && b->isDerivedFrom<T>())
159  return (T*)b;
160  else
161  return 0;
162 #endif
163 }
164 
165 template <typename T>
166 const T* ccast2(const Base::BaseClass* b)
167 {
168  return dynamic_cast<const T*>(b);
169 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
170  if (b && b->isDerivedFrom<T>())
171  return (T*)b;
172  else
173  return 0;
174 #endif
175 }
176 
177 
178 } // namespace Base
179 
180 #endif
bool isDerivedFrom(const Type type) const
#define BASE_EXPORT
Definition: base_defines.h:12
void *(* instantiationMethod)(void)
Definition: Type.h:70
static void * create(void)
Definition: Base.h:107
Definition: Type.h:56
Definition: CoreDocument.h:197
BaseClass class and root of the type system.
Definition: Base.h:92
Definition: Base.h:19
bool isDerivedFrom() const
Definition: Base.h:114
const T * ccast2(const Base::BaseClass *b)
Definition: Base.h:166
T * cast2(Base::BaseClass *b)
Definition: Base.h:154
Definition: AbstractXMLReader.h:8