MeVisLab Toolbox Reference
ml::XMLTreeNode Class 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>

Inheritance diagram for ml::XMLTreeNode:
ml::TreeNode

Public Member Functions

 XMLTreeNode (TreeNode::ConstructionMode mode=TreeNode::CM_writerRoot)
 Constructor. More...
 
 ~XMLTreeNode () override
 Destructor. More...
 
const char * getLastReadChildName () const override
 Returns the name of the child most recently read. More...
 
Version support
void setVersion (const char *className, int version) override
 Set version for current node. className is currently not used. More...
 
int getVersion (const char *) override
 Get version of current node. className is currently not used. More...
 
- Public Member Functions inherited from ml::TreeNode
virtual ~TreeNode ()
 Destructor deleting all children of this node. More...
 
virtual void addChild (bool val, const char *name) ADD_ULONG_CHILD
 Factory method adding a child encapsulating a variable of type bool. More...
 
virtual void addChild (unsigned char val, const char *name) ADD_ULONG_CHILD
 Factory method adding a child encapsulating a variable of type unsigned char. More...
 
virtual void addChild (char val, const char *name) ADD_LONG_CHILD
 Factory method adding a child encapsulating a variable of type char. More...
 
virtual void addChild (unsigned short val, const char *name) ADD_ULONG_CHILD
 Factory method adding a child encapsulating a variable of type unsigned short. More...
 
virtual void addChild (short val, const char *name) ADD_LONG_CHILD
 Factory method adding a child encapsulating a variable of type short. More...
 
virtual void addChild (unsigned int val, const char *name) ADD_ULONG_CHILD
 Factory method adding a child encapsulating a variable of type unsigned int. More...
 
virtual void addChild (int val, const char *name) ADD_LONG_CHILD
 Factory method adding a child encapsulating a variable of type int. More...
 
virtual void addChild (float val, const char *name) ADD_LDOUBLE_CHILD
 Factory method adding a child encapsulating a variable of type float. More...
 
virtual void addChild (double val, const char *name) ADD_LDOUBLE_CHILD
 Factory method adding a child encapsulating a variable of type double. More...
 

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: More...
 
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 More...
 
static int _numActiveRootInstances
 
static bool _xercesInitialized
 Indicates whether the Xerces XML SubSystem is already initialized. More...
 
 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. More...
 
XMLTreeNode_addTreeNodeChild (DOMElement *child)
 Adds a new node containing the given child. More...
 
static char * _getTextNodeString (DOMElement *parentNode)
 Returns the string contained by the TextNode child of parentNode. More...
 

Export methods:

void writeToFile (const char *fileName) override
 Writes the complete tree to a file. Throws TNE_WritingFile. More...
 
void writeToString (std::string &str) override
 Generates a string representation of the subtree represented by this node to a file. More...
 

Import methods:

void readFromFile (const char *fileName) override
 Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError. More...
 
void readFromString (const std::string &str) override
 Reads the subtree represented by this node from a string. More...
 

Tree building methods:

The addChild methods add the variable or object val as a child node with tag name tagName.

They all throw

  • TNE_ChildNotFound when no child with the specified tagName was found,
  • TNE_ReadingString when the child node was found, but the system was unable to read the string representing its value,
  • TNE_ReadingT (where T is the short name of the type of the first parameter) when this could also be read, but the conversion of the string to the class T failed,
  • TNE_InvalidParent when something has gone terribly wrong. One possibility is that you tried to read a child from a completely empty tree.
void addChild (unsigned long val, const char *tagName) override
 Factory method adding a child encapsulating a variable of type long. More...
 
void addChild (long val, const char *tagName) override
 Factory method adding a child encapsulating a variable of type long. More...
 
void addChild (MLuint64 val, const char *tagName) override
 Factory method adding a child encapsulating a variable of type MLuint64. More...
 
void addChild (MLint64 val, const char *tagName) override
 Factory method adding a child encapsulating a variable of type MLint64. More...
 
void addChild (long double val, const char *tagName) override
 Factory method adding a child encapsulating a variable of type long double. More...
 
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. More...
 
TreeNodeaddChild (const char *tagName) override
 Adds a group or container node with the specified tag name. More...
 

Tree reading methods:

The readChild methods read the variable or object val from the child node identified by tagName.

They all throw

  • TNE_ChildNotFound when no child with the specified tagName was found,
  • TNE_ReadingString when the child node was found, but the system was unable to read the string representing its value,
  • TNE_ReadingT (where T is the short name of the type of the first parameter) when this could also be read, but the conversion of the string to the class T failed,
  • TNE_InvalidParent when something has gone terribly wrong. One possibility is that you tried to read a child from a completely empty tree.
