13 #ifndef ML_TREE_NODE_H
14 #define ML_TREE_NODE_H
35 #if ML_DEPRECATED_SINCE(3,5,0)
84 #if ML_DEPRECATED_SINCE(3,5,0)
145 std::string _message;
149 static const char* _stdErrorMsg[];
158 #define TREE_NODE_CHECK_THROW(x) { if (!(x)) throw TreeNodeException(TNE_UserDefined, #x); }
178 #define VOID_IMPLEMENTATION(which) { throw TreeNodeException(TNE_VoidImplementation, which); }
184 #define VOID_IMPLEMENTATION_RET(which, R) { if (MLAlwaysTrue){ throw TreeNodeException(TNE_VoidImplementation, which); } return R; }
187 #define ADD_LONG_CHILD { addChild(static_cast<long>(val), name); }
190 #define ADD_ULONG_CHILD { addChild(static_cast<unsigned long>(val), name); }
193 #define ADD_LDOUBLE_CHILD { addChild(static_cast<long double>(val), name); }
197 #define READ_LONG_CHILD(DST_TYPE) { long lval=0; readChild(lval, name); val = static_cast<DST_TYPE>(lval); }
201 #define READ_ULONG_CHILD(DST_TYPE) { unsigned long lval=0; readChild(lval, name); val = static_cast<DST_TYPE>(lval); }
205 #define READ_LDOUBLE_CHILD(DST_TYPE){ long double ldval=0; readChild(ldval, name); val = static_cast<DST_TYPE>(ldval); }
209 #define READ_LONG_CHILD_FOR_BOOL { long lval=0; readChild(lval, name); val = (lval!=0); }
256 #if !ML_DEPRECATED_SINCE(3,5,0)
272 [[deprecated]]
virtual void readFromString (
const char* )
VOID_IMPLEMENTATION(
"readFromString");
273 #if !ML_DEPRECATED_SINCE(3,5,0)
338 virtual void addChild(
const std::string& ,
const char* )
VOID_IMPLEMENTATION(
"addChild(const std::string&)");
369 virtual void addChild (
const void*
const ,
size_t ,
const char* )
VOID_IMPLEMENTATION(
"addChild(void*)");
410 virtual
void readChild (
char& val, const
char* name =
nullptr)
READ_LONG_CHILD(
char);
413 virtual
void readChild (
unsigned char& val, const
char* name =
nullptr)
READ_ULONG_CHILD(
unsigned char);
416 virtual
void readChild (
short& val, const
char* name =
nullptr)
READ_LONG_CHILD(
short);
419 virtual
void readChild (
unsigned short& val, const
char* name =
nullptr)
READ_ULONG_CHILD(
unsigned short);
422 virtual
void readChild (
int& val, const
char* name =
nullptr)
READ_LONG_CHILD(
int);
425 virtual
void readChild (
unsigned int& val, const
char* name =
nullptr)
READ_ULONG_CHILD(
unsigned int);
428 virtual
void readChild (
long& , const
char* =
nullptr)
VOID_IMPLEMENTATION("readChild(
long&)");
431 virtual
void readChild (
unsigned long& , const
char* =
nullptr)
VOID_IMPLEMENTATION("readChild(
unsigned long&)");
440 virtual
void readChild (
float& val, const
char* name =
nullptr)
READ_LDOUBLE_CHILD(
float);
443 virtual
void readChild (
double& val, const
char* name =
nullptr)
READ_LDOUBLE_CHILD(
double);
446 virtual
void readChild (
long double& , const
char* =
nullptr)
VOID_IMPLEMENTATION("readChild(
long double&)");
477 virtual
void readChild (
void*& ,
unsigned long& , const
char* =
nullptr)
VOID_IMPLEMENTATION("readChild(
char*&)");
493 virtual
void readChild(std::
string& , const
char* =
nullptr)
VOID_IMPLEMENTATION("readChild(std::
string&)");
495 #if !ML_DEPRECATED_SINCE(3,5,0)
501 [[deprecated]]
virtual void addChild (
const char*
const ,
const char* )
VOID_IMPLEMENTATION(
"addChild(const char* const)");
507 [[deprecated]]
virtual void readChild (
char*& ,
const char* =
nullptr)
VOID_IMPLEMENTATION("readChild(
char*&)");
511 [[deprecated]] virtual
void deleteString (
char* ) const
VOID_IMPLEMENTATION("deleteString(
char*)");
512 #if !ML_DEPRECATED_SINCE(3, 5, 0)
530 virtual TreeNode* readContainerChild (
const char* name =
nullptr)
533 readChild(node, name);
544 virtual Base* readBaseChild (
const char* name =
nullptr)
546 Base* objP =
nullptr;
547 readChild(objP, name);
566 virtual const char* getLastReadChildName()
const {
VOID_IMPLEMENTATION_RET(
"getLastReadChildName()",
nullptr); }
569 bool isRootNode()
const {
return _isRoot; }
595 TreeNode(ConstructionMode ) :
613 std::vector<TreeNode*> &_getChildTreeNodes();
624 void _appendNewChild(TreeNode& newNode) { _childTreeNodes.push_back(&newNode); }
646 std::vector<TreeNode*> _childTreeNodes;
659 #undef VOID_IMPLEMENTATION
660 #undef ADD_ULONG_CHILD
661 #undef ADD_LONG_CHILD
662 #undef ADD_LDOUBLE_CHILD
663 #undef READ_ULONG_CHILD
664 #undef READ_LONG_CHILD
665 #undef READ_LDOUBLE_CHILD
666 #undef READ_LONG_CHILD_FOR_BOOL
680 #define ML_READCHILD_OPTIONAL(obj, tagName, defaultVal) \
681 if (parent->hasChild(tagName)) { \
682 parent->readChild(obj, tagName); \
689 #define ML_ADDSTATE_VERSION(ThisClass) parent->setVersion("#ThisClass#", ThisClass::getAddStateVersion());
693 #define ML_ADDSTATE_SUPER(SuperClass) { \
694 TreeNode* superClassNode = parent->addChild("_" #SuperClass); \
695 SuperClass::addStateToTree(superClassNode); \
700 #define ML_READSTATE_SUPER(SuperClass) { \
701 TreeNode* superClassNode = parent->readContainerChild("_" #SuperClass); \
702 SuperClass::readStateFromTree(superClassNode); \
713 #define ML_TREE_NODE_SUPPORT_VIA_PERSISTENT_STATE \
714 virtual void addStateToTree(TreeNode* parent) const \
716 auto state = persistentState(); \
717 if (state.empty()){ state = "Could not read object state."; } \
718 parent->addChild(state, "State"); \
721 virtual void readStateFromTree(TreeNode* parent) \
724 parent->readChild(state, "State"); \
725 setPersistentState(state); \
Class representing general ML objects that support import/export via strings (setPersistentState() an...
SubImageBoxd - SubImageBox with coordinates of float data type.
The class TreeNodeException is the base class for all exceptions thrown by the class TreeNode and all...
virtual const char * getMessage() const
Returns the error string.
virtual ~TreeNodeException()
Destructor.
int getCode() const
Returns the error code.
int _errorCode
The error code of the exception.
TreeNodeException(int errorCode=0, const char *msg=nullptr)
Creates a new exception object with code errorCode and an optional error message.
The class TreeNode is the abstract base class for the import/export of ML objects.
virtual void addChild(char val, const char *name) ADD_LONG_CHILD
Factory method adding a child encapsulating a variable of type char.
@ CM_readerRoot
Construct as root node for reading.
@ CM_writerRoot
Construct as root node for writing.
virtual ~TreeNode()
Destructor deleting all children of this node.
virtual void addChild(int val, const char *name) ADD_LONG_CHILD
Factory method adding a child encapsulating a variable of type int.
virtual void addChild(MLint64, const char *) VOID_IMPLEMENTATION("addChild(MLint64)")
Factory method adding a child encapsulating a variable of type MLint64.
virtual void addChild(unsigned short val, const char *name) ADD_ULONG_CHILD
Factory method adding a child encapsulating a variable of type unsigned short.
virtual void addChild(double val, const char *name) ADD_LDOUBLE_CHILD
Factory method adding a child encapsulating a variable of type double.
virtual void addChild(short val, const char *name) ADD_LONG_CHILD
Factory method adding a child encapsulating a variable of type short.
virtual void writeToString(std::string &) VOID_IMPLEMENTATION("writeToString")
Generates a string representation of the subtree represented by this node to a file.
virtual void writeToFile(const char *) VOID_IMPLEMENTATION("writeToFile")
Writes the subtree represented by this node to a file.
virtual void addChild(unsigned int val, const char *name) ADD_ULONG_CHILD
Factory method adding a child encapsulating a variable of type unsigned int.
virtual void addChild(unsigned char val, const char *name) ADD_ULONG_CHILD
Factory method adding a child encapsulating a variable of type unsigned char.
virtual void addChild(long, const char *) VOID_IMPLEMENTATION("addChild(long)")
Factory method adding a child encapsulating a variable of type long.
virtual void addChild(bool val, const char *name) ADD_ULONG_CHILD
Factory method adding a child encapsulating a variable of type bool.
virtual void addChild(unsigned long, const char *) VOID_IMPLEMENTATION("addChild(unsigned long)")
Factory method adding a child encapsulating a variable of type long.
virtual void addChild(MLuint64, const char *) VOID_IMPLEMENTATION("addChild(MLuint64)")
Factory method adding a child encapsulating a variable of type MLuint64.
virtual void readFromFile(const char *) VOID_IMPLEMENTATION("readFromFile")
Reads the subtree represented by this node from a file.
virtual void addChild(float val, const char *name) ADD_LDOUBLE_CHILD
Factory method adding a child encapsulating a variable of type float.
virtual void addChild(long double, const char *) VOID_IMPLEMENTATION("addChild(long double)")
Factory method adding a child encapsulating a variable of type long double.
virtual void readFromString(const std::string &) VOID_IMPLEMENTATION("readFromString")
Reads the subtree represented by this node from a string.
#define MLEXPORT
To export symbols from a dll/shared object, we need to mark them with the MLEXPORT symbol.
#define ML_ABSTRACT_ROOT_CLASS_HEADER(className)
#define ML_ROOT_CLASS_HEADER(className)
#define ADD_LONG_CHILD
For each signed integer type, addChild(long) is called by default.
#define READ_LDOUBLE_CHILD(DST_TYPE)
For each floating point type, readChild(LDouble) is called by default and the results is simply caste...
#define VOID_IMPLEMENTATION(which)
Standard body for a method in this interface class.
#define VOID_IMPLEMENTATION_RET(which, R)
Standard body for a method in this interface class.
#define READ_LONG_CHILD_FOR_BOOL
For each signed integer type, readChild(Long) is called by default and the results is simply casted t...
#define ADD_LDOUBLE_CHILD
For each floating point type, addChild(LDouble) is called by default.
#define READ_LONG_CHILD(DST_TYPE)
For each signed integer type, readChild(Long) is called by default and the results is simply casted t...
#define READ_ULONG_CHILD(DST_TYPE)
For each unsigned integer type, readChild(ULong) is called by default and the results is simply caste...
#define ADD_ULONG_CHILD
For each unsigned integer type, addChild(ulong) is called by default.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
INT64 MLint64
Include 64 bit integer support for Windows or Unix.
@ TNE_UnsupportedClassVersion
@ TNE_ReadingSubImageBoxd