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 
27 ML_UTILS_START_NAMESPACE
28 
29  //-------------------------------------------------------------------------
34 
52  //-------------------------------------------------------------------------
53  class RuntimeType {
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 
81  ML_UTILS_EXPORT bool isDerivedFrom(const RuntimeType* runtimeType) const;
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 
125 ML_UTILS_END_NAMESPACE
126 
127 
128 //-----------------------------------------------------------------------------------
129 // Stream output for std::ostream
130 //-----------------------------------------------------------------------------------
131 namespace 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...
Definition: mlRuntimeType.h:53
void * createInstance() const
Creates and returns an instance of the of the class (NULL if such an instance is unavailable).
Definition: mlRuntimeType.h:98
void * RuntimeTypeCreateCB()
A type of a callback function to create an instance of a class handled by the Runtime class.
Definition: mlRuntimeType.h:57
RuntimeTypeCreateCB * getCallback() const
Returns the callback used to create an instance of the object or NULL on abstract classes.
MLint getId() const
Returns the id which describes at which place 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.
Definition: mlRuntimeType.h:94
const char * getDllName() const
Returns the null terminated string name of the source dll or "" if it is unknown.
Definition: mlRuntimeType.h:87
ML_UTILS_EXPORT RuntimeType(const RuntimeType *parent=nullptr, const char *className=nullptr, RuntimeTypeCreateCB *callback=nullptr, const char *dllName=nullptr)
Constructor.
ML_UTILS_EXPORT bool isDerivedFrom(const RuntimeType *runtimeType) const
Returns true if this (runtime)type is derived from the argument (runtime)type runtimeType.
const RuntimeType * getParent() const
Returns the parent (runtime)type of the type, i.e., the type it is derived from or NULL if not derive...
Definition: mlRuntimeType.h:91
const char * getName() const
Returns the null terminated string name of the class. Returns "BadType" on error.
Definition: mlRuntimeType.h:84
ML_UTILS_EXPORT ~RuntimeType()
Destructor. Cleans up all stuff.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
#define ML_UTILS_EXPORT
Defines platform dependent DLL export macro for mlUtils.
Definition: mlUtilities.h:20