MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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:
42
45 : Base()
46 , _id(0)
47 , _name(nullptr)
48 {}
49
51 BaseItem(MLssize_t id, const char* nameStr = nullptr)
52 : Base()
53 , _id(id)
54 , _name(nullptr)
55 {
56 setName(nameStr);
57 }
58
61 : Base()
62 , _name(nullptr)
63 {
64 setId(item.getId());
65 setName(item.name());
66 }
67
69
72 {
73 _id = id;
74 }
75
78 {
79 return _id;
80 }
81
83 ~BaseItem() override
84 {
85 setName(nullptr);
86 }
87
88
91
92
94 const char* name() const
95 {
96 return _name;
97 }
98
100 void setName(const char* newName);
101
102
105
107 std::string persistentState() const override;
108
110 void setPersistentState(const std::string& state) override;
111
113 void addStateToTree(TreeNode* parent) const override;
114
116
121
123 void readStateFromTree(TreeNode* parent) override;
124
127
129 void readFrom(AbstractPersistenceInputStream* stream, int version) override;
130
132
134 BaseItem* deepCopy() const override
135 {
136 return new BaseItem(*this);
137 };
138
139protected:
143 char* newString(const std::string& str) const;
144
146 void deleteString(char* str) const;
147
148
149private:
151 MLssize_t _id;
152
154 char* _name;
155
157};
158
159
161
162
163#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:60
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:44
BaseItem(MLssize_t id, const char *nameStr=nullptr)
ID and name.
Definition mlBaseItem.h:51
void readFrom(AbstractPersistenceInputStream *stream, int version) override
read state from stream
~BaseItem() override
Destructor.
Definition mlBaseItem.h:83
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:71
BaseItem & operator=(const BaseItem &item)
Assignment operator.
BaseItem * deepCopy() const override
Create a deep copy of the BaseItem.
Definition mlBaseItem.h:134
ML_SET_ADDSTATE_VERSION(0)
Set addState version number.
MLssize_t getId() const
Sets the id of the item.
Definition mlBaseItem.h:77
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:94
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:63
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition mlTreeNode.h:160
#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 that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Definition mlTypeDefs.h:563