VAPOR3 3.9.4
Public Member Functions | Static Public Member Functions | Friends | List of all members
VAPoR::XmlNode Class Reference

An Xml tree. More...

#include <XmlNode.h>

Inheritance diagram for VAPoR::XmlNode:
Wasp::MyBase

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 XmlNodeConstruct (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0)
 
 XmlNode (const XmlNode &node)
 
virtual XmlNodeClone ()
 
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
 
XmlNodeAddChild (const XmlNode *child)
 
XmlNodeAddChild (const XmlNode &child)
 
virtual int GetNumChildren () const
 
virtual XmlNodeNewChild (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0)
 
virtual XmlNodeNewChild (const string &tag, size_t numChildrenHint=0)
 
virtual int DeleteChild (size_t index)
 
virtual int DeleteChild (const string &tag)
 
virtual void DeleteAll ()
 
virtual XmlNodeGetChild (size_t index) const
 
virtual bool HasChild (size_t index) const
 
virtual XmlNodeGetChild (const string &tag) const
 
virtual bool HasChild (const string &tag) const
 
virtual XmlNodeGetNode (std::vector< string > path, bool absolute) const
 
virtual XmlNodeGetNode (string path) const
 
virtual XmlNodeGetParent () const
 
void SetParent (XmlNode *parent)
 
XmlNodeoperator= (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 XmlNodeGetRoot () 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)
 

Detailed Description

An Xml tree.

Author
John Clyne
Version
$Revision$
Date
$Date$

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()

Definition at line 49 of file XmlNode.h.

Constructor & Destructor Documentation

◆ XmlNode() [1/4]

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

Parameters
[in]tagName of Xml node
[in]attrsA list of Xml attribute names and values for this node
[in]numChildrenHintReserve space for the indicated number of children. Children must be created with the NewChild() method

◆ XmlNode() [2/4]

VAPoR::XmlNode::XmlNode ( const string &  tag,
size_t  numChildrenHint = 0 
)

◆ XmlNode() [3/4]

VAPoR::XmlNode::XmlNode ( )

◆ XmlNode() [4/4]

VAPoR::XmlNode::XmlNode ( const XmlNode node)

Copy constructor for the XmlNode class.

Create's a new XmlNode node from an existing one. The new node will be parentless.

Parameters
[in]nodeXmlNode instance from which to construct a copy

◆ ~XmlNode()

virtual VAPoR::XmlNode::~XmlNode ( )
virtual

Destructor

Recursively delete node and chilren, but only if this is the root node. Otherwise this method is a no-op

See also
SetParent()

Member Function Documentation

◆ AddChild() [1/2]

XmlNode * VAPoR::XmlNode::AddChild ( const XmlNode child)

◆ AddChild() [2/2]

XmlNode * VAPoR::XmlNode::AddChild ( const XmlNode child)

Return the number of children nodes this node has

Return values
nThe number of direct children this node has
See also
NewChild() Add an existing node as a child of the current node.

The new child node will be cloned from child and appended to the array of child nodes.

Parameters
[in]childis the XmlNode object to be added as a child
Return values
newchildReturns a pointer to the newly created child. This is a no-fail method (NULL is never returned).

◆ Attrs()

map< string, string > & VAPoR::XmlNode::Attrs ( )
inline

Set or get that node's attributes

Return values
attrsA reference to the node's attributes

Definition at line 101 of file XmlNode.h.

◆ Clone()

virtual XmlNode * VAPoR::XmlNode::Clone ( )
inlinevirtual

Definition at line 76 of file XmlNode.h.

◆ Construct()

virtual XmlNode * VAPoR::XmlNode::Construct ( const string &  tag,
const map< string, string > &  attrs,
size_t  numChildrenHint = 0 
)
inlinevirtual

Definition at line 65 of file XmlNode.h.

◆ DeleteAll()

virtual void VAPoR::XmlNode::DeleteAll ( )
virtual

Recursively delete all descendants of a node.

◆ DeleteChild() [1/2]

virtual int VAPoR::XmlNode::DeleteChild ( const string &  tag)
virtual

◆ DeleteChild() [2/2]

virtual int VAPoR::XmlNode::DeleteChild ( size_t  index)
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())

Parameters
[in]indexIndex of the child. The first child is zero
Return values
statusReturns a non-negative value on success
See also
GetNumChildren()

◆ GetAllocatedNodes()

static const std::vector< XmlNode * > & VAPoR::XmlNode::GetAllocatedNodes ( )
inlinestatic

Definition at line 498 of file XmlNode.h.

◆ GetChild() [1/2]

virtual XmlNode * VAPoR::XmlNode::GetChild ( const string &  tag) const
virtual

