ML Reference
mlRuntimeSubClass.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_RUNTIME_SUB_CLASS_H
14#define ML_RUNTIME_SUB_CLASS_H
15
20
21#include "mlRuntimeType.h"
22
23//--------------------------------------------------------------
31//--------------------------------------------------------------
32#define ML_BASE_IS_A(base,type) ((base && base->getTypeId()) ? base->getTypeId()->isDerivedFrom(type::getClassTypeId()) : false)
33
34
35//--------------------------------------------------------------
37//--------------------------------------------------------------
38#ifndef ML_EMPTY_PARAM
39#define ML_EMPTY_PARAM
40#endif
41
42#define ML_INTERNAL_CLASS_HEADER_CREATECB(EXP_SYM) \
43public: \
44 /* Creates an instance of this class type. */ \
45 [[nodiscard]] \
46 EXP_SYM static void* createCB(); \
47private:
48
49#define ML_INTERNAL_CLASS_HEADER_EXPORTED(className, EXP_SYM, ML_INTERNAL_VIRTUAL, ML_INTERNAL_OVERRIDE) \
50public: \
51 /* Creates a new runtime type from class name and insert */\
52 /* it into the runtime type system. */\
53 /* A \p classPrefix (a null terminated string) can be passed */\
54 /* which then will be prefixed to the class name before */\
55 /* creating the runtime type name from it. */\
56 /* \p nameReplacement is also a null terminated string which */\
57 /* will be used as replacement of the class name if passed as */\
58 /* non nullptr. It will still be prefixed if a prefix is passed. */\
59 EXP_SYM static void initClass(const char* classPrefix=nullptr, \
60 const char* nameReplacement=nullptr);\
61 \
62 /* Removes the class type from the runtime type system. */ \
63 EXP_SYM static void destroyClass(); \
64 \
65 /* Returns the runtime type of this class. */ \
66 EXP_SYM static const RuntimeType* getClassTypeId(); \
67 \
68 /* Returns the (evt. overloaded) runtime type of this object.*/ \
69 EXP_SYM ML_INTERNAL_VIRTUAL const RuntimeType* getTypeId() const ML_INTERNAL_OVERRIDE; \
70 \
71 /* Returns the null terminated type name of this runtime type*/ \
72 /* or the string "<Name of Uninitialized Type>" if the type */ \
73 /* is still uninitialized. That case will also cause an ML */ \
74 /* error message with code ML_TYPE_NOT_REGISTERED. */ \
75 EXP_SYM ML_INTERNAL_VIRTUAL const char* getTypeIdName() const ML_INTERNAL_OVERRIDE; \
76 \
77private: \
78 /* Pointer to the runtime type of this class which is stored */ \
79 /* in the runtime type system. */ \
80 static const RuntimeType* _classType;
81
82//--------------------------------------------------------------
89//--------------------------------------------------------------
90#define ML_CLASS_HEADER_EXPORTED(className, EXP_SYM) \
91 ML_INTERNAL_CLASS_HEADER_EXPORTED(className, EXP_SYM, ML_EMPTY_PARAM, override) \
92 ML_INTERNAL_CLASS_HEADER_CREATECB(EXP_SYM)
93
94//--------------------------------------------------------------
97//--------------------------------------------------------------
98#define ML_CLASS_HEADER(className) \
99 ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, ML_EMPTY_PARAM, override) \
100 ML_INTERNAL_CLASS_HEADER_CREATECB(ML_EMPTY_PARAM)
101
102#define ML_ROOT_CLASS_HEADER(className) \
103 ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, virtual, ML_EMPTY_PARAM) \
104 ML_INTERNAL_CLASS_HEADER_CREATECB(ML_EMPTY_PARAM)
105
106#define ML_INTERNAL_CLASS_SOURCE(className,parentName,createCB) \
107 \
108/* Pointer to the runtime type of this class which is stored */ \
109/* in the runtime type system. Types should be initialized */ \
110/* to nullptr since Runtime::badType() could be initialized */ \
111/* to nullptr later than the type itself. */ \
112const RuntimeType* className::_classType = nullptr; \
113 \
114/* Creates a new runtime type from class name and insert */ \
115/* it into the runtime type system. */ \
116/* A \p classPrefix (a null terminated string) can be passed */ \
117/* which then will be prefixed to the class name before */ \
118/* creating the runtime type name from it. */ \
119/* \p nameReplacement is also a null terminated string which */ \
120/* will be used as replacement of the class name if passed as */ \
121/* non nullptr. It will still be prefixed if a prefix is passed. */ \
122void className::initClass(const char* classPrefix, \
123 const char* nameReplacement) \
124{ \
125 _classType = Runtime::initType(_classType, \
126 #parentName, \
127 classPrefix, \
128 #className, \
129 createCB, \
130 nameReplacement); \
131} \
132/* Removes the class type from the runtime type system. */ \
133void className::destroyClass() \
134{ \
135 Runtime::destroyType(#className); \
136} \
137 \
138/* Returns the runtime type of this class. */ \
139const RuntimeType* className::getClassTypeId() \
140{ \
141 return _classType; \
142} \
143 \
144/* Returns the (evt. overloaded) runtime type of this object.*/ \
145const RuntimeType* className::getTypeId() const \
146{ \
147 return _classType; \
148} \
149 \
150/* Returns the null terminated type name of this runtime type */ \
151/* or the string "<Name of Uninitialized Type>" if the type */ \
152/* is still uninitialized. That case will also cause an ML */ \
153/* error message with code ML_TYPE_NOT_REGISTERED. */ \
154const char* className::getTypeIdName() const \
155{ \
156 return Runtime::_getCheckedTypeIdName(_classType, #className); \
157}
158
159#define ML_INTERNAL_CLASS_CREATECB(className) \
160/* Creates an instance of this class type. */ \
161void* className::createCB() \
162{ \
163 return new className(); \
164} \
165
166
167//--------------------------------------------------------------
173//--------------------------------------------------------------
174#define ML_CLASS_SOURCE(className,parentName) \
175 ML_INTERNAL_CLASS_SOURCE(className,parentName, className::createCB) \
176 ML_INTERNAL_CLASS_CREATECB(className)
177
178//--------------------------------------------------------------
183//--------------------------------------------------------------
184#define ML_ROOT_CLASS_SOURCE(className) \
185 ML_CLASS_SOURCE(className,)
186
187
188//--------------------------------------------------------------
193//--------------------------------------------------------------
194#define ML_ABSTRACT_CLASS_HEADER_EXPORTED(className, EXP_SYM) \
195 ML_INTERNAL_CLASS_HEADER_EXPORTED(className, EXP_SYM, ML_EMPTY_PARAM, override)
196
197//--------------------------------------------------------------
201//--------------------------------------------------------------
202#define ML_ABSTRACT_CLASS_HEADER(className) \
203 ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, ML_EMPTY_PARAM, override)
204
205#define ML_ABSTRACT_ROOT_CLASS_HEADER(className) \
206 ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, virtual , ML_EMPTY_PARAM)
207
208//--------------------------------------------------------------
214//--------------------------------------------------------------
215#define ML_ABSTRACT_CLASS_SOURCE(className,parentName) \
216 ML_INTERNAL_CLASS_SOURCE(className,parentName, nullptr) \
217
218//--------------------------------------------------------------
223//--------------------------------------------------------------
224#define ML_ABSTRACT_ROOT_CLASS_SOURCE(className) \
225 ML_ABSTRACT_CLASS_SOURCE(className,)
226
227
228//--------------------------------------------------------------
234//--------------------------------------------------------------
235#define ML_MODULE_CLASS_HEADER(className) \
236 /* Implement normal class header stuff. */ \
237 ML_CLASS_HEADER(className) \
238 \
239 /* Implement private copy constructor. */ \
240 private: className(const className&); \
241 \
242 /* Implement private assignment operator. */ \
243 private: className& operator=(const className&); \
244
245
246//--------------------------------------------------------------
253//--------------------------------------------------------------
254#define ML_MODULE_CLASS_SOURCE(className, parentName) \
255 /* Implement normal class source stuff. */ \
256 ML_CLASS_SOURCE(className, parentName)
257
258//--------------------------------------------------------------
264//--------------------------------------------------------------
265#define ML_ABSTRACT_MODULE_CLASS_HEADER(className) \
266 /* Implement normal class header stuff. */ \
267 ML_ABSTRACT_CLASS_HEADER(className) \
268 \
269 /* Implement private copy constructor. */ \
270 private: className(const className&); \
271 \
272 /* Implement private assignment operator. */ \
273 private: className& operator=(const className&); \
274
275
276//--------------------------------------------------------------
283//--------------------------------------------------------------
284#define ML_ABSTRACT_MODULE_CLASS_SOURCE(className, parentName) \
285 /* Implement normal class source stuff. */ \
286 ML_ABSTRACT_CLASS_SOURCE(className, parentName)
287
288
289//--------------------------------------------------------------
293//--------------------------------------------------------------
294#define ML_MODULE_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
295 /* Implement normal class source stuff. */ \
296 ML_CLASS_SOURCE(className, parentName)
297
298
299//--------------------------------------------------------------
303//--------------------------------------------------------------
304#define ML_ABSTRACT_MODULE_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
305 /* Implement normal class source stuff. */ \
306 ML_ABSTRACT_CLASS_SOURCE(className, parentName)
307
308
309#endif // __mlRuntimeSubClass_H
310