MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00004 00009 // 00010 // Defines the following class: 00011 // - BaseItem: A general base class (derived from Base) for list items that have 00012 // an id and a name. Should be used for list objects that are editable via a 00013 // container and/or editor module. 00014 //---------------------------------------------------------------------------------- 00015 00016 #ifndef __mlBaseItem_H 00017 #define __mlBaseItem_H 00018 00019 00020 // ML-includes 00021 #ifndef __mlBaseInit_H 00022 #include "mlBaseInit.h" 00023 #endif 00024 #ifndef __mlModuleIncludes_H 00025 #include "mlModuleIncludes.h" 00026 #endif 00027 00028 ML_START_NAMESPACE 00029 00030 class TreeNode; 00031 00032 // ------------------------------------------------------------------ 00033 // Base object class BaseItem 00034 // ------------------------------------------------------------------ 00035 00037 class MLBASEEXPORT BaseItem : public Base 00038 { 00039 public: 00040 00042 00043 00045 BaseItem () : Base(), _id(0), _name(NULL) {} 00046 00048 BaseItem (MLssize_t id, const char *nameStr = NULL) : Base(), _id(id), _name(NULL) { setName(nameStr); } 00049 00051 BaseItem (const BaseItem &item) : Base(), _name(NULL) { *this = item; } 00052 00054 00056 void setId(MLssize_t id){ _id = id; } 00057 00059 MLssize_t getId() const { return _id; } 00060 00062 virtual ~BaseItem () { setName(NULL); } 00063 00064 00066 virtual BaseItem &operator = (const BaseItem &item); 00067 00069 bool operator <(const BaseItem &) const { return false; } 00070 00072 bool operator ==(const BaseItem &) const { return false; } 00073 00074 00076 const char *name () const { return _name; } 00077 00079 void setName (const char *newName); 00080 00081 00083 00084 00087 virtual char *getPersistentState () const; 00088 00090 virtual void setPersistentState (const char *state); 00091 00094 virtual void clearPersistentState (char *state) const; 00095 00097 virtual void addStateToTree(TreeNode* parent) const; 00098 00100 00104 ML_SET_ADDSTATE_VERSION(0); 00105 00107 virtual void readStateFromTree(TreeNode* parent); 00108 00110 virtual void writeTo(AbstractPersistenceOutputStream* stream) const; 00111 00113 virtual void readFrom(AbstractPersistenceInputStream* stream, int version); 00114 00116 00118 virtual BaseItem* deepCopy() const { return new BaseItem(*this); }; 00119 00120 protected: 00121 00125 char *newString (const std::string &str) const; 00126 00128 void deleteString (char *str) const; 00129 00130 00131 private: 00132 00134 MLssize_t _id; 00135 00137 char *_name; 00138 00139 ML_CLASS_HEADER(BaseItem) 00140 00141 }; 00142 00143 00144 ML_END_NAMESPACE 00145 00146 00147 #endif // __mlBaseItem_H 00148