VAPOR3 3.9.4
|
An Xml tree. More...
#include <XmlNode.h>
Public Member Functions | |
XmlNode (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0) | |
XmlNode (const string &tag, size_t numChildrenHint=0) | |
XmlNode () | |
virtual XmlNode * | Construct (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0) |
XmlNode (const XmlNode &node) | |
virtual XmlNode * | Clone () |
virtual | ~XmlNode () |
string & | Tag () |
string | GetTag () const |
void | SetTag (string tag) |
map< string, string > & | Attrs () |
virtual void | SetElementLong (const vector< string > &tags, const vector< long > &values) |
virtual void | SetElementLong (const vector< string > &tags, long value) |
virtual void | SetElementLong (const string &tag, const vector< long > &values) |
virtual void | SetElementLong (const string &tag, long value) |
virtual const vector< long > & | GetElementLong (const string &tag) const |
virtual bool | HasElementLong (const string &tag) const |
virtual void | SetElementDouble (const string &tag, const vector< double > &values) |
virtual void | SetElementDouble (const string &tag, double value) |
virtual void | SetElementDouble (const vector< string > &tags, const vector< double > &values) |
virtual void | SetElementDouble (const vector< string > &tags, double value) |
virtual const vector< double > & | GetElementDouble (const string &tag) const |
virtual bool | HasElementDouble (const string &tag) const |
virtual void | SetElementString (const string &tag, const string &values) |
virtual const string & | GetElementString (const string &tag) const |
virtual void | SetElementStringVec (const string &tag, const vector< string > &values) |
virtual void | SetElementStringVec (const vector< string > &tagpath, const vector< string > &values) |
virtual void | GetElementStringVec (const string &tag, vector< string > &vec) const |
virtual bool | HasElementString (const string &tag) const |
XmlNode * | AddChild (const XmlNode *child) |
XmlNode * | AddChild (const XmlNode &child) |
virtual int | GetNumChildren () const |
virtual XmlNode * | NewChild (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0) |
virtual XmlNode * | NewChild (const string &tag, size_t numChildrenHint=0) |
virtual int | DeleteChild (size_t index) |
virtual int | DeleteChild (const string &tag) |
virtual void | DeleteAll () |
virtual XmlNode * | GetChild (size_t index) const |
virtual bool | HasChild (size_t index) const |
virtual XmlNode * | GetChild (const string &tag) const |
virtual bool | HasChild (const string &tag) const |
virtual XmlNode * | GetNode (std::vector< string > path, bool absolute) const |
virtual XmlNode * | GetNode (string path) const |
virtual XmlNode * | GetParent () const |
void | SetParent (XmlNode *parent) |
XmlNode & | operator= (const XmlNode &rhs) |
Assignment operator. | |
bool | operator== (const XmlNode &rhs) const |
Equivalence operator. | |
bool | operator!= (const XmlNode &rhs) const |
virtual bool | IsRoot () const |
virtual std::vector< string > | GetPathVec () const |
virtual string | GetPath () const |
virtual XmlNode * | GetRoot () const |
Public Member Functions inherited from Wasp::MyBase | |
MyBase () | |
const string & | getClassName () const |
Static Public Member Functions | |
static const std::vector< XmlNode * > & | GetAllocatedNodes () |
static ostream & | streamOut (ostream &os, const XmlNode &node) |
static bool | IsValidXMLElement (const string &s, int *badIdx=nullptr) |
static string | SanitizeXMLTag (string s) |
Static Public Member Functions inherited from Wasp::MyBase | |
static void | SetErrMsg (const char *format,...) |
Record a formatted error message. | |
static void | SetErrMsg (int errcode, const char *format,...) |
Record a formatted error message and an error code. | |
static const char * | GetErrMsg () |
static void | SetErrCode (int err_code) |
Record an error code. | |
static int | GetErrCode () |
Retrieve the current error code. | |
static void | SetErrMsgCB (ErrMsgCB_T cb) |
static ErrMsgCB_T | GetErrMsgCB () |
static void | SetErrMsgFilePtr (FILE *fp) |
static const FILE * | SetErrMsgFilePtr () |
static void | SetDiagMsg (const char *format,...) |
Record a formatted diagnostic message. | |
static const char * | GetDiagMsg () |
static void | SetDiagMsgCB (DiagMsgCB_T cb) |
static DiagMsgCB_T | GetDiagMsgCB () |
static void | SetDiagMsgFilePtr (FILE *fp) |
static bool | EnableErrMsg (bool enable) |
static bool | GetEnableErrMsg () |
Friends | |
ostream & | operator<< (ostream &s, const XmlNode &node) |
Write the XML tree, rooted at this node, to a file in XML format. | |
Additional Inherited Members | |
Public Types inherited from Wasp::MyBase | |
typedef void(* | ErrMsgCB_T) (const char *msg, int err_code) |
typedef void(* | DiagMsgCB_T) (const char *msg) |
Static Public Attributes inherited from Wasp::MyBase | |
static char * | ErrMsg |
static int | ErrCode |
static int | ErrMsgSize |
static FILE * | ErrMsgFilePtr |
static ErrMsgCB_T | ErrMsgCB |
static char * | DiagMsg |
static int | DiagMsgSize |
static FILE * | DiagMsgFilePtr |
static DiagMsgCB_T | DiagMsgCB |
static bool | Enabled |
Protected Member Functions inherited from Wasp::MyBase | |
void | SetClassName (const string &name) |
An Xml tree.
This class manages an XML tree. Each node in the tree coresponds to an XML "parent" element. The concept of "parent" element is a creation of this class, and should be confused with any notions of parent in more commonly used XML jargon. A parent element is simply one possessing child XML elements Non-parent elements - those elements that do not have children elements - may be thought of as data elements. Typically non-parent elements possess XML character data. Parent elements may or may not have XML character data themselves.
The XmlNode class is derived from the MyBase base class. Hence all of the methods make use of MyBase's error reporting capability. Any method with a return type of int returns a 0 on success, and and a negative int on failure, unless otherwise docummented. Similary, methods returning pointers return non-NULL on success and NULL on failure. Failure in either case triggers logging of an error message with MyBase::SetErrMsg()
VAPoR::XmlNode::XmlNode | ( | const string & | tag, |
const map< string, string > & | attrs, | ||
size_t | numChildrenHint = 0 |
||
) |
Constructor for the XmlNode class.
Create's a new Xml node
[in] | tag | Name of Xml node |
[in] | attrs | A list of Xml attribute names and values for this node |
[in] | numChildrenHint | Reserve space for the indicated number of children. Children must be created with the NewChild() method |
VAPoR::XmlNode::XmlNode | ( | const string & | tag, |
size_t | numChildrenHint = 0 |
||
) |
VAPoR::XmlNode::XmlNode | ( | ) |
VAPoR::XmlNode::XmlNode | ( | const XmlNode & | node | ) |
|
virtual |
Destructor
Recursively delete node and chilren, but only if this is the root node. Otherwise this method is a no-op
Return the number of children nodes this node has
n | The number of direct children this node has |
The new child node will be cloned from child
and appended to the array of child nodes.
[in] | child | is the XmlNode object to be added as a child |
newchild | Returns a pointer to the newly created child. This is a no-fail method (NULL is never returned). |
|
inline |
|
inlinevirtual |
|
virtual |
Recursively delete all descendants of a node.
|
virtual |
|
virtual |
Delete the indicated child node.
Delete the indicated child node, decrementing the total number of children by one. Return an error if the child does not exist (i.e. if index >= GetNumChildren())
[in] | index | Index of the child. The first child is zero |
status | Returns a non-negative value on success |
|
inlinestatic |
|
virtual |
Return the indicated child node.
Return the indicated tagged child node. Return NULL if the child does not exist.
[in] | tag | Name of the child node to return |
child | Returns the indicated child, or NULL if the child could does not exist. No error is generated on failure. |
|
virtual |
Return the indicated child node.
Return the ith child of this node. The first child node is index=0, the last is index=GetNumChildren()-1. Return NULL if the child does not exist.
[in] | index | Index of the child. The first child is zero |
child | Returns the indicated child, or NULL if the child could does not exist. No error is generated on failure. |
|
virtual |
Get an Xml element's data of type double
Return the character data associated with the Xml elemented named by tag
for this node. The data is interpreted and returned as a vector of doubles. If the element does not exist an empty vector is returned.
[in] | tag | Name of element |
vector | Vector of doubles associated with the named elemented |
|
virtual |
Get an Xml element's data of type long
Return the character data associated with the Xml elemented named by tag
for this node. The data is interpreted and returned as a vector of longs. If the element does not exist an empty vector is returned.
[in] | tag | Name of element |
vector | Vector of longs associated with the named elemented |
|
virtual |
Get an Xml element's data of type string
Return the character data associated with the Xml elemented named by tag
for this node. The data is interpreted and returned as a string. If the element does not exist an empty vector is returned.
[in] | tag | Name of element |
string | The string associated with the named element |
|
virtual |
Get an Xml element's data of type string
Return the character data associated with the Xml elemented named by tag
for this node. The data is interpreted as a space-separated list of words (contiguous characters). The string vector returned is generated by treating white space as delimeters between vector elements. If the element does not exist an empty vector is returned
[in] | tag | Name of element |
[out] | vec | Vector of strings associated with the named element |
|
virtual |
Return a pointer to a node with the indicated path if it exists
This method returns a pointer to the node with the path indicated by the path vector path
. If absolute
is true the search begins from the root of the root of the tree. If absolute
is false, the search begins with the children of this node.
retval
The indicated node is returned on success. If the path is not valid NULL is returned, but no error is reported
Referenced by VAPoR::ParamsContainer::GetNode(), and VAPoR::RenParamsContainer::GetNode().
|
virtual |
Return a pointer to a node with the indicated path if it exists
The path argument path
is parsed into a vector of strings, with the '/' character used as a delimiter. The resulting path vector is passed to GetNode(std::vector <string> path, bool absolute). If the first character in path
is '/' then an absolute path is assumed.
|
inlinevirtual |
|
inlinevirtual |
|
virtual |
Get the path from the root to this node as a delimeter separated string
This method constructs a delimeter separated path from the string vector returned by GetPathVec(). The delimiter is a '/'
|
virtual |
Get the path from the root to this node as a vector of tags
This method returns an ordered vector of strings containing all of the XmlNode tags from the root to this node. The first string in the vector is the root node tag.
|
virtual |
Get the root node of the tree
Walks up the tree starting from this node and returns the root node of the tree
|
virtual |
Return true if the indicated child node exists
[in] | tag | Name of the child node |
bool |
|
virtual |
Return true if the indicated child node exists
[in] | index | Index of the child. The first child is zero |
bool |
|
virtual |
Return true if the named element of type double exists
[in] | tag | Name of element |
bool |
|
virtual |
Return true if the named element of type long exists
[in] | tag | Name of element |
value | at element |
|
virtual |
Return true if the named element of type string exists
[in] | tag | Name of element |
bool |
|
inlinevirtual |
|
static |
|
virtual |
Create a new child of this node
Create a new child node, named tag
. The new child node will be appended to the array of child nodes. The numChildrenHint
parameter is a hint specifying how many children the new child itself may have.
[in] | tag | Name to give the new child node |
[in] | attrs | A list of Xml attribute names and values for this node |
[in] | numChildrenHint | Reserve space for future children of this node |
child | Returns the newly created child, or NULL if the child could not be created |
|
inlinevirtual |
|
inline |
bool VAPoR::XmlNode::operator== | ( | const XmlNode & | rhs | ) | const |
Equivalence operator.
|
static |
|
virtual |
Set an Xml element of type double
This method defines and sets an Xml element. The Xml character data to be associated with this element is the array of doubles specified by values
[in] | tag | Name of the element to define/set |
[in] | values | Vector of doubles to be converted to character data |
status | 0 if successful |
|
inlinevirtual |
|
virtual |
Set an Xml element of type double, using a sequence of tags
This method defines and sets an Xml element. The Xml character data to be associated with this element is the array of doubles specified by values
[in] | tags | vector of tags to the specified element |
[in] | values | Vector of doubles to be converted to character data |
status | 0 if successful |
|
inlinevirtual |
|
virtual |
Set an Xml element of type long
This method defines and sets an Xml element. The Xml character data to be associated with this element is the array of longs specified by values
[in] | tag | Name of the element to define/set |
[in] | values | Vector of longs to be converted to character data |
status | Returns 0 if successful |
|
inlinevirtual |
|
virtual |
Set an Xml element of type long
This method defines and sets an Xml element. The Xml character data to be associated with this element is the array of longs specified by values
[in] | tags | Sequence of names of elements as a path to the desired node |
[in] | values | Vector of longs to be converted to character data |
status | Returns 0 if successful |
|
inlinevirtual |
|
virtual |
Set an Xml element of type string
This method defines and sets an Xml element. The Xml character data to be associated with this element is the string specified by values
[in] | tag | Name of the element to define/set |
[in] | values | string to be converted to character data |
status | Returns a non-negative value on success |
status | Returns 0 if successful |
|
virtual |
Set an Xml element of type string
This method defines and sets an Xml element. The Xml character data to be associated with this element is the array of strings specified by values
. The array of strings is first translated to a single string of space-separated words (contiguous characters)
[in] | tag | Name of the element to define/set |
[in] | values | Vector of strings to be converted to a space-separated list of characters |
status | Returns 0 if successful |
|
virtual |
Set an Xml element of type string
This method defines and sets an Xml element. The Xml character data to be associated with this element is the array of strings specified by values
. The array of strings is first translated to a single string of space-separated words (contiguous characters)
[in] | tagpath | sequence of tags leading from this to element |
[in] | values | Vector of strings to be converted to a space-separated list of characters |
status | Returns 0 if successful |
void VAPoR::XmlNode::SetParent | ( | XmlNode * | parent | ) |
Set a node's parent
Set the parent node to parent
, adding this node to the children of parent
, and removing it from the children of the node's current parent. If parent
already has a child with the same name as this node that child is deleted.
parent
may be NULL in which case the node becomes a root node
|
static |
|
inline |
|
friend |
Write the XML tree, rooted at this node, to a file in XML format.