ML 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
36ML_UTILS_START_NAMESPACE
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
116 // Sets addStateToTree version number that can be accessed via getAddStateVersion()
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
144ML_UTILS_END_NAMESPACE
145
146#undef ML_BASE_VERSION
147
149
175template<typename ToTypePtr>
176inline ToTypePtr mlbase_cast(ML_UTILS_NAMESPACE::Base* from) {
177 if (from) {
178 if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
179 return static_cast<ToTypePtr>(from);
180 } else {
181 return NULL;
182 }
183 } else {
184 return NULL;
185 }
186}
187
189template<typename ToTypePtr>
190inline ToTypePtr mlbase_cast(const ML_UTILS_NAMESPACE::Base* from) {
191 if (from) {
192 if (from->getTypeId()->isDerivedFrom((static_cast<ToTypePtr>(0))->getClassTypeId())) {
193 return static_cast<ToTypePtr>(from);
194 } else {
195 return NULL;
196 }
197 } else {
198 return NULL;
199 }
200}
201
202#endif // __mlBase_H
203
204
virtual void setPersistentState(const std::string &state)
virtual std::string detailString() const
Definition mlBase.h:136
virtual bool implementsPersistence(PersistenceInterface) const
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 * deepCopy() const
Definition mlBase.h:124
virtual ~Base()
Destructor.
virtual void readFrom(AbstractPersistenceInputStream *, int)
Definition mlBase.h:114
virtual bool isRefCountedBase() const
Returns whether the instance is derived from RefCountedBase.
Definition mlBase.h:132
virtual void writeTo(AbstractPersistenceOutputStream *) const
Definition mlBase.h:103
bool isOfAllowedType(const std::vector< const RuntimeType * > &types) const
PersistenceInterface
This enum describes the different persistence interfaces available.
Definition mlBase.h:73
@ PersistenceByString
Definition mlBase.h:74
@ PersistenceByTreeNode
Definition mlBase.h:75
@ PersistenceByStream
Definition mlBase.h:76
virtual void readStateFromTree(TreeNode *)
Reads the object state from the children of the given parent node.
Definition mlBase.h:94
ToTypePtr mlbase_cast(ml::Base *from)
Template function to allow type-safe casting of a base object to a derived object.
Definition mlBase.h:176
#define ML_PERSISTENCE_VERSION(v)
Nicer name for ML_SET_ADDSTATE_VERSION.
Definition mlBase.h:34
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18