OpenLexocad  28.0
Base.h
Go to the documentation of this file.
1 #pragma once
2 #include <Base/Type.h>
3 
4 namespace Core
5 {
6 class CoreDocument;
7 }
8 
9 
10 
12 #define TYPESYSTEM_HEADER() \
13 public: \
14  friend class Core::CoreDocument; \
15  static Base::Type getClassTypeId(void); \
16  virtual Base::Type getTypeId(void) const; \
17  static void setIfcNameAndID(const std::string& s, int id); \
18  static void init(void); \
19  static void* create(void); \
20 \
21 private: \
22  static Base::Type classTypeId; \
23  static std::string ifcEntityName; \
24  static int ifcEntityID;
25 
26 
28 #define TYPESYSTEM_SOURCE_P(_class_) \
29  Base::Type _class_::getClassTypeId(void) { return ::_class_::classTypeId; } \
30  Base::Type _class_::getTypeId(void) const { return ::_class_::classTypeId; } \
31  void _class_::setIfcNameAndID(const std::string& s, int id) \
32  { \
33  ifcEntityName = s; \
34  ifcEntityID = id; \
35  } \
36  Base::Type _class_::classTypeId = Base::Type::badType(); \
37  std::string _class_::ifcEntityName; \
38  int _class_::ifcEntityID; \
39  void* _class_::create(void) { return new ::_class_(); }
40 
42 #define TYPESYSTEM_SOURCE_ABSTRACT_P(_class_) \
43  Base::Type _class_::getClassTypeId(void) { return ::_class_::classTypeId; } \
44  Base::Type _class_::getTypeId(void) const { return ::_class_::classTypeId; } \
45  void _class_::setIfcNameAndID(const std::string& s, int id) \
46  { \
47  ifcEntityName = s; \
48  ifcEntityID = id; \
49  } \
50  Base::Type _class_::classTypeId = Base::Type::badType(); \
51  std::string _class_::ifcEntityName; \
52  int _class_::ifcEntityID; \
53  void* _class_::create(void) { return 0; }
54 
55 
57 #define TYPESYSTEM_SOURCE(_class_, _parentclass_) \
58  TYPESYSTEM_SOURCE_P(_class_); \
59  void _class_::init(void) \
60  { \
61  initSubclass(::_class_::classTypeId, #_class_, #_parentclass_, &(::_class_::create)); \
62  initIfcTypes(::_class_::ifcEntityName, ::_class_::classTypeId, ::_class_::ifcEntityID); \
63  }
64 
66 #define TYPESYSTEM_SOURCE_ABSTRACT(_class_, _parentclass_) \
67  TYPESYSTEM_SOURCE_ABSTRACT_P(_class_); \
68  void _class_::init(void) \
69  { \
70  initSubclass(::_class_::classTypeId, #_class_, #_parentclass_, &(::_class_::create)); \
71  initIfcTypes(::_class_::ifcEntityName, ::_class_::classTypeId, ::_class_::ifcEntityID); \
72  }
73 
74 namespace Base
75 {
77 class LX_BASE_EXPORT BaseClass
78 {
79 public:
81  // //
82  // --------------------- BEGIN API --------------------- //
83  // //
84  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
85  // //
87 
88  static Type getClassTypeId(void);
89  virtual Type getTypeId(void) const;
90  static void init(void);
91 
92  static void* create(void) { return 0; }
93  static void setIfcNameAndID(const std::string& n, int id);
94 
95  // DG, Debugging, after destructor, this value is 0xDEADBEEF
96  long ____deadVal = 0xBADEAFFE;
97 
98 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
99  template <typename T>
100  bool isDerivedFrom() const
101  {
102  return getTypeId().isDerivedFrom(T::getClassTypeId());
103  }
104 #endif
105 
106  bool isDerivedFrom(const Type type) const { return getTypeId().isDerivedFrom(type); }
107 
109  // //
110  // ---------------------- END API ---------------------- //
111  // //
113 
114 
115  void* operator new(size_t size)
116  {
117  //cout << "Overloading new operator with size: " << size << endl;
118  void* p = ::operator new(size);
119  return p;
120  }
121 
122  void operator delete(void* p)
123  {
124  //cout << "Overloading delete operator " << endl;
125  free(p);
126  }
127 
128  /*
129  BaseClass* operator->()
130  {
131  return this;
132  }
133  */
134 
136  {
137  return this;
138  }
139 
141  {
142  BaseClass* me = (BaseClass*)(this);
143  return me;
144  }
145 
146  /*
147  BaseClass* operator->() const
148  {
149  return static_cast<BaseClass*>(this);
150  }
151  */
152 
153 private:
154  static Type classTypeId;
155  static std::string ifcEntityName;
156  static int ifcEntityID;
157 
158 protected:
159  static void initSubclass(Base::Type& toInit, const char* ClassName, const char* ParentName, Type::instantiationMethod method = 0);
160  static void initIfcTypes(const std::string& s, Base::Type classTypeId, int id);
161 
162 public:
164  BaseClass() = default;
166  virtual ~BaseClass();
167 
168 
169 
170 
171 private:
172  int getEntityTypeID();
173  std::string getEntityTypeString();
174  static int getEntityTypeIDStatic();
175  static std::string getEntityTypeStringStatic();
176  static std::vector<Base::Type> getLxTypeForIfcEntityTypeID(int id);
177  std::vector<Base::Type> getLxTypeForIfcEntityTypeString(std::string& s);
178  static int getIfcEntityTypeIDForLxType(Base::Type t);
179  static std::map<Base::Type, std::string> getLxTypesMap();
180 
181 };
182 
183 
184 template <typename T>
186 {
187  return dynamic_cast<T*>(b);
188 
189 /*
190 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
191  if (b && b->isDerivedFrom<T>())
192  return (T*)b;
193  else
194  return 0;
195 #endif
196 */
197 }
198 
199 template <typename T>
200 const T* ccast2(const Base::BaseClass* b)
201 {
202  return dynamic_cast<const T*>(b);
203 /*
204 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
205  if (b && b->isDerivedFrom<T>())
206  return (T*)b;
207  else
208  return 0;
209 #endif
210 */
211 }
212 
213 } // namespace Base
Base::Type
Definition: Type.h:51
Base::BaseClass
BaseClass class and root of the type system.
Definition: Base.h:78
Core::CoreDocument
Definition: CoreDocument.h:269
Base::BaseClass::create
static void * create(void)
Definition: Base.h:92
Base::ccast2
const T * ccast2(const Base::BaseClass *b)
Definition: Base.h:200
Base::Type::instantiationMethod
void *(* instantiationMethod)(void)
Definition: Type.h:64
Base::cast2
T * cast2(Base::BaseClass *b)
Definition: Base.h:185
Base::BaseClass::isDerivedFrom
bool isDerivedFrom() const
Definition: Base.h:100
Base::BaseClass::isDerivedFrom
bool isDerivedFrom(const Type type) const
Definition: Base.h:106
Base::BaseClass::~BaseClass
virtual ~BaseClass()
Destruction.
Core
Definition: Base.h:5
Base::BaseClass::init
static void init(void)
Base::BaseClass::getClassTypeId
static Type getClassTypeId(void)
Base::BaseClass::operator->
BaseClass * operator->() const
Definition: Base.h:140
Base::BaseClass::operator->
BaseClass * operator->()
Definition: Base.h:135
Type.h
Base::BaseClass::BaseClass
BaseClass()=default
Construction.
Base::BaseClass::initIfcTypes
static void initIfcTypes(const std::string &s, Base::Type classTypeId, int id)
Base::BaseClass::setIfcNameAndID
static void setIfcNameAndID(const std::string &n, int id)
Base::BaseClass::initSubclass
static void initSubclass(Base::Type &toInit, const char *ClassName, const char *ParentName, Type::instantiationMethod method=0)
Base::BaseClass::getTypeId
virtual Type getTypeId(void) const
Base
Definition: AbstractXMLReader.h:5