MeVisLab Toolbox Reference
mlBaseItem.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_ITEM_H
14#define ML_BASE_ITEM_H
15
16
18
19// Defines the following class:
20// - BaseItem: A general base class (derived from Base) for list items that have
21// an id and a name. Should be used for list objects that are editable via a
22// container and/or editor module.
23
24// ML-includes
25#include "mlBaseInit.h"
26#include "mlModuleIncludes.h"
27
29
30class TreeNode;
31
32// ------------------------------------------------------------------
33// Base object class BaseItem
34// ------------------------------------------------------------------
35
38{
39public:
40
43
45 BaseItem () : Base(), _id(0), _name(nullptr) {}
46
48 BaseItem (MLssize_t id, const char *nameStr = nullptr) : Base(), _id(id), _name(nullptr) { setName(nameStr); }
49
51 BaseItem (const BaseItem &item) : Base(), _name(nullptr) { *this = item; }
52
54
56 void setId(MLssize_t id){ _id = id; }
57
59 MLssize_t getId() const { return _id; }
60
62 ~BaseItem () override { setName(nullptr); }
63
64
66 BaseItem &operator = (const BaseItem &item);
67
68
70 const char *name () const { return _name; }
71
73 void setName (const char *newName);
74
75
78
80 std::string persistentState() const override;
81
83 void setPersistentState(const std::string& state) override;
84
86 void addStateToTree(TreeNode* parent) const override;
87
89
94
96 void readStateFromTree(TreeNode* parent) override;
97
100
102 void readFrom(AbstractPersistenceInputStream* stream, int version) override;
103
105
107 BaseItem* deepCopy() const override { return new BaseItem(*this); };
108
109protected:
110
114 char *newString (const std::string &str) const;
115
117 void deleteString (char *str) const;
118
119
120private:
121
123 MLssize_t _id;
124
126 char *_name;
127
129
130};
131
132
134
135
136#endif // MLBASEITEM_H
Class for reading object data from a stream.
Class for writing object data to a stream.
General Base object class for list items that have an id and a name.
Definition mlBaseItem.h:38
std::string persistentState() const override
Return a string representation of the item object.
BaseItem(const BaseItem &item)
Copy constructor.
Definition mlBaseItem.h:51
void addStateToTree(TreeNode *parent) const override
Attaches the object state as children of the given parent node.
void writeTo(AbstractPersistenceOutputStream *stream) const override
write state to stream
void setPersistentState(const std::string &state) override
Initialize the item object from the string state.
BaseItem()
Default constructor.
Definition mlBaseItem.h:45
BaseItem(MLssize_t id, const char *nameStr=nullptr)
ID and name.
Definition mlBaseItem.h:48
void readFrom(AbstractPersistenceInputStream *stream, int version) override
read state from stream
~BaseItem() override
Destructor.
Definition mlBaseItem.h:62
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
void setId(MLssize_t id)
Sets the id of the item.
Definition mlBaseItem.h:56
BaseItem * deepCopy() const override
Create a deep copy of the BaseItem.
Definition mlBaseItem.h:107
ML_SET_ADDSTATE_VERSION(0)
Set addState version number.
MLssize_t getId() const
Sets the id of the item.
Definition mlBaseItem.h:59
void setName(const char *newName)
Set name, object stores a copy.
void deleteString(char *str) const
Dispose a string allocated with newString()
char * newString(const std::string &str) const
Convenience method to create a copy of the string str allocated on the heap.
const char * name() const
Get name.
Definition mlBaseItem.h:70
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:154
#define MLBASEEXPORT
defined Header file mlBaseInit.h
Definition mlBaseInit.h:22
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
SSIZE_T MLssize_t
The signed ML size type which is a signed 32 bit size_t on 32 bit platforms and 64 bit one on 64 bit ...
Definition mlTypeDefs.h:566