VAPoR
0.1
|
An Xml tree. More...
#include <XmlNode.h>
Public Types | |
enum | ErrCode_T { ERR_DEF = 1, ERR_TNP } |
Public Types inherited from VetsUtil::MyBase | |
typedef void(* | ErrMsgCB_T) (const char *msg, int err_code) |
typedef void(* | DiagMsgCB_T) (const char *msg) |
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 () |
map< string, string > & | Attrs () |
virtual int | SetElementLong (const vector< string > &tags, const vector< long > &values) |
virtual int | SetElementLong (const string &tag, const vector< long > &values) |
virtual const vector< long > & | GetElementLong (const string &tag) const |
virtual int | HasElementLong (const string &tag) const |
virtual int | SetElementDouble (const string &tag, const vector< double > &values) |
virtual int | SetElementDouble (const vector< string > &tags, const vector< double > &values) |
virtual const vector< double > & | GetElementDouble (const string &tag) const |
virtual int | HasElementDouble (const string &tag) const |
virtual int | SetElementString (const string &tag, const string &values) |
virtual const string & | GetElementString (const string &tag) const |
virtual int | SetElementStringVec (const string &tag, const vector< string > &values) |
virtual int | SetElementStringVec (const vector< string > &tagpath, const vector< string > &values) |
virtual void | GetElementStringVec (const string &tag, vector< string > &vec) const |
virtual int | HasElementString (const string &tag) const |
virtual void | AddChild (XmlNode *child) |
virtual int | GetNumChildren () const |
virtual XmlNode * | NewChild (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0) |
virtual int | DeleteChild (size_t index) |
virtual int | DeleteChild (const string &tag) |
virtual void | DeleteAll () |
virtual void | ClearChildren () |
virtual int | ReplaceChild (XmlNode *childNode, XmlNode *newChild) |
virtual XmlNode * | GetChild (size_t index) const |
virtual XmlNode * | GetParent () |
virtual int | HasChild (size_t index) |
virtual XmlNode * | GetChild (const string &tag) const |
virtual bool & | ErrOnMissing () |
virtual int | HasChild (const string &tag) |
Public Member Functions inherited from VetsUtil::MyBase | |
MyBase () | |
const string & | getClassName () const |
Static Public Member Functions | |
static ostream & | streamOut (ostream &os, const XmlNode &node) |
static string | replaceAll (const string &sourceString, const char *input, const char *output) |
Static Public Member Functions inherited from VetsUtil::MyBase | |
static void | SetErrMsg (const char *format,...) |
Record a formatted error message. More... | |
static void | SetErrMsg (int errcode, const char *format,...) |
Record a formatted error message and an error code. More... | |
static const char * | GetErrMsg () |
static void | SetErrCode (int err_code) |
Record an error code. More... | |
static int | GetErrCode () |
Retrieve the current error code. More... | |
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. More... | |
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 Public Attributes | |
static vector< long > | _emptyLongVec |
static vector< double > | _emptyDoubleVec |
static vector< string > | _emptyStringVec |
static string | _emptyString |
Static Public Attributes inherited from VetsUtil::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 Attributes | |
map< string, vector< long > > | _longmap |
map< string, vector< double > > | _doublemap |
map< string, string > | _stringmap |
bool | _errOnMissing |
Friends | |
ostream & | operator<< (ostream &s, const XmlNode &node) |
Write the XML tree, rooted at this node, to a file in XML format. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from VetsUtil::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 - the success of any method (including constructors) can (and should) be tested with the GetErrCode() method. If non-zero, an error message can be retrieved with GetErrMsg().
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 | ( | const XmlNode & | node | ) |
|
virtual |
|
virtual |
Return the number of children nodes this node has
n | The number of direct children this node has |
The new child node will be appended to the array of child nodes.
[in] | child | is the XmlNode object to be added as a child |
|
inline |
|
inlinevirtual |
|
inlinevirtual |
Reimplemented in VAPoR::ParamNode.
|
virtual |
Recursively delete all descendants of a node.
|
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 |
|
virtual |
|
inlinevirtual |
Set or Get the Error on Missing Flag
This method returns a reference to a flag that may be used to control whether GetElement methods will generate an error if the requested element is not present. If the flag is set to true, an error will be generated if the element is not found. By default the flag is true.
flag | A reference to the Error on Missing flag |
|
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 |
Reimplemented in VAPoR::ParamNode.
Referenced by VAPoR::ParamNode::GetChild(), and VAPoR::ParamNode::GetNode().
|
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 |
|
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. If ErrOnMissing() is true an error is generated if the element is missing;
[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. If ErrOnMissing() is true an error is generated if the element is missing;
[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. If ErrOnMissing() is true an error is generated if the element is missing;
[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 |
|
inlinevirtual |
|
inlinevirtual |
|
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 indicated child node exists
[in] | tag | Name of the child node |
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 |
|
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 |
|
static |
Replace the indicated child node with specified new child node
If indicated child does not exist, return -1, otherwise return the index of the replaced child.
[in] | childNode | Pointer to existing child node |
[in] | newChild | Pointer to replacement child node |
status | Returns non-negative child index on success |
|
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 |
Reimplemented in VAPoR::ParamNode.
|
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 |
Reimplemented in VAPoR::ParamNode.
|
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 |
Reimplemented in VAPoR::ParamNode.
|
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 |
Reimplemented in VAPoR::ParamNode.
|
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 |
Reimplemented in VAPoR::ParamNode.
|
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 |
Reimplemented in VAPoR::ParamNode.
|
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 |
Reimplemented in VAPoR::ParamNode.
|
static |
|
inline |
|
friend |
Write the XML tree, rooted at this node, to a file in XML format.
|
protected |
|
protected |