129 std::string _message;
133 static const char* _stdErrorMsg[];
142#define TREE_NODE_CHECK_THROW(x) { if (!(x)) throw TreeNodeException(TNE_UserDefined, #x); }
162#define VOID_IMPLEMENTATION(which) { throw TreeNodeException(TNE_VoidImplementation, which); }
168#define VOID_IMPLEMENTATION_RET(which, R) { if (MLAlwaysTrue){ throw TreeNodeException(TNE_VoidImplementation, which); } return R; }
171#define ADD_LONG_CHILD { addChild(static_cast<long>(val), name); }
174#define ADD_ULONG_CHILD { addChild(static_cast<unsigned long>(val), name); }
177#define ADD_LDOUBLE_CHILD { addChild(static_cast<long double>(val), name); }
181#define READ_LONG_CHILD(DST_TYPE) { long lval=0; readChild(lval, name); val = static_cast<DST_TYPE>(lval); }
185#define READ_ULONG_CHILD(DST_TYPE) { unsigned long lval=0; readChild(lval, name); val = static_cast<DST_TYPE>(lval); }
189#define READ_LDOUBLE_CHILD(DST_TYPE){ long double ldval=0; readChild(ldval, name); val = static_cast<DST_TYPE>(ldval); }
193#define READ_LONG_CHILD_FOR_BOOL { long lval=0; readChild(lval, name); val = (lval!=0); }
374 virtual
void readChild (
char& val, const
char* name =
nullptr)
READ_LONG_CHILD(
char);
377 virtual
void readChild (
unsigned char& val, const
char* name =
nullptr)
READ_ULONG_CHILD(
unsigned char);
380 virtual
void readChild (
short& val, const
char* name =
nullptr)
READ_LONG_CHILD(
short);
383 virtual
void readChild (
unsigned short& val, const
char* name =
nullptr)
READ_ULONG_CHILD(
unsigned short);
386 virtual
void readChild (
int& val, const
char* name =
nullptr)
READ_LONG_CHILD(
int);
389 virtual
void readChild (
unsigned int& val, const
char* name =
nullptr)
READ_ULONG_CHILD(
unsigned int);
392 virtual
void readChild (
long& , const
char* =
nullptr)
VOID_IMPLEMENTATION(
"readChild(long&)");
395 virtual
void readChild (
unsigned long& , const
char* =
nullptr)
VOID_IMPLEMENTATION(
"readChild(unsigned long&)");
404 virtual
void readChild (
float& val, const
char* name =
nullptr)
READ_LDOUBLE_CHILD(
float);
407 virtual
void readChild (
double& val, const
char* name =
nullptr)
READ_LDOUBLE_CHILD(
double);
410 virtual
void readChild (
long double& , const
char* =
nullptr)
VOID_IMPLEMENTATION(
"readChild(long double&)");
442 virtual
void readChild (
void*& ,
unsigned long& , const
char* =
nullptr)
VOID_IMPLEMENTATION(
"readChild(char*&)");
458 virtual
void readChild(
std::
string& , const
char* =
nullptr)
VOID_IMPLEMENTATION(
"readChild(std::string&)");
462 template <typename
T>
bool readOptionalChild(
T& value, const
char* name)
464 if (hasChild(name)) {
465 readChild(value, name);
473 template <
typename T>
T getOptionalChildValue(
const char* name,
const T& defaultValue)
476 if (readOptionalChild(value, name)) {
496 virtual TreeNode* readContainerChild (
const char* name =
nullptr)
498 TreeNode* node =
nullptr;
499 readChild(node, name);
512 virtual Base* readBaseChild (
const char* name =
nullptr)
514 Base* objP =
nullptr;
515 readChild(objP, name);
534 virtual const char* getLastReadChildName()
const {
VOID_IMPLEMENTATION_RET(
"getLastReadChildName()",
nullptr); }
537 bool isRootNode()
const {
return _isRoot; }
549 virtual void deleteMemory(
void* ){};
566 TreeNode(ConstructionMode ) :
584 std::vector<TreeNode*> &_getChildTreeNodes();
595 void _appendNewChild(TreeNode& newNode) { _childTreeNodes.push_back(&newNode); }
617 std::vector<TreeNode*> _childTreeNodes;
630#undef VOID_IMPLEMENTATION
631#undef ADD_ULONG_CHILD
633#undef ADD_LDOUBLE_CHILD
634#undef READ_ULONG_CHILD
635#undef READ_LONG_CHILD
636#undef READ_LDOUBLE_CHILD
637#undef READ_LONG_CHILD_FOR_BOOL
651#define ML_READCHILD_OPTIONAL(obj, tagName, defaultVal) \
652if (parent->hasChild(tagName)) { \
653 parent->readChild(obj, tagName); \
660#define ML_ADDSTATE_VERSION(ThisClass) parent->setVersion("#ThisClass#", ThisClass::getAddStateVersion());
664#define ML_ADDSTATE_SUPER(SuperClass) { \
665TreeNode* superClassNode = parent->addChild("_" #SuperClass); \
666SuperClass::addStateToTree(superClassNode); \
671#define ML_READSTATE_SUPER(SuperClass) { \
672TreeNode* superClassNode = parent->readContainerChild("_" #SuperClass); \
673SuperClass::readStateFromTree(superClassNode); \
684#define ML_TREE_NODE_SUPPORT_VIA_PERSISTENT_STATE \
685virtual void addStateToTree(TreeNode* parent) const \
687auto state = persistentState(); \
688if (state.empty()){ state = "Could not read object state."; } \
689parent->addChild(state, "State"); \
692virtual void readStateFromTree(TreeNode* parent) \
695parent->readChild(state, "State"); \
696setPersistentState(state); \
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)
virtual const char * getMessage() const
Returns the error string.
virtual void addChild(char val, const char *name) ADD_LONG_CHILD
Factory method for adding a child encapsulating a variable of type char.
@ CM_COUNT
number of construction modes
@ 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 for adding a child encapsulating a variable of type int.
virtual void addChild(MLint64, const char *) VOID_IMPLEMENTATION("addChild(MLint64)")
Factory method for adding a child encapsulating a variable of type MLint64.
virtual void addChild(unsigned short val, const char *name) ADD_ULONG_CHILD
Factory method for adding a child encapsulating a variable of type unsigned short.
virtual void addChild(double val, const char *name) ADD_LDOUBLE_CHILD
Factory method for adding a child encapsulating a variable of type double.
virtual void addChild(short val, const char *name) ADD_LONG_CHILD
Factory method for 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 for adding a child encapsulating a variable of type unsigned int.
virtual void addChild(unsigned char val, const char *name) ADD_ULONG_CHILD
Factory method for adding a child encapsulating a variable of type unsigned char.
virtual void addChild(long, const char *) VOID_IMPLEMENTATION("addChild(long)")
Factory method for adding a child encapsulating a variable of type long.
virtual void addChild(bool val, const char *name) ADD_ULONG_CHILD
Factory method for adding a child encapsulating a variable of type bool.
virtual void addChild(unsigned long, const char *) VOID_IMPLEMENTATION("addChild(unsigned long)")
Factory method for adding a child encapsulating a variable of type long.
virtual void addChild(MLuint64, const char *) VOID_IMPLEMENTATION("addChild(MLuint64)")
Factory method for 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 for adding a child encapsulating a variable of type float.
virtual void addChild(long double, const char *) VOID_IMPLEMENTATION("addChild(long double)")
Factory method for 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
Code it as import symbol if compiled elsewhere.
#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)
#define VOID_IMPLEMENTATION(which)
Standard body for a method in this interface class.
#define VOID_IMPLEMENTATION_RET(which, R)
#define READ_LONG_CHILD_FOR_BOOL
#define ADD_LDOUBLE_CHILD
For each floating point type, addChild(LDouble) is called by default.
#define READ_LONG_CHILD(DST_TYPE)
#define READ_ULONG_CHILD(DST_TYPE)
#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
Tvec4< MLdouble > Vector4
A vector with four components of type double.
Tmat4< MLdouble > Matrix4
The standard 4x4 matrix of type double.
Tvec3< MLdouble > Vector3
A vector with three components of type double.
Tvec6< MLdouble > Vector6
A vector with six components of type double.
Tvec2< MLdouble > Vector2
A vector with two components of type double.
Tmat3< MLdouble > Matrix3
The standard 3x3 matrix of type double.
TSubImageBox< MLint > SubImageBox
Defines the standard SubImageBox type used in the ML. Its size varies with the size of the MLint type...
TImageVector< MLint > ImageVector
Defines the standard ImageVector type that is used by the ML for indexing and coordinates.