MeVisLab Toolbox Reference
|
The class XMLTreeNode implements the abstract class TreeNode to allow export and import of ML objects to and from XML files and strings. More...
#include <mlXMLTreeNode.h>
Public Member Functions | |
XMLTreeNode (TreeNode::ConstructionMode mode=TreeNode::CM_writerRoot) | |
Constructor. | |
~XMLTreeNode () override | |
Destructor. | |
const char * | getLastReadChildName () const override |
Returns the name of the child most recently read. | |
Export methods: | |
void | writeToFile (const char *fileName) override |
Writes the complete tree to a file. Throws TNE_WritingFile. | |
void | writeToString (std::string &str) override |
Generates a string representation of the subtree represented by this node to a file. | |
Import methods: | |
void | readFromFile (const char *fileName) override |
Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError. | |
void | readFromString (const std::string &str) override |
Reads the subtree represented by this node from a string. | |
Tree building methods: | |
The addChild methods add the variable or object val as a child node with tag name tagName. They all throw
| |
void | addChild (unsigned long val, const char *tagName) override |
Factory method adding a child encapsulating a variable of type long. | |
void | addChild (long val, const char *tagName) override |
Factory method adding a child encapsulating a variable of type long. | |
void | addChild (MLuint64 val, const char *tagName) override |
Factory method adding a child encapsulating a variable of type MLuint64. | |
void | addChild (MLint64 val, const char *tagName) override |
Factory method adding a child encapsulating a variable of type MLint64. | |
void | addChild (long double val, const char *tagName) override |
Factory method adding a child encapsulating a variable of type long double. | |
void | addChild (const Vector2 &vec, const char *tagName) override |
void | addChild (const Vector3 &vec, const char *tagName) override |
void | addChild (const Vector4 &vec, const char *tagName) override |
void | addChild (const Vector6 &vec, const char *tagName) override |
void | addChild (const ImageVector &vec, const char *tagName) override |
void | addChild (const Matrix3 &mat, const char *tagName) override |
void | addChild (const Matrix4 &mat, const char *tagName) override |
void | addChild (const SubImageBox &box, const char *tagName) override |
void | addChild (const SubImageBoxd &box, const char *tagName) override |
void | addChild (const std::string &str, const char *tagName) override |
void | addChild (const void *const ptr, size_t noBytes, const char *tagName) override |
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 addStateToTree() / readStateFromTree() methods. | |
TreeNode * | addChild (const char *tagName) override |
Adds a group or container node with the specified tag name. | |
Tree reading methods: | |
The readChild methods read the variable or object val from the child node identified by tagName. They all throw
| |
bool | hasChild (const char *tagName=nullptr) override |
returns true when a child of the given tagName exists. | |
void | readChild (unsigned long &val, const char *tagName=nullptr) override |
void | readChild (long &val, const char *tagName=nullptr) override |
void | readChild (MLuint64 &val, const char *tagName=nullptr) override |
void | readChild (MLint64 &val, const char *tagName=nullptr) override |
void | readChild (long double &val, const char *tagName=nullptr) override |
void | readChild (Vector2 &val, const char *tagName=nullptr) override |
void | readChild (Vector3 &val, const char *tagName=nullptr) override |
void | readChild (Vector4 &val, const char *tagName=nullptr) override |
void | readChild (Vector6 &val, const char *tagName=nullptr) override |
void | readChild (ImageVector &val, const char *tagName=nullptr) override |
void | readChild (Matrix3 &val, const char *tagName=nullptr) override |
void | readChild (Matrix4 &val, const char *tagName=nullptr) override |
void | readChild (SubImageBox &val, const char *tagName=nullptr) override |
void | readChild (SubImageBoxd &val, const char *tagName=nullptr) override |
void | readChild (void *&ptr, unsigned long &noBytes, const char *tagName=nullptr) override |
void | readChild (std::string &val, const char *tagName=nullptr) override |
The string returned is allocated on the heap. | |
void | readChild (Base *&val, const char *tagName=nullptr) override |
The type of the object here is read from the XML file. | |
void | readChild (Base &val, const char *tagName=nullptr) override |
Opposed to the readChild(Base*& ...) method, you have to create the object yourself BEFORE calling this method. | |
void | readChild (TreeNode *&val, const char *tagName=nullptr) override |
Returns the group or container node with the specified tag name. | |
Version support | |
void | setVersion (const char *className, int version) override |
Set version for current node. className is currently not used. | |
int | getVersion (const char *) override |
Get version of current node. className is currently not used. | |
Public Member Functions inherited from ml::TreeNode | |
virtual | ~TreeNode () |
Destructor deleting all children of this node. | |
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 char val, const char *name) ADD_ULONG_CHILD |
Factory method adding a child encapsulating a variable of type unsigned char. | |
virtual void | addChild (char val, const char *name) ADD_LONG_CHILD |
Factory method adding a child encapsulating a variable of type char. | |
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 (short val, const char *name) ADD_LONG_CHILD |
Factory method adding a child encapsulating a variable of type short. | |
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 (int val, const char *name) ADD_LONG_CHILD |
Factory method adding a child encapsulating a variable of type int. | |
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 (double val, const char *name) ADD_LDOUBLE_CHILD |
Factory method adding a child encapsulating a variable of type double. | |
Static Public Member Functions | |
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 name: | |
XML system handling | |
static void | initXMLSystem () |
static void | terminateXMLSystem () |
Xerces-specific interface (protected): | |
DOMElement * | _parentDOMNode |
pointer to the DOM node actually wrapped by this class | |
static int | _numActiveRootInstances |
static bool | _xercesInitialized |
Indicates whether the Xerces XML SubSystem is already initialized. | |
XMLTreeNode (DOMElement *parent) | |
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 element with the name tagName (NULL matches anything) or NULL. | |
XMLTreeNode * | _addTreeNodeChild (DOMElement *child) |
Adds a new node containing the given child. | |
static char * | _getTextNodeString (DOMElement *parentNode) |
Returns the string contained by the TextNode child of parentNode. | |
Additional Inherited Members | |
Public Types inherited from ml::TreeNode | |
enum | ConstructionMode { CM_writerRoot , CM_readerRoot , CM_COUNT } |
TreeNode construction modes: More... | |
The class XMLTreeNode implements the abstract class TreeNode to allow export and import of ML objects to and from XML files and strings.
class XML TreeNode
Definition at line 82 of file mlXMLTreeNode.h.
ml::XMLTreeNode::XMLTreeNode | ( | TreeNode::ConstructionMode | mode = TreeNode::CM_writerRoot | ) |
Constructor.
Initializes the parser system and creates a root node for reading or writing. Once a tree has been created (either building it yourself using the addChild() factory methods, or reading it from a file or string using readFromFile() or readFromString()), there is no longer a difference between both kinds of nodes, so you can read from a node created as a writer root and the other way around. Just don't call readFromFile or readFromString from a non-empty root node (unless you know exactly what you're doing!). Simply delete the root node and create a new one for reading in those cases. Throws TNE_XML_SystemInit if the parser system initialization failed.
mode | Use TreeNode::CM_writerRoot if you want to create a root node for writing, and TreeNode::CM_readerRoot for reading. |
|
override |
Destructor.
Terminates the parser system and DELETES THE COMPLETE TREE.
|
protected |
protected constructor:
|
protected |
Adds a new node containing the given child.
|
protected |
Starting from the element after node (or the first element, if node is NULL), returns the first DOM element with the name tagName (NULL matches anything) or NULL.
|
staticprotected |
Returns the string contained by the TextNode child of parentNode.
|
override |
Adds an child representing an object whose class is derived from base and thus implements the addStateToTree() / readStateFromTree() methods.
generic | When set to true (default), the actual object type is stored with the object to allow later creation of polymorph objects. When set to false the type is not stored, so that the user has to know the exact type when reading the object again. |
Adds a group or container node with the specified tag name.
This way you can group a bunch of smaller objects by adding them as child nodes to the node returned.
|
override |
|
override |
|
override |
|
override |
Factory method adding a child encapsulating a variable of type long double.
Reimplemented from ml::TreeNode.
Factory method adding a child encapsulating a variable of type long.
Reimplemented from ml::TreeNode.
Factory method adding a child encapsulating a variable of type MLint64.
Reimplemented from ml::TreeNode.
Factory method adding a child encapsulating a variable of type MLuint64.
Reimplemented from ml::TreeNode.
Factory method adding a child encapsulating a variable of type long.
Reimplemented from ml::TreeNode.
Returns the name of the child most recently read.
Get version of current node. className
is currently not used.
returns true when a child of the given tagName exists.
If NULL is given as tagName, true is returned if a child with an arbitrary name was found behind the current reading position. This reading position remains unchanged by the method; however, getLastReadChildName() will afterwards return the name of that child.
normalizes the given filename so that it can be used by Xerces to read or write a file with the given name:
Opposed to the readChild(Base*& ...) method, you have to create the object yourself BEFORE calling this method.
This is probably faster than using the runtime system, so whenever you know the actual type of the object in advance, this method is recommended.
The type of the object here is read from the XML file.
This is only possible, if it had been added with generic = true during the construction (see addChild). The object is created on the heap using the ML runtime system. The user is responsible for its disposal.
|
override |
The string returned is allocated on the heap.
Make sure to later dispose it using deleteString().
|
override |
|
override |
Returns the group or container node with the specified tag name.
|
override |
Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError.
Reimplemented from ml::TreeNode.
Reads the subtree represented by this node from a string.
This method can be used to quickly implement setPersistentString() for a class with TreeNode support. It might not make sense in all cases, for example when the derived class performs a binary import/export of the data.
Reimplemented from ml::TreeNode.
Set version for current node. className
is currently not used.
Writes the complete tree to a file. Throws TNE_WritingFile.
Reimplemented from ml::TreeNode.
|
overridevirtual |
Generates a string representation of the subtree represented by this node to a file.
This method can be used to quickly implement getPersistentString() for a class with TreeNode support. It might not make sense in all cases, for example when the derived class performs a binary import/export of the data.
Reimplemented from ml::TreeNode.
|
staticprotected |
Definition at line 291 of file mlXMLTreeNode.h.
|
protected |
pointer to the DOM node actually wrapped by this class
Definition at line 287 of file mlXMLTreeNode.h.
|
staticprotected |
Indicates whether the Xerces XML SubSystem is already initialized.
Definition at line 294 of file mlXMLTreeNode.h.