bool hasChild (const char *tagName=nullptr) override
 returns true when a child of the given tagName exists. More...
 
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
 
void readChild (Base *&val, const char *tagName=nullptr) override
 The type of the object here is read from the XML file. More...
 
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. More...
 
void readChild (TreeNode *&val, const char *tagName=nullptr) override
 Returns the group or container node with the specified tag name. More...
 

Additional Inherited Members

- Public Types inherited from ml::TreeNode
enum  ConstructionMode { CM_writerRoot , CM_readerRoot , CM_COUNT }
 TreeNode construction modes: More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ XMLTreeNode() [1/2]

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.

Parameters
modeUse TreeNode::CM_writerRoot if you want to create a root node for writing, and TreeNode::CM_readerRoot for reading.

◆ ~XMLTreeNode()

ml::XMLTreeNode::~XMLTreeNode ( )
override

Destructor.

Terminates the parser system and DELETES THE COMPLETE TREE.

◆ XMLTreeNode() [2/2]

ml::XMLTreeNode::XMLTreeNode ( DOMElement *  parent)
protected

protected constructor:

Member Function Documentation

◆ _addTreeNodeChild()

XMLTreeNode* ml::XMLTreeNode::_addTreeNodeChild ( DOMElement *  child)
protected

Adds a new node containing the given child.

◆ _findElemByTagName()

DOMElement* ml::XMLTreeNode::_findElemByTagName ( const char *  tagName,
DOMNode *  prevNode = nullptr 
)
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.

◆ _getTextNodeString()

static char* ml::XMLTreeNode::_getTextNodeString ( DOMElement *  parentNode)
staticprotected

Returns the string contained by the TextNode child of parentNode.

◆ addChild() [1/18]

void ml::XMLTreeNode::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.

Parameters
genericWhen 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.

◆ addChild() [2/18]

TreeNode* ml::XMLTreeNode::addChild ( const char *  tagName)
override

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.

◆ addChild() [3/18]

void ml::XMLTreeNode::addChild ( const ImageVector vec,
const char *  tagName 
)
override

◆ addChild() [4/18]

void ml::XMLTreeNode::addChild ( const Matrix3 mat,
const char *  tagName 
)
override

◆ addChild() [5/18]

void ml::XMLTreeNode::addChild ( const Matrix4 mat,
const char *  tagName 
)
override

◆ addChild() [6/18]

void ml::XMLTreeNode::addChild ( const std::string &  str,
const char *  tagName 
)
override

◆ addChild() [7/18]

void ml::XMLTreeNode::addChild ( const SubImageBox box,
const char *  tagName 
)
override

◆ addChild() [8/18]

void ml::XMLTreeNode::addChild ( const SubImageBoxd box,
const char *  tagName 
)
override

◆ addChild() [9/18]

void ml::XMLTreeNode::addChild ( const Vector2 vec,
const char *  tagName 
)
override

◆ addChild() [10/18]

void ml::XMLTreeNode::addChild ( const Vector3 vec,
const char *  tagName 
)
override

◆ addChild() [11/18]

void ml::XMLTreeNode::addChild ( const Vector4 vec,
const char *  tagName 
)
override

◆ addChild() [12/18]

void ml::XMLTreeNode::addChild ( const Vector6 vec,
const char *  tagName 
)
override

◆ addChild() [13/18]

void ml::XMLTreeNode::addChild ( const void *const  ptr,
size_t  noBytes,
const char *  tagName 
)
override

◆ addChild() [14/18]

void ml::XMLTreeNode::addChild ( long double  ,
const char *   
)
overridevirtual

Factory method adding a child encapsulating a variable of type long double.

Reimplemented from ml::TreeNode.

◆ addChild() [15/18]

void ml::XMLTreeNode::addChild ( long  ,
const char *   
)
overridevirtual

Factory method adding a child encapsulating a variable of type long.

Reimplemented from ml::TreeNode.

◆ addChild() [16/18]

void ml::XMLTreeNode::addChild ( MLint64  ,
const char *   
)
overridevirtual

Factory method adding a child encapsulating a variable of type MLint64.

Reimplemented from ml::TreeNode.

◆ addChild() [17/18]

void ml::XMLTreeNode::addChild ( MLuint64  ,
const char *   
)
overridevirtual

Factory method adding a child encapsulating a variable of type MLuint64.

Reimplemented from ml::TreeNode.

◆ addChild() [18/18]

void ml::XMLTreeNode::addChild ( unsigned long  ,
const char *   
)
overridevirtual

Factory method adding a child encapsulating a variable of type long.

Reimplemented from ml::TreeNode.