Return the indicated child node.

Return the indicated tagged child node. Return NULL if the child does not exist.

Parameters
[in]tagName of the child node to return
Return values
childReturns the indicated child, or NULL if the child could does not exist. No error is generated on failure.

◆ GetChild() [2/2]

virtual XmlNode * VAPoR::XmlNode::GetChild ( size_t  index) const
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.

Parameters
[in]indexIndex of the child. The first child is zero
Return values
childReturns the indicated child, or NULL if the child could does not exist. No error is generated on failure.
See also
GetNumChildren()

◆ GetElementDouble()

virtual const vector< double > & VAPoR::XmlNode::GetElementDouble ( const string &  tag) const
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.

Parameters
[in]tagName of element
Return values
vectorVector of doubles associated with the named elemented

◆ GetElementLong()

virtual const vector< long > & VAPoR::XmlNode::GetElementLong ( const string &  tag) const
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.

Parameters
[in]tagName of element
Return values
vectorVector of longs associated with the named elemented

◆ GetElementString()

virtual const string & VAPoR::XmlNode::GetElementString ( const string &  tag) const
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.

Parameters
[in]tagName of element
Return values
stringThe string associated with the named element

◆ GetElementStringVec()

virtual void VAPoR::XmlNode::GetElementStringVec ( const string &  tag,
vector< string > &  vec 
) const
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

Parameters
[in]tagName of element
[out]vecVector of strings associated with the named element

◆ GetNode() [1/2]

virtual XmlNode * VAPoR::XmlNode::GetNode ( std::vector< string >  path,
bool  absolute 
) const
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().

◆ GetNode() [2/2]

virtual XmlNode * VAPoR::XmlNode::GetNode ( string  path) const
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.

See also
GetNode(std::vector <string> path, bool absolute)

◆ GetNumChildren()

virtual int VAPoR::XmlNode::GetNumChildren ( ) const
inlinevirtual

Definition at line 319 of file XmlNode.h.

◆ GetParent()

virtual XmlNode * VAPoR::XmlNode::GetParent ( ) const
inlinevirtual

Return the node's parent

This method returns a pointer to the parent node, or NULL if this node is the root of the tree.

Return values
nodePointer to parent node or NULL if no parent exists

Definition at line 441 of file XmlNode.h.

◆ GetPath()

virtual string VAPoR::XmlNode::GetPath ( ) const
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 '/'

◆ GetPathVec()

virtual std::vector< string > VAPoR::XmlNode::GetPathVec ( ) const
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.

◆ GetRoot()

virtual XmlNode * VAPoR::XmlNode::GetRoot ( ) const
virtual

Get the root node of the tree

Walks up the tree starting from this node and returns the root node of the tree

◆ GetTag()

string VAPoR::XmlNode::GetTag ( ) const
inline

Definition at line 93 of file XmlNode.h.

◆ HasChild() [1/2]

virtual bool VAPoR::XmlNode::HasChild ( const string &  tag) const
virtual

Return true if the indicated child node exists

Parameters
[in]tagName of the child node
Return values
bool

◆ HasChild() [2/2]

virtual bool VAPoR::XmlNode::HasChild ( size_t  index) const
virtual

Return true if the indicated child node exists

Parameters
[in]indexIndex of the child. The first child is zero
Return values
bool

◆ HasElementDouble()

virtual bool VAPoR::XmlNode::HasElementDouble ( const string &  tag) const
virtual

Return true if the named element of type double exists

Parameters
[in]tagName of element
Return values
bool

◆ HasElementLong()

virtual bool VAPoR::XmlNode::HasElementLong ( const string &  tag) const
virtual

Return true if the named element of type long exists

Parameters
[in]tagName of element
Return values
valueat element

◆ HasElementString()

virtual bool VAPoR::XmlNode::HasElementString ( const string &  tag) const
virtual

Return true if the named element of type string exists

Parameters
[in]tagName of element
Return values
bool

◆ IsRoot()

virtual bool VAPoR::XmlNode::IsRoot ( ) const
inlinevirtual

Return boolean indicating if this node is the root of the tree

This method returns true if the node is the root if the tree. I.e. true is returned if the node has no parent. Otherwise false is returned.

Definition at line 474 of file XmlNode.h.

◆ IsValidXMLElement()

static bool VAPoR::XmlNode::IsValidXMLElement ( const string &  s,
int *  badIdx = nullptr 
)
static

◆ NewChild() [1/2]

virtual XmlNode * VAPoR::XmlNode::NewChild ( const string &  tag,
const map< string, string > &  attrs,
size_t  numChildrenHint = 0 
)
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.

