MeVisLab Toolbox Reference
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) static int getAddStateVersion(void) { return v; };
34#define ML_PERSISTENCE_VERSION(v) ML_SET_ADDSTATE_VERSION(v)
35
37
39class TreeNode;
40class AbstractPersistenceOutputStream;
41class AbstractPersistenceInputStream;
43
44//----------------------------------------------------------------------
49
57//----------------------------------------------------------------------
59{
60public:
61
64
66 virtual ~Base();
67
69
71
78
81 virtual bool implementsPersistence(PersistenceInterface) const { return false; }
82
84 virtual std::string persistentState() const;
85
88 virtual void setPersistentState(const std::string& state);
89
91 virtual void addStateToTree(TreeNode* /*parent*/) const { ; }
92
94 virtual void readStateFromTree(TreeNode* /*parent*/) { ; }
95
103 virtual void writeTo(AbstractPersistenceOutputStream* /*stream*/) const {}
104
114 virtual void readFrom(AbstractPersistenceInputStream* /*stream*/, int /*version*/) {}
115
118
119
120
121
124 virtual Base* deepCopy() const { return nullptr; };
125
129 bool isOfAllowedType(const std::vector<const RuntimeType*>& types) const;
130
132 virtual bool isRefCountedBase() const { return false; }
133
136 virtual std::string detailString() const { return std::string(); }
137
141
142};
143
145
146#undef ML_BASE_VERSION
147
149
177template<typename ToTypePtr>
178inline ToTypePtr mlbase_cast(ML_UTILS_NAMESPACE::Base* from) {
179 if (from) {
180 if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
181 return static_cast<ToTypePtr>(from);
182 } else {
183 return NULL;
184 }
185 } else {
186 return NULL;
187 }
188}
189
191template<typename ToTypePtr>
192inline ToTypePtr mlbase_cast(const ML_UTILS_NAMESPACE::Base* from) {
193 if (from) {
194 if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
195 return static_cast<ToTypePtr>(from);
196 } else {
197 return NULL;
198 }
199 } else {
200 return NULL;
201 }
202}
203
204#endif // __mlBase_H
205
206
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:59
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
Return a string describing this object.
Definition mlBase.h:136
virtual bool implementsPersistence(PersistenceInterface) const
Override this method to declare which persistence interfaces are implemented by your derived class.
Definition mlBase.h:81
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:91
virtual ~Base()
Destructor.
virtual void readFrom(AbstractPersistenceInputStream *, int)
Read the objects state from the data stream object.
Definition mlBase.h:114
virtual bool isRefCountedBase() const
Returns if the instance is derived from RefCountedBase.
Definition mlBase.h:132
virtual void writeTo(AbstractPersistenceOutputStream *) const
Write the objects state to the data stream object.
Definition mlBase.h:103
bool isOfAllowedType(const std::vector< const RuntimeType * > &types) const
Check if 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:73
@ PersistenceByString
Definition mlBase.h:74
@ PersistenceByTreeNode
Definition mlBase.h:75
virtual void readStateFromTree(TreeNode *)
Reads the object state from the children of the given parent node.
Definition mlBase.h:94
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:154
ToTypePtr mlbase_cast(ml::Base *from)
Template function to allow type-safe casting of a base object to a derived object.
Definition mlBase.h:178
#define ML_PERSISTENCE_VERSION(v)
Nicer name for ML_SET_ADDSTATE_VERSION.
Definition mlBase.h:34
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
#define ML_UTILS_EXPORT
Defines platform dependent DLL export macro for mlUtils.
Definition mlUtilities.h:20