MeVisLab Toolbox Reference
mlRuntimeType.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_TYPE_H
14#define ML_RUNTIME_TYPE_H
15
21
22//ML-includes
23#include "mlUtilsSystem.h"
24
25#include <ostream>
26
28
29 //-------------------------------------------------------------------------
34
52 //-------------------------------------------------------------------------
54 public:
57 typedef void* RuntimeTypeCreateCB();
58
59 //----------------------------------------------------------
62 //----------------------------------------------------------
69 ML_UTILS_EXPORT RuntimeType(const RuntimeType *parent = nullptr,
70 const char *className = nullptr,
71 RuntimeTypeCreateCB *callback = nullptr,
72 const char *dllName = nullptr);
73
76
82
84 inline const char* getName() const { return _className ? _className : "BadType"; }
85
87 inline const char* getDllName() const { return _dllName ? _dllName : ""; }
88
91 inline const RuntimeType* getParent() const { return _parent; }
92
94 inline bool canCreateInstance() const { return _callback!=nullptr; }
95
98 inline void* createInstance() const { return _callback ? (*_callback)() : nullptr; }
99
101 inline RuntimeTypeCreateCB * getCallback() const { return _callback; }
102
104 inline MLint getId() const { return _id; }
105
107
108 private:
110 char* _className;
111
113 char* _dllName;
114
116 const RuntimeType* _parent;
117
119 MLint _id;
120
122 RuntimeTypeCreateCB* _callback;
123 };
124
126
127
128//-----------------------------------------------------------------------------------
129// Stream output for std::ostream
130//-----------------------------------------------------------------------------------
131namespace std {
132
134 inline ostream& operator<<(ostream& s, const ML_UTILS_NAMESPACE::RuntimeType &rt)
135 {
136 s << "Class: "
137 << " Name :" << rt.getName()
138 << " DllName :" << rt.getDllName()
139 << " Parent: " << (rt.getParent() ? rt.getParent()->getName() : "NULL")
140 << " Abstract: " << (rt.getCallback() ? "No" : "Yes")
141 << std::endl;
142 return s;
143 }
144
145}
146
147#endif // __mlRuntimeType_H
148
149
RuntimeType contains type and inheritance information of a class and a static dictionary with informa...
void * RuntimeTypeCreateCB()
A type of a callback function to create an instance of a class handled by the Runtime class.
const RuntimeType * getParent() const
Returns the parent (runtime) type of the type, i.e., the type it is derived from or NULL if not deriv...
const char * getDllName() const
Returns the NULL-terminated string name of the source DLL or "" if it is unknown.
MLint getId() const
Returns the ID that describes where the type was registered in the Runtime Type System.
bool canCreateInstance() const
Returns true if this (runtime) type knows how to create an instance of the class.
ML_UTILS_EXPORT RuntimeType(const RuntimeType *parent=nullptr, const char *className=nullptr, RuntimeTypeCreateCB *callback=nullptr, const char *dllName=nullptr)
Constructor.
void * createInstance() const
Creates and returns an instance of the of the class or NULL if such an instance is unavailable.
RuntimeTypeCreateCB * getCallback() const
Returns the callback used to create an instance of the object or NULL on abstract classes.
ML_UTILS_EXPORT bool isDerivedFrom(const RuntimeType *runtimeType) const
Returns true if this (runtime) type is derived from the argument (runtime) type runtimeType.
ML_UTILS_EXPORT ~RuntimeType()
Destructor. Cleans up all elements.
const char * getName() const
Returns the NULL-terminated string name of the class. Returns 'BadType' on error.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.