MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlBase.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_BASE_H
14#define ML_BASE_H
15
20
21// Project-includes
22#include "mlUtilsSystem.h"
23#include "mlRuntimeSubClass.h"
24#include "mlRuntime.h"
25
26#include <ThirdPartyWarningsDisable.h>
27#include <string>
28#include <vector>
29#include <ThirdPartyWarningsRestore.h>
30
32#define ML_SET_ADDSTATE_VERSION(v) \
33 static int getAddStateVersion(void) \
34 { \
35 return v; \
36 };
38#define ML_PERSISTENCE_VERSION(v) ML_SET_ADDSTATE_VERSION(v)
39
41
43class TreeNode;
44class AbstractPersistenceOutputStream;
45class AbstractPersistenceInputStream;
47
48//----------------------------------------------------------------------
53
61//----------------------------------------------------------------------
63{
64public:
67
69 virtual ~Base();
70
72
74
81
85 {
86 return false;
87 }
88
90 virtual std::string persistentState() const;
91
94 virtual void setPersistentState(const std::string& state);
95
97 virtual void addStateToTree(TreeNode* /*parent*/) const
98 {
99 ;
100 }
101
103 virtual void readStateFromTree(TreeNode* /*parent*/)
104 {
105 ;
106 }
107
115 virtual void writeTo(AbstractPersistenceOutputStream* /*stream*/) const
116 {}
117
127 virtual void readFrom(AbstractPersistenceInputStream* /*stream*/, int /*version*/)
128 {}
129
130 // Sets addStateToTree version number that can be accessed via getAddStateVersion()
132
133
134
135
138 virtual Base* deepCopy() const
139 {
140 return nullptr;
141 };
142
146 bool isOfAllowedType(const std::vector<const RuntimeType*>& types) const;
147
149 virtual bool isRefCountedBase() const
150 {
151 return false;
152 }
153
156 virtual std::string detailString() const
157 {
158 return std::string();
159 }
160
164};
165
167
168#undef ML_BASE_VERSION
169
171
197template <typename ToTypePtr> inline ToTypePtr mlbase_cast(ML_UTILS_NAMESPACE::Base* from)
198{
199 if (from) {
200 if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
201 return static_cast<ToTypePtr>(from);
202 }
203 else {
204 return NULL;
205 }
206 }
207 else {
208 return NULL;
209 }
210}
211
213template <typename ToTypePtr> inline ToTypePtr mlbase_cast(const ML_UTILS_NAMESPACE::Base* from)
214{
215 if (from) {
216 if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
217 return static_cast<ToTypePtr>(from);
218 }
219 else {
220 return NULL;
221 }
222 }
223 else {
224 return NULL;
225 }
226}
227
228#endif // __mlBase_H
Class for reading object data from a stream.
Class for writing object data to a stream.
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
virtual void setPersistentState(const std::string &state)
Restores the object's internal state from a string that had been previously generated using persisten...
virtual std::string detailString() const
Returns a string describing this object.
Definition mlBase.h:156
virtual bool implementsPersistence(PersistenceInterface) const
Override this method to declare which persistence interfaces are implemented by your derived class.
Definition mlBase.h:84
Base()
Constructor.
virtual std::string persistentState() const
Returns a string describing the object's internal state.
virtual void addStateToTree(TreeNode *) const
Attaches the object state as children of the given parent node.
Definition mlBase.h:97
virtual ~Base()
Destructor.
virtual void readFrom(AbstractPersistenceInputStream *, int)
Reads the objects state from the data stream object.
Definition mlBase.h:127
virtual bool isRefCountedBase() const
Returns whether the instance is derived from RefCountedBase.
Definition mlBase.h:149
virtual void writeTo(AbstractPersistenceOutputStream *) const
Writes the objects state to the data stream object.
Definition mlBase.h:115
bool isOfAllowedType(const std::vector< const RuntimeType * > &types) const
Checks whether this object's type is equal to or derived from one of the types given in the argument.
PersistenceInterface
This enum describes the different persistence interfaces available.
Definition mlBase.h:76
@ PersistenceByString
Definition mlBase.h:77
@ PersistenceByTreeNode
Definition mlBase.h:78
virtual void readStateFromTree(TreeNode *)
Reads the object state from the children of the given parent node.
Definition mlBase.h:103
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:160
ToTypePtr mlbase_cast(ml::Base *from)
Template function to allow type-safe casting of a base object to a derived object.
Definition mlBase.h:197
#define ML_PERSISTENCE_VERSION(v)
Nicer name for ML_SET_ADDSTATE_VERSION.
Definition mlBase.h:38
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18