◆ getLastReadChildName()

const char* ml::XMLTreeNode::getLastReadChildName ( ) const
override

Returns the name of the child most recently read.

◆ getVersion()

int ml::XMLTreeNode::getVersion ( const char *  )
override

Get version of current node. className is currently not used.

◆ hasChild()

bool ml::XMLTreeNode::hasChild ( const char *  tagName = nullptr)
override

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.

◆ initXMLSystem()

static void ml::XMLTreeNode::initXMLSystem ( )
static

◆ normalizeFileName()

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:

  • A leading double-slash is converted to a double-backslash THE RETURNED CHARACTER ARRAY IS TO BE DELETED BY THE CALLER USING delete.

◆ readChild() [1/19]

void ml::XMLTreeNode::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.

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.

◆ readChild() [2/19]

void ml::XMLTreeNode::readChild ( Base *&  val,
const char *  tagName = nullptr 
)
override

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.

◆ readChild() [3/19]

void ml::XMLTreeNode::readChild ( ImageVector val,
const char *  tagName = nullptr 
)
override

◆ readChild() [4/19]

void ml::XMLTreeNode::readChild ( long &  val,
const char *  tagName = nullptr 
)
override

◆ readChild() [5/19]

void ml::XMLTreeNode::readChild ( long double &  val,
const char *  tagName = nullptr 
)
override

◆ readChild() [6/19]

void ml::XMLTreeNode::readChild ( Matrix3 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [7/19]

void ml::XMLTreeNode::readChild ( Matrix4 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [8/19]

void ml::XMLTreeNode::readChild ( MLint64 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [9/19]

void ml::XMLTreeNode::readChild ( MLuint64 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [10/19]

void ml::XMLTreeNode::readChild ( std::string &  val,
const char *  tagName = nullptr 
)
override

◆ readChild() [11/19]

void ml::XMLTreeNode::readChild ( SubImageBox val,
const char *  tagName = nullptr 
)
override

◆ readChild() [12/19]

void ml::XMLTreeNode::readChild ( SubImageBoxd val,
const char *  tagName = nullptr 
)
override

◆ readChild() [13/19]

void ml::XMLTreeNode::readChild ( TreeNode *&  val,
const char *  tagName = nullptr 
)
override

Returns the group or container node with the specified tag name.

◆ readChild() [14/19]

void ml::XMLTreeNode::readChild ( unsigned long &  val,
const char *  tagName = nullptr 
)
override

◆ readChild() [15/19]

void ml::XMLTreeNode::readChild ( Vector2 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [16/19]

void ml::XMLTreeNode::readChild ( Vector3 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [17/19]

void ml::XMLTreeNode::readChild ( Vector4 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [18/19]

void ml::XMLTreeNode::readChild ( Vector6 val,
const char *  tagName = nullptr 
)
override

◆ readChild() [19/19]

void ml::XMLTreeNode::readChild ( void *&  ptr,
unsigned long &  noBytes,
const char *  tagName = nullptr 
)
override

◆ readFromFile()

void ml::XMLTreeNode::readFromFile ( const char *  fileName)
overridevirtual

Generates a tree parsing a file. Throws TNE_FileNotFound, TNE_ReadingFile, TNE_XML_ParserError.

Reimplemented from ml::TreeNode.

◆ readFromString()

void ml::XMLTreeNode::readFromString ( const std::string &  )
overridevirtual

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.

◆ setVersion()

void ml::XMLTreeNode::setVersion ( const char *  className,
int  version 
)
override

Set version for current node. className is currently not used.

◆ terminateXMLSystem()

static void ml::XMLTreeNode::terminateXMLSystem ( )
static

◆ writeToFile()

void ml::XMLTreeNode::writeToFile ( const char *  fileName)
overridevirtual

Writes the complete tree to a file. Throws TNE_WritingFile.

Reimplemented from ml::TreeNode.

◆ writeToString()

void ml::XMLTreeNode::writeToString ( std::string &  )
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.

Member Data Documentation

◆ _numActiveRootInstances

int ml::XMLTreeNode::_numActiveRootInstances
staticprotected

Definition at line 327 of file mlXMLTreeNode.h.

◆ _parentDOMNode

DOMElement* ml::XMLTreeNode::_parentDOMNode
protected

pointer to the DOM node actually wrapped by this class

Definition at line 323 of file mlXMLTreeNode.h.

◆ _xercesInitialized

bool ml::XMLTreeNode::_xercesInitialized
staticprotected

Indicates whether the Xerces XML SubSystem is already initialized.

Definition at line 330 of file mlXMLTreeNode.h.


The documentation for this class was generated from the following file: