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