13 #ifndef ML_XMLTREE_NODE_H
14 #define ML_XMLTREE_NODE_H
22 #include "../mlParserSystem.h"
31 class XercesDOMParser;
70 static const char* _stdErrorMsg[];
110 #if !ML_DEPRECATED_SINCE(3,5,0)
114 [[deprecated]]
void writeToString (
char*& str)
override;
115 #if !ML_DEPRECATED_SINCE(3,5,0)
128 #if !ML_DEPRECATED_SINCE(3,5,0)
132 [[deprecated]]
void readFromString (
const char* str)
override;
133 #if !ML_DEPRECATED_SINCE(3,5,0)
155 void addChild (
unsigned long val,
const char* tagName)
override;
156 void addChild (
long val,
const char* tagName)
override;
159 void addChild (
long double val,
const char* tagName)
override;
169 #if !ML_DEPRECATED_SINCE(3,5,0)
172 [[deprecated]]
void addChild (
const char*
const text,
const char* tagName)
override;
173 #if !ML_DEPRECATED_SINCE(3,5,0)
177 void addChild(
const std::string& str,
const char* tagName)
override;
178 void addChild (
const void*
const ptr,
size_t noBytes,
const char* tagName)
override;
188 void addChild (
const Base*
const obj,
const char* tagName,
bool generic =
true)
override;
214 bool hasChild (
const char* tagName =
nullptr)
override;
217 void readChild (
unsigned long& val,
const char* tagName =
nullptr)
override;
218 void readChild (
long& val,
const char* tagName =
nullptr)
override;
221 void readChild (
long double& val,
const char* tagName =
nullptr)
override;
231 void readChild (
void*& ptr,
unsigned long& noBytes,
const char* tagName =
nullptr)
override;
235 #if !ML_DEPRECATED_SINCE(3,5,0)
239 [[deprecated]]
void readChild (
char*& val,
const char* tagName =
nullptr)
override;
240 #if !ML_DEPRECATED_SINCE(3,5,0)
244 void readChild(std::string& val,
const char* tagName =
nullptr)
override;
259 #if !ML_DEPRECATED_SINCE(3,5,0)
266 [[deprecated]]
void deleteString (
char* str)
const override;
267 #if !ML_DEPRECATED_SINCE(3,5,0)
277 void setVersion(
const char* className,
int version)
override;
336 void _initFromParser(XercesDOMParser& parser);
342 DOMNode* _lastNodeRead;
361 #if ML_DEPRECATED_SINCE(3, 5, 0)
363 #define ML_PERSISTENCE_SUPPORT_VIA_XML \
364 inline std::string persistentState() override const \
369 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_writerRoot); \
370 addStateToTree(ioRootNode.get()); \
371 ioRootNode->writeToString(str); \
373 catch (const TreeNodeException &e) \
375 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - persistentState()", \
376 std::string("Exception ") + e.getMessage() + " occurred.", \
377 "Returning empty string."); \
382 inline void setPersistentState(const std::string &state) override \
388 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_readerRoot); \
389 this->readStateFromTree(ioRootNode.get()); \
390 ioRootNode->readFromString(state); \
392 catch (const TreeNodeException &e) \
394 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - setPersistentState()", \
395 std::string("Exception ") + e.getMessage() + " occurred.", \
396 "Continuing. Warning: Object state may be undefined!"); \
399 inline [[nodiscard]] [[deprecated]] char * getPersistentState() override const \
401 char *cstr = nullptr; \
404 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_writerRoot); \
405 addStateToTree(ioRootNode.get()); \
406 ioRootNode->writeToString(cstr); \
408 catch (const TreeNodeException &e) \
410 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - getPersistentState()", \
411 std::string("Exception ") + e.getMessage() + " occurred.", \
412 "Returning nullptr."); \
417 inline [[deprecated]] void setPersistentState(const char *state) override \
419 if (!state || std::string(state).empty()) \
423 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_readerRoot); \
424 this->readStateFromTree(ioRootNode.get()); \
425 ioRootNode->readFromString(state); \
427 catch (const TreeNodeException &e) \
429 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - setPersistentState()", \
430 std::string("Exception ") + e.getMessage() + " occurred.", \
431 "Continuing. Warning: Object state may be undefined!"); \
434 inline [[deprecated]] virtual void clearPersistentState(char *state) const \
436 if (!state || std::string(state).empty()) \
440 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_readerRoot); \
441 ioRootNode->deleteString(state); \
443 catch (const TreeNodeException &e) \
445 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - clearPersistentState()", \
446 std::string("Exception ") + e.getMessage() + " occurred.", \
447 "Continuing. Warning: Object state may be undefined!"); \
453 #define ML_PERSISTENCE_SUPPORT_VIA_XML \
454 inline std::string persistentState() override const \
459 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_writerRoot); \
460 addStateToTree(ioRootNode.get()); \
461 ioRootNode->writeToString(str); \
463 catch (const TreeNodeException &e) \
465 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - persistentState()", \
466 std::string("Exception ") + e.getMessage() + " occurred.", \
467 "Returning empty string."); \
472 inline void setPersistentState(const std::string &state) override \
478 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_readerRoot); \
479 this->readStateFromTree(ioRootNode.get()); \
480 ioRootNode->readFromString(state); \
482 catch (const TreeNodeException &e) \
484 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - setPersistentState()", \
485 std::string("Exception ") + e.getMessage() + " occurred.", \
486 "Continuing. Warning: Object state may be undefined!"); \
491 inline [[nodiscard]] [[deprecated]] char *getPersistentState() override const \
493 char *cstr = nullptr; \
496 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_writerRoot); \
497 addStateToTree(ioRootNode.get()); \
498 ioRootNode->writeToString(cstr); \
500 catch (const TreeNodeException &e) \
502 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - getPersistentState()", \
503 std::string("Exception ") + e.getMessage() + " occurred.", \
504 "Returning nullptr."); \
509 inline [[deprecated]] void setPersistentState(const char *state) override \
511 if (!state || std::string(state).empty()) \
515 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_readerRoot); \
516 this->readStateFromTree(ioRootNode.get()); \
517 ioRootNode->readFromString(state); \
519 catch (const TreeNodeException &e) \
521 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - setPersistentState()", \
522 std::string("Exception ") + e.getMessage() + " occurred.", \
523 "Continuing. Warning: Object state may be undefined!"); \
526 inline [[deprecated]] virtual void clearPersistentState(char *state) const \
528 if (!state || std::string(state).empty()) \
532 auto ioRootNode = std::make_unique<XMLTreeNode>(TreeNode::CM_readerRoot); \
533 ioRootNode->deleteString(state); \
535 catch (const TreeNodeException &e) \
537 ML_PRINT_ERROR("ML_PERSISTENCE_SUPPORT_VIA_XML - clearPersistentState()", \
538 std::string("Exception ") + e.getMessage() + " occurred.", \
539 "Continuing. Warning: Object state may be undefined!"); \
Defines library specific stuff, mostly for system independence.
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...
The class TreeNode is the abstract base class for the import/export of ML objects.
ConstructionMode
TreeNode construction modes:
The XMLTreeNodeException class extends the exceptions already provided by class TreeNodeException.
const char * getMessage() const override
Returns an error message containing error code and message (if present).
XMLTreeNodeException(int errorCode=0, const char *msg=nullptr)
Constructor.
The class XMLTreeNode implements the abstract class TreeNode to allow export and import of ML objects...
static char * normalizeFileName(const char *fileName)
normalizes the given filename so that it can be used by Xerces to read or write a file with the given...
void readFromString(const std::string &str) override
Reads the subtree represented by this node from a string.
void readChild(SubImageBox &val, const char *tagName=nullptr) override
void readChild(Matrix4 &val, const char *tagName=nullptr) override
static void terminateXMLSystem()
void setVersion(const char *className, int version) override
Set version for current node. className is currently not used.
void addChild(const Matrix4 &mat, const char *tagName) override
void readChild(Base *&val, const char *tagName=nullptr) override
The type of the object here is read from the XML file.
void addChild(const void *const ptr, size_t noBytes, const char *tagName) override
void readChild(Vector2 &val, const char *tagName=nullptr) override
void writeToString(std::string &str) override
Generates a string representation of the subtree represented by this node to a file.
static void initXMLSystem()
void addChild(const std::string &str, const char *tagName) override
void addChild(const SubImageBox &box, const char *tagName) override
void readChild(long double &val, const char *tagName=nullptr) override
XMLTreeNode(TreeNode::ConstructionMode mode=TreeNode::CM_writerRoot)
Constructor.
void addChild(const Vector3 &vec, const char *tagName) override
void addChild(const Vector6 &vec, const char *tagName) override
void readChild(ImageVector &val, const char *tagName=nullptr) override
void addChild(unsigned long val, const char *tagName) override
Factory method adding a child encapsulating a variable of type long.
void readChild(SubImageBoxd &val, const char *tagName=nullptr) override
void readChild(unsigned long &val, const char *tagName=nullptr) override
void readChild(Vector6 &val, const char *tagName=nullptr) override
void addChild(const Vector4 &vec, const char *tagName) override
static int _numActiveRootInstances
void addChild(const SubImageBoxd &box, const char *tagName) override
void readChild(Base &val, const char *tagName=nullptr) override
Opposed to the readChild(Base*& ...) method, you have to create the object yourself BEFORE calling th...
TreeNode * addChild(const char *tagName) override
Adds a group or container node with the specified tag name.
DOMElement * _parentDOMNode
pointer to the DOM node actually wrapped by this class
void readFromFile(const char *fileName) override
Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError.
void readChild(Vector3 &val, const char *tagName=nullptr) override
void addChild(const Vector2 &vec, const char *tagName) override
XMLTreeNode * _addTreeNodeChild(DOMElement *child)
Adds a new node containing the given child.
const char * getLastReadChildName() const override
Returns the name of the child most recently read.
void readChild(MLint64 &val, const char *tagName=nullptr) override
void addChild(const ImageVector &vec, const char *tagName) override
void readChild(long &val, const char *tagName=nullptr) override
XMLTreeNode(DOMElement *parent)
void readChild(Matrix3 &val, const char *tagName=nullptr) override
static bool _xercesInitialized
Indicates whether the Xerces XML SubSystem is already initialized.
DOMElement * _findElemByTagName(const char *tagName, DOMNode *prevNode=nullptr)
Starting from the element after node (or the first element, if node is NULL), returns the first DOM e...
~XMLTreeNode() override
Destructor.
void readChild(Vector4 &val, const char *tagName=nullptr) override
void addChild(long double val, const char *tagName) override
Factory method adding a child encapsulating a variable of type long double.
void addChild(MLuint64 val, const char *tagName) override
Factory method adding a child encapsulating a variable of type MLuint64.
void addChild(long val, const char *tagName) override
Factory method adding a child encapsulating a variable of type long.
void addChild(const Base *const obj, const char *tagName, bool generic=true) override
Adds an child representing an object whose class is derived from base and thus implements the addStat...
void writeToFile(const char *fileName) override
Writes the complete tree to a file. Throws TNE_WritingFile.
void readChild(MLuint64 &val, const char *tagName=nullptr) override
void readChild(TreeNode *&val, const char *tagName=nullptr) override
Returns the group or container node with the specified tag name.
bool hasChild(const char *tagName=nullptr) override
returns true when a child of the given tagName exists.
void readChild(void *&ptr, unsigned long &noBytes, const char *tagName=nullptr) override
void readChild(std::string &val, const char *tagName=nullptr) override
void addChild(const Matrix3 &mat, const char *tagName) override
void addChild(MLint64 val, const char *tagName) override
Factory method adding a child encapsulating a variable of type MLint64.
int getVersion(const char *) override
Get version of current node. className is currently not used.
static char * _getTextNodeString(DOMElement *parentNode)
Returns the string contained by the TextNode child of parentNode.
#define PARSER_EXPORT
Definiert systemspezifische Macros, die f"ur diese DLL gelten sollen.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
INT64 MLint64
Include 64 bit integer support for Windows or Unix.
Implement the AbstractPersistence(Input/Output)Stream classes with XML backend.
@ TNE_XML_LAST_MESSAGE_IDX
Only for number calculations; do not use.
@ TNE_XML_ReadingRawDataSize