MeVisLabToolboxReference
|
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. | |
virtual | ~XMLTreeNode () |
Destructor. | |
virtual const char * | getLastReadChildName () const |
Returns the name of the child most recently read. | |
Export methods: | |
virtual void | writeToFile (const char *fileName) |
Writes the complete tree to a file. Throws TNE_WritingFile. | |
virtual void | writeToString (char *&str) |
Writes the subtree rooted by this node to a string. | |
Import methods: | |
virtual void | readFromFile (const char *fileName) |
Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError. | |
virtual void | readFromString (const char *str) |
Generates a tree parsing a string. Throws TNE_XML_ParserError. | |
Tree building methods: | |
The addChild methods add the variable or object val as a child node with tag name tagName. They all throw
| |
virtual void | addChild (unsigned long val, const char *tagName) |
Factory method adding a child encapsulating a variable of type long. | |
virtual void | addChild (long val, const char *tagName) |
Factory method adding a child encapsulating a variable of type long. | |
virtual void | addChild (MLuint64 val, const char *tagName) |
Factory method adding a child encapsulating a variable of type MLuint64. | |
virtual void | addChild (MLint64 val, const char *tagName) |
Factory method adding a child encapsulating a variable of type MLint64. | |
virtual void | addChild (long double val, const char *tagName) |
Factory method adding a child encapsulating a variable of type long double. | |
virtual void | addChild (const vec2 &vec, const char *tagName) |
Factory method adding a child encapsulating a variable of type Vector2. | |
virtual void | addChild (const vec3 &vec, const char *tagName) |
Factory method adding a child encapsulating a variable of type Vector3. | |
virtual void | addChild (const vec4 &vec, const char *tagName) |
Factory method adding a child encapsulating a variable of type Vector4. | |
virtual void | addChild (const vec6 &vec, const char *tagName) |
Factory method adding a child encapsulating a variable of type Vector6. | |
virtual void | addChild (const Vector &vec, const char *tagName) |
virtual void | addChild (const mat3 &mat, const char *tagName) |
Factory method adding a child encapsulating a variable of type Matrix3. | |
virtual void | addChild (const mat4 &mat, const char *tagName) |
Factory method adding a child encapsulating a variable of type Matrix4. | |
virtual void | addChild (const SubImgBox &box, const char *tagName) |
Factory method adding a child encapsulating a variable of type SubImageBox. | |
virtual void | addChild (const SubImgBoxf &box, const char *tagName) |
Factory method adding a child encapsulating a variable of type SubImageBoxd. | |
virtual void | addChild (const char *const text, const char *tagName) |
virtual void | addChild (const void *const ptr, size_t noBytes, const char *tagName) |
Factory method adding a child encapsulating raw data, identified by name, beginning at address ptr, and containing noBytes bytes. | |
virtual void | addChild (const Base *const obj, const char *tagName, bool generic=true) |
Adds an child representing an object whose class is derived from base and thus implements the addStateToTree() / readStateFromTree() methods. | |
virtual TreeNode * | addChild (const char *tagName) |
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
| |
virtual bool | hasChild (const char *tagName=NULL) |
returns true when a child of the given tagName exists. | |
virtual void | readChild (unsigned long &val, const char *tagName=NULL) |
Reads the value of a child of type unsigned long that is identified by its name. | |
virtual void | readChild (long &val, const char *tagName=NULL) |
Reads the value of a child of type long that is identified by its name. | |
virtual void | readChild (MLuint64 &val, const char *tagName=NULL) |
Reads the value of a child of type MLuint64 that is identified by its name. | |
virtual void | readChild (MLint64 &val, const char *tagName=NULL) |
Reads the value of a child of type MLint64 that is identified by its name. | |
virtual void | readChild (long double &val, const char *tagName=NULL) |
Reads the value of a child of type long double that is identified by its name. | |
virtual void | readChild (vec2 &val, const char *tagName=NULL) |
Reads the value of a child of type Vector2 that is identified by its name. | |
virtual void | readChild (vec3 &val, const char *tagName=NULL) |
Reads the value of a child of type Vector3 that is identified by its name. | |
virtual void | readChild (vec4 &val, const char *tagName=NULL) |
Reads the value of a child of type Vector4 that is identified by its name. | |
virtual void | readChild (vec6 &val, const char *tagName=NULL) |
Reads the value of a child of type Vector6 that is identified by its name. | |
virtual void | readChild (Vector &val, const char *tagName=NULL) |
virtual void | readChild (mat3 &val, const char *tagName=NULL) |
Reads the value of a child of type Matrix3 that is identified by its name. | |
virtual void | readChild (mat4 &val, const char *tagName=NULL) |
Reads the value of a child of type Matrix4 that is identified by its name. | |
virtual void | readChild (SubImgBox &val, const char *tagName=NULL) |
Reads the value of a child of type SubImageBox that is identified by its name. | |
virtual void | readChild (SubImgBoxf &val, const char *tagName=NULL) |
Reads the value of a child of type SubImageBoxd that is identified by its name. | |
virtual void | readChild (void *&ptr, unsigned long &noBytes, const char *tagName=NULL) |
Reads a child containing raw data that is identified by its name. | |
virtual void | readChild (char *&val, const char *tagName=NULL) |
The string returned is allocated on the heap. | |
virtual void | readChild (Base *&val, const char *tagName=NULL) |
The type of the object here is read from the XML file. | |
virtual void | readChild (Base &val, const char *tagName=NULL) |
Opposed to the readChild(Base*& ...) method, you have to create the object yourself BEFORE calling this method. | |
virtual void | readChild (TreeNode *&val, const char *tagName=NULL) |
Returns the group or container node with the specified tag name. | |
virtual void | deleteString (char *str) const |
delete a string that was created using either void readChild (char*& val, const char* tagName); or void writeToString (char*& str); | |
Version support | |
virtual void | setVersion (const char *className, int version) |
Set version for current node. className is currently not used. | |
virtual int | getVersion (const char *) |
Get version of current node. className is currently not used. | |
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 bool | _xercesInitialized |
Indicates whether the Xerces XML SubSystem is already initialized. | |
XMLTreeNode (DOMElement *parent) | |
protected constructor: | |
DOMElement * | _findElemByTagName (const char *tagName, DOMNode *prevNode=NULL) |
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. |
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 73 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. |
virtual ml::XMLTreeNode::~XMLTreeNode | ( | ) | [virtual] |
Destructor.
Terminates the parser system and DELETES THE COMPLETE TREE.
ml::XMLTreeNode::XMLTreeNode | ( | DOMElement * | parent | ) | [protected] |
protected constructor:
XMLTreeNode* ml::XMLTreeNode::_addTreeNodeChild | ( | DOMElement * | child | ) | [protected] |
Adds a new node containing the given child.
DOMElement* ml::XMLTreeNode::_findElemByTagName | ( | const char * | tagName, |
DOMNode * | prevNode = NULL |
||
) | [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.
static char* ml::XMLTreeNode::_getTextNodeString | ( | DOMElement * | parentNode | ) | [static, protected] |
Returns the string contained by the TextNode child of parentNode.
virtual void ml::XMLTreeNode::addChild | ( | MLint64 | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type MLint64.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | long double | double, |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type long double.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const mat4 & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type Matrix4.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const SubImgBox & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type SubImageBox.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const SubImgBoxf & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type SubImageBoxd.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const char *const | text, |
const char * | tagName | ||
) | [virtual] |
virtual void ml::XMLTreeNode::addChild | ( | const vec2 & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type Vector2.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const void *const | const, |
size_t | , | ||
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating raw data, identified by name, beginning at address ptr, and containing noBytes bytes.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const Base *const | obj, |
const char * | tagName, | ||
bool | generic = true |
||
) | [virtual] |
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. |
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const vec3 & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type Vector3.
Reimplemented from ml::TreeNode.
virtual TreeNode* ml::XMLTreeNode::addChild | ( | const char * | tagName | ) | [virtual] |
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.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | long | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type long.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const vec4 & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type Vector4.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | unsigned long | long, |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type long.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const vec6 & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type Vector6.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | MLuint64 | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type MLuint64.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::addChild | ( | const Vector & | vec, |
const char * | tagName | ||
) | [virtual] |
virtual void ml::XMLTreeNode::addChild | ( | const mat3 & | , |
const char * | |||
) | [virtual] |
Factory method adding a child encapsulating a variable of type Matrix3.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::deleteString | ( | char * | str | ) | const [virtual] |
delete a string that was created using either void readChild (char*& val, const char* tagName); or void writeToString (char*& str);
Reimplemented from ml::TreeNode.
virtual const char* ml::XMLTreeNode::getLastReadChildName | ( | ) | const [virtual] |
Returns the name of the child most recently read.
Reimplemented from ml::TreeNode.
virtual int ml::XMLTreeNode::getVersion | ( | const char * | ) | [virtual] |
Get version of current node. className
is currently not used.
Reimplemented from ml::TreeNode.
virtual bool ml::XMLTreeNode::hasChild | ( | const char * | tagName = NULL | ) | [virtual] |
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.
Reimplemented from ml::TreeNode.
static void ml::XMLTreeNode::initXMLSystem | ( | ) | [static] |
static char* ml::XMLTreeNode::normalizeFileName | ( | const char * | fileName | ) | [static] |
normalizes the given filename so that it can be used by Xerces to read or write a file with the given name:
Reads the value of a child of type MLint64
that is identified by its name.
Reimplemented from ml::TreeNode.
Reads the value of a child of type Vector2
that is identified by its name.
Reimplemented from ml::TreeNode.
Reads the value of a child of type Vector6
that is identified by its name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readChild | ( | long & | , |
const char * | = NULL |
||
) | [virtual] |
Reads the value of a child of type long
that is identified by its name.
Reimplemented from ml::TreeNode.
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.
Reimplemented from ml::TreeNode.
Reads the value of a child of type Vector3
that is identified by its name.
Reimplemented from ml::TreeNode.
Reads the value of a child of type SubImageBox
that is identified by its name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readChild | ( | void *& | , |
unsigned long & | , | ||
const char * | = NULL |
||
) | [virtual] |
Reads a child containing raw data that is identified by its name.
Returns the number of bytes read in noBytes.
Reimplemented from ml::TreeNode.
Reads the value of a child of type Vector4
that is identified by its name.
Reimplemented from ml::TreeNode.
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.
Reimplemented from ml::TreeNode.
Reads the value of a child of type Matrix4
that is identified by its name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readChild | ( | long double & | , |
const char * | = NULL |
||
) | [virtual] |
Reads the value of a child of type long
double
that is identified by its name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readChild | ( | char *& | val, |
const char * | tagName = NULL |
||
) | [virtual] |
The string returned is allocated on the heap.
Make sure to later dispose it using deleteString().
Reimplemented from ml::TreeNode.
Reads the value of a child of type MLuint64
that is identified by its name.
Reimplemented from ml::TreeNode.
Returns the group or container node with the specified tag name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readChild | ( | SubImgBoxf & | , |
const char * | = NULL |
||
) | [virtual] |
Reads the value of a child of type SubImageBoxd
that is identified by its name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readChild | ( | unsigned long & | , |
const char * | = NULL |
||
) | [virtual] |
Reads the value of a child of type unsigned
long
that is identified by its name.
Reimplemented from ml::TreeNode.
Reads the value of a child of type Matrix3
that is identified by its name.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readFromFile | ( | const char * | fileName | ) | [virtual] |
Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::readFromString | ( | const char * | str | ) | [virtual] |
Generates a tree parsing a string. Throws TNE_XML_ParserError.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::setVersion | ( | const char * | className, |
int | version | ||
) | [virtual] |
Set version for current node. className
is currently not used.
Reimplemented from ml::TreeNode.
static void ml::XMLTreeNode::terminateXMLSystem | ( | ) | [static] |
virtual void ml::XMLTreeNode::writeToFile | ( | const char * | fileName | ) | [virtual] |
Writes the complete tree to a file. Throws TNE_WritingFile.
Reimplemented from ml::TreeNode.
virtual void ml::XMLTreeNode::writeToString | ( | char *& | str | ) | [virtual] |
Writes the subtree rooted by this node to a string.
Reimplemented from ml::TreeNode.
DOMElement* ml::XMLTreeNode::_parentDOMNode [protected] |
pointer to the DOM node actually wrapped by this class
Definition at line 274 of file mlXMLTreeNode.h.
bool ml::XMLTreeNode::_xercesInitialized [static, protected] |
Indicates whether the Xerces XML SubSystem is already initialized.
Definition at line 277 of file mlXMLTreeNode.h.