MeVisLab Toolbox 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
#if ML_DEPRECATED_SINCE(3,5,0)
41
#define BASE_IS_A(base, type) ML_BASE_IS_A(base, type)
43
#endif
44
45
//--------------------------------------------------------------
47
//--------------------------------------------------------------
48
#ifndef ML_EMPTY_PARAM
49
#define ML_EMPTY_PARAM
50
#endif
51
52
#define ML_INTERNAL_CLASS_HEADER_CREATECB(EXP_SYM) \
53
public: \
54
/* Creates an instance of this class type. */
\
55
[[nodiscard]] \
56
EXP_SYM static void* createCB(); \
57
private:
58
59
#define ML_INTERNAL_CLASS_HEADER_EXPORTED(className, EXP_SYM, ML_INTERNAL_VIRTUAL, ML_INTERNAL_OVERRIDE) \
60
public: \
61
/* Creates a new runtime type from class name and insert */
\
62
/* it into the runtime type system. */
\
63
/* A \p classPrefix (a null terminated string) can be passed */
\
64
/* which then will be prefixed to the class name before */
\
65
/* creating the runtime type name from it. */
\
66
/* \p nameReplacement is also a null terminated string which */
\
67
/* will be used as replacement of the class name if passed as */
\
68
/* non nullptr. It will still be prefixed if a prefix is passed. */
\
69
EXP_SYM static void initClass(const char* classPrefix=nullptr, \
70
const char* nameReplacement=nullptr);\
71
\
72
/* Removes the class type from the runtime type system. */
\
73
EXP_SYM static void destroyClass(); \
74
\
75
/* Returns the runtime type of this class. */
\
76
EXP_SYM static const RuntimeType* getClassTypeId(); \
77
\
78
/* Returns the (evt. overloaded) runtime type of this object.*/
\
79
EXP_SYM ML_INTERNAL_VIRTUAL const RuntimeType* getTypeId() const ML_INTERNAL_OVERRIDE; \
80
\
81
/* Returns the null terminated type name of this runtime type*/
\
82
/* or the string "<Name of Uninitialized Type>" if the type */
\
83
/* is still uninitialized. That case will also cause an ML */
\
84
/* error message with code ML_TYPE_NOT_REGISTERED. */
\
85
EXP_SYM ML_INTERNAL_VIRTUAL const char* getTypeIdName() const ML_INTERNAL_OVERRIDE; \
86
\
87
private: \
88
/* Pointer to the runtime type of this class which is stored */
\
89
/* in the runtime type system. */
\
90
static const RuntimeType* _classType;
91
92
//--------------------------------------------------------------
99
//--------------------------------------------------------------
100
#define ML_CLASS_HEADER_EXPORTED(className, EXP_SYM) \
101
ML_INTERNAL_CLASS_HEADER_EXPORTED(className, EXP_SYM, ML_EMPTY_PARAM, override) \
102
ML_INTERNAL_CLASS_HEADER_CREATECB(EXP_SYM)
103
104
//--------------------------------------------------------------
107
//--------------------------------------------------------------
108
#define ML_CLASS_HEADER(className) \
109
ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, ML_EMPTY_PARAM, override) \
110
ML_INTERNAL_CLASS_HEADER_CREATECB(ML_EMPTY_PARAM)
111
112
#define ML_ROOT_CLASS_HEADER(className) \
113
ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, virtual, ML_EMPTY_PARAM) \
114
ML_INTERNAL_CLASS_HEADER_CREATECB(ML_EMPTY_PARAM)
115
116
#define ML_INTERNAL_CLASS_SOURCE(className,parentName,createCB) \
117
\
118
/* Pointer to the runtime type of this class which is stored */
\
119
/* in the runtime type system. Types should be initialized */
\
120
/* to nullptr since Runtime::badType() could be initialized */
\
121
/* to nullptr later than the type itself. */
\
122
const RuntimeType* className::_classType = nullptr; \
123
\
124
/* Creates a new runtime type from class name and insert */
\
125
/* it into the runtime type system. */
\
126
/* A \p classPrefix (a null terminated string) can be passed */
\
127
/* which then will be prefixed to the class name before */
\
128
/* creating the runtime type name from it. */
\
129
/* \p nameReplacement is also a null terminated string which */
\
130
/* will be used as replacement of the class name if passed as */
\
131
/* non nullptr. It will still be prefixed if a prefix is passed. */
\
132
void className::initClass(const char* classPrefix, \
133
const char* nameReplacement) \
134
{ \
135
_classType = Runtime::initType(_classType, \
136
#parentName, \
137
classPrefix, \
138
#className, \
139
createCB, \
140
nameReplacement); \
141
} \
142
/* Removes the class type from the runtime type system. */
\
143
void className::destroyClass() \
144
{ \
145
Runtime::destroyType(#className); \
146
} \
147
\
148
/* Returns the runtime type of this class. */
\
149
const RuntimeType* className::getClassTypeId() \
150
{ \
151
return _classType; \
152
} \
153
\
154
/* Returns the (evt. overloaded) runtime type of this object.*/
\
155
const RuntimeType* className::getTypeId() const \
156
{ \
157
return _classType; \
158
} \
159
\
160
/* Returns the null terminated type name of this runtime type */
\
161
/* or the string "<Name of Uninitialized Type>" if the type */
\
162
/* is still uninitialized. That case will also cause an ML */
\
163
/* error message with code ML_TYPE_NOT_REGISTERED. */
\
164
const char* className::getTypeIdName() const \
165
{ \
166
return Runtime::_getCheckedTypeIdName(_classType, #className); \
167
}
168
169
#define ML_INTERNAL_CLASS_CREATECB(className) \
170
/* Creates an instance of this class type. */
\
171
void* className::createCB() \
172
{ \
173
return new className(); \
174
} \
175
176
177
//--------------------------------------------------------------
183
//--------------------------------------------------------------
184
#define ML_CLASS_SOURCE(className,parentName) \
185
ML_INTERNAL_CLASS_SOURCE(className,parentName, className::createCB) \
186
ML_INTERNAL_CLASS_CREATECB(className)
187
188
//--------------------------------------------------------------
193
//--------------------------------------------------------------
194
#define ML_ROOT_CLASS_SOURCE(className) \
195
ML_CLASS_SOURCE(className,)
196
197
198
//--------------------------------------------------------------
203
//--------------------------------------------------------------
204
#define ML_ABSTRACT_CLASS_HEADER_EXPORTED(className, EXP_SYM) \
205
ML_INTERNAL_CLASS_HEADER_EXPORTED(className, EXP_SYM, ML_EMPTY_PARAM, override)
206
207
//--------------------------------------------------------------
211
//--------------------------------------------------------------
212
#define ML_ABSTRACT_CLASS_HEADER(className) \
213
ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, ML_EMPTY_PARAM, override)
214
215
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className) \
216
ML_INTERNAL_CLASS_HEADER_EXPORTED(className, ML_EMPTY_PARAM, virtual , ML_EMPTY_PARAM)
217
218
//--------------------------------------------------------------
224
//--------------------------------------------------------------
225
#define ML_ABSTRACT_CLASS_SOURCE(className,parentName) \
226
ML_INTERNAL_CLASS_SOURCE(className,parentName, nullptr) \
227
228
//--------------------------------------------------------------
233
//--------------------------------------------------------------
234
#define ML_ABSTRACT_ROOT_CLASS_SOURCE(className) \
235
ML_ABSTRACT_CLASS_SOURCE(className,)
236
237
238
//--------------------------------------------------------------
244
//--------------------------------------------------------------
245
#define ML_MODULE_CLASS_HEADER(className) \
246
/* Implement normal class header stuff. */
\
247
ML_CLASS_HEADER(className) \
248
\
249
/* Implement private copy constructor. */
\
250
private: className(const className&); \
251
\
252
/* Implement private assignment operator. */
\
253
private: className& operator=(const className&); \
254
255
256
//--------------------------------------------------------------
263
//--------------------------------------------------------------
264
#define ML_MODULE_CLASS_SOURCE(className, parentName) \
265
/* Implement normal class source stuff. */
\
266
ML_CLASS_SOURCE(className, parentName)
267
268
//--------------------------------------------------------------
274
//--------------------------------------------------------------
275
#define ML_ABSTRACT_MODULE_CLASS_HEADER(className) \
276
/* Implement normal class header stuff. */
\
277
ML_ABSTRACT_CLASS_HEADER(className) \
278
\
279
/* Implement private copy constructor. */
\
280
private: className(const className&); \
281
\
282
/* Implement private assignment operator. */
\
283
private: className& operator=(const className&); \
284
285
286
//--------------------------------------------------------------
293
//--------------------------------------------------------------
294
#define ML_ABSTRACT_MODULE_CLASS_SOURCE(className, parentName) \
295
/* Implement normal class source stuff. */
\
296
ML_ABSTRACT_CLASS_SOURCE(className, parentName)
297
298
299
//--------------------------------------------------------------
303
//--------------------------------------------------------------
304
#define ML_MODULE_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
305
/* Implement normal class source stuff. */
\
306
ML_CLASS_SOURCE(className, parentName)
307
308
309
//--------------------------------------------------------------
313
//--------------------------------------------------------------
314
#define ML_ABSTRACT_MODULE_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
315
/* Implement normal class source stuff. */
\
316
ML_ABSTRACT_CLASS_SOURCE(className, parentName)
317
318
319
#if ML_DEPRECATED_SINCE(3,5,0)
320
323
326
#define ML_BASEOP_CLASS_HEADER(className) \
327
ML_MODULE_CLASS_HEADER(className)
330
#define ML_BASEOP_CLASS_SOURCE(className, parentName) \
331
ML_MODULE_CLASS_SOURCE(className, parentName)
332
335
#define ML_ABSTRACT_BASEOP_CLASS_HEADER(className) \
336
ML_ABSTRACT_MODULE_CLASS_HEADER(className)
337
340
#define ML_ABSTRACT_BASEOP_CLASS_SOURCE(className, parentName) \
341
ML_ABSTRACT_MODULE_CLASS_SOURCE(className, parentName)
342
345
#define ML_BASEOP_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
346
ML_CLASS_SOURCE(className, parentName)
347
350
#define ML_ABSTRACT_BASEOP_CLASS_SOURCE_EXT(className, parentName, superClassConstructs) \
351
ML_ABSTRACT_CLASS_SOURCE(className, parentName)
352
354
355
#endif
// ML_DEPRECATED
356
357
358
#endif
// __mlRuntimeSubClass_H
359
mlRuntimeType.h
MeVis
Foundation
Sources
MLUtilities
mlRuntimeSubClass.h
Generated by
1.9.1