VAPoR  0.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
VAPoR::XmlNode Class Reference

An Xml tree. More...

#include <XmlNode.h>

Inheritance diagram for VAPoR::XmlNode:
VetsUtil::MyBase VAPoR::ParamNode

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 XmlNodeConstruct (const string &tag, const map< string, string > &attrs, size_t numChildrenHint=0)
 
 XmlNode (const XmlNode &node)
 
virtual XmlNodeClone ()
 
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 XmlNodeNewChild (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 XmlNodeGetChild (size_t index) const
 
virtual XmlNodeGetParent ()
 
virtual int HasChild (size_t index)
 
virtual XmlNodeGetChild (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)
 

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

Definition at line 47 of file XmlNode.h.

Member Enumeration Documentation

Enumerator
ERR_DEF 
ERR_TNP 

Definition at line 49 of file XmlNode.h.

Constructor & Destructor Documentation

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
VAPoR::XmlNode::XmlNode ( const string &  tag,
size_t  numChildrenHint = 0 
)
VAPoR::XmlNode::XmlNode ( )
inline

Definition at line 73 of file XmlNode.h.

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

Copy constructor for the XmlNode class.

Create's a new XmlNode node from an existing one.

Parameters
[in]nodeXmlNode instance from which to construct a copy
virtual VAPoR::XmlNode::~XmlNode ( )
virtual

Member Function Documentation

virtual void VAPoR::XmlNode::AddChild ( XmlNode child)
virtual

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 appended to the array of child nodes.

Note
The node is shallow copied into the tree (only the pointer is copied. Furthermore, the destructor for this class will delete the added child. Whoops!!
Parameters
[in]childis the XmlNode object to be added as a child
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.

virtual void VAPoR::XmlNode::ClearChildren ( )
inlinevirtual

Clear the children, but don't delete them.

Definition at line 363 of file XmlNode.h.

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

Definition at line 87 of file XmlNode.h.

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

Reimplemented in VAPoR::ParamNode.

Definition at line 74 of file XmlNode.h.

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

Recursively delete all descendants of a node.

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()
virtual int VAPoR::XmlNode::DeleteChild ( const string &  tag)
virtual
virtual bool& VAPoR::XmlNode::ErrOnMissing ( )
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.

Return values
flagA reference to the Error on Missing flag

Definition at line 426 of file XmlNode.h.

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
See also
GetNumChildren()

Reimplemented in VAPoR::ParamNode.

Referenced by VAPoR::ParamNode::GetChild(), and VAPoR::ParamNode::GetNode().

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
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. If ErrOnMissing() is true an error is generated if the element is missing;

Parameters
[in]tagName of element
Return values
vectorVector of doubles associated with the named elemented
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. If ErrOnMissing() is true an error is generated if the element is missing;

Parameters
[in]tagName of element
Return values
vectorVector of longs associated with the named elemented
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. If ErrOnMissing() is true an error is generated if the element is missing;

Parameters
[in]tagName of element
Return values
stringThe string associated with the named element
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
virtual int VAPoR::XmlNode::GetNumChildren ( ) const
inlinevirtual

Definition at line 323 of file XmlNode.h.

virtual XmlNode* VAPoR::XmlNode::GetParent ( )
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 397 of file XmlNode.h.

virtual int VAPoR::XmlNode::HasChild ( size_t  index)
virtual

Return true if the indicated child node exists

Parameters
[in]indexIndex of the child. The first child is zero
Return values
bool
virtual int VAPoR::XmlNode::HasChild ( const string &  tag)
virtual

Return true if the indicated child node exists

Parameters
[in]tagName of the child node
Return values
bool
virtual int 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
virtual int 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
virtual int 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
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
static string VAPoR::XmlNode::replaceAll ( const string &  sourceString,
const char *  input,
const char *  output 
)
static
virtual int VAPoR::XmlNode::ReplaceChild ( XmlNode childNode,
XmlNode newChild 
)
virtual

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.

Parameters
[in]childNodePointer to existing child node
[in]newChildPointer to replacement child node
Return values
statusReturns non-negative child index on success
virtual int 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

Reimplemented in VAPoR::ParamNode.

virtual int 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

Reimplemented in VAPoR::ParamNode.

virtual int 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

Reimplemented in VAPoR::ParamNode.

virtual int 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

Reimplemented in VAPoR::ParamNode.

virtual int 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

Reimplemented in VAPoR::ParamNode.

virtual int 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

Reimplemented in VAPoR::ParamNode.

virtual int 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

Reimplemented in VAPoR::ParamNode.

static ostream& VAPoR::XmlNode::streamOut ( ostream &  os,
const XmlNode node 
)
static
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 95 of file XmlNode.h.

Friends And Related Function Documentation

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

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

Member Data Documentation

map<string, vector<double> > VAPoR::XmlNode::_doublemap
protected

Definition at line 456 of file XmlNode.h.

vector<double> VAPoR::XmlNode::_emptyDoubleVec
static

Definition at line 449 of file XmlNode.h.

vector<long> VAPoR::XmlNode::_emptyLongVec
static

Definition at line 448 of file XmlNode.h.

string VAPoR::XmlNode::_emptyString
static

Definition at line 451 of file XmlNode.h.

vector<string> VAPoR::XmlNode::_emptyStringVec
static

Definition at line 450 of file XmlNode.h.

bool VAPoR::XmlNode::_errOnMissing
protected

Definition at line 458 of file XmlNode.h.

map<string, vector<long> > VAPoR::XmlNode::_longmap
protected

Definition at line 455 of file XmlNode.h.

map<string, string> VAPoR::XmlNode::_stringmap
protected

Definition at line 457 of file XmlNode.h.


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