Parameters
[in]tagName to give the new child node
[in]attrsA list of Xml attribute names and values for this node
[in]numChildrenHintReserve space for future children of this node
Return values
childReturns the newly created child, or NULL if the child could not be created

◆ NewChild() [2/2]

virtual XmlNode * VAPoR::XmlNode::NewChild ( const string &  tag,
size_t  numChildrenHint = 0 
)
inlinevirtual

Definition at line 336 of file XmlNode.h.

◆ operator!=()

bool VAPoR::XmlNode::operator!= ( const XmlNode rhs) const
inline

Definition at line 467 of file XmlNode.h.

◆ operator=()

XmlNode & VAPoR::XmlNode::operator= ( const XmlNode rhs)

Assignment operator.

◆ operator==()

bool VAPoR::XmlNode::operator== ( const XmlNode rhs) const

Equivalence operator.

◆ SanitizeXMLTag()

static string VAPoR::XmlNode::SanitizeXMLTag ( string  s)
static

◆ SetElementDouble() [1/4]

virtual void VAPoR::XmlNode::SetElementDouble ( const string &  tag,
const vector< double > &  values 
)
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

Parameters
[in]tagName of the element to define/set
[in]valuesVector of doubles to be converted to character data
Return values
status0 if successful

◆ SetElementDouble() [2/4]

virtual void VAPoR::XmlNode::SetElementDouble ( const string &  tag,
double  value 
)
inlinevirtual

Definition at line 178 of file XmlNode.h.

◆ SetElementDouble() [3/4]

virtual void VAPoR::XmlNode::SetElementDouble ( const vector< string > &  tags,
const vector< double > &  values 
)
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

Parameters
[in]tagsvector of tags to the specified element
[in]valuesVector of doubles to be converted to character data
Return values
status0 if successful

◆ SetElementDouble() [4/4]

virtual void VAPoR::XmlNode::SetElementDouble ( const vector< string > &  tags,
double  value 
)
inlinevirtual

Definition at line 196 of file XmlNode.h.

◆ SetElementLong() [1/4]

virtual void VAPoR::XmlNode::SetElementLong ( const string &  tag,
const vector< long > &  values 
)
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

Parameters
[in]tagName of the element to define/set
[in]valuesVector of longs to be converted to character data
Return values
statusReturns 0 if successful

◆ SetElementLong() [2/4]

virtual void VAPoR::XmlNode::SetElementLong ( const string &  tag,
long  value 
)
inlinevirtual

Definition at line 141 of file XmlNode.h.

◆ SetElementLong() [3/4]

virtual void VAPoR::XmlNode::SetElementLong ( const vector< string > &  tags,
const vector< long > &  values 
)
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

Parameters
[in]tagsSequence of names of elements as a path to the desired node
[in]valuesVector of longs to be converted to character data
Return values
statusReturns 0 if successful

◆ SetElementLong() [4/4]

virtual void VAPoR::XmlNode::SetElementLong ( const vector< string > &  tags,
long  value 
)
inlinevirtual

Definition at line 123 of file XmlNode.h.

◆ SetElementString()

virtual void VAPoR::XmlNode::SetElementString ( const string &  tag,
const string &  values 
)
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

Parameters
[in]tagName of the element to define/set
[in]valuesstring to be converted to character data
Return values
statusReturns a non-negative value on success
statusReturns 0 if successful

◆ SetElementStringVec() [1/2]

virtual void VAPoR::XmlNode::SetElementStringVec ( const string &  tag,
const vector< string > &  values 
)
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)

Parameters
[in]tagName of the element to define/set
[in]valuesVector of strings to be converted to a space-separated list of characters
Return values
statusReturns 0 if successful

◆ SetElementStringVec() [2/2]

virtual void VAPoR::XmlNode::SetElementStringVec ( const vector< string > &  tagpath,
const vector< string > &  values 
)
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)

Parameters
[in]tagpathsequence of tags leading from this to element
[in]valuesVector of strings to be converted to a space-separated list of characters
Return values
statusReturns 0 if successful

◆ SetParent()

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

See also
IsRoot();

◆ SetTag()

void VAPoR::XmlNode::SetTag ( string  tag)
inline

Definition at line 95 of file XmlNode.h.

◆ streamOut()

static ostream & VAPoR::XmlNode::streamOut ( ostream &  os,
const XmlNode node 
)
static

◆ Tag()

string & VAPoR::XmlNode::Tag ( )
inline

Set or get that node's tag (name)

Return values
tagA reference to the node's tag

Definition at line 91 of file XmlNode.h.

Friends And Related Function Documentation

◆ operator<<

ostream & operator<< ( ostream &  s,
const XmlNode node 
)
friend

Write the XML tree, rooted at this node, to a file in XML format.


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