Parasol Planning Library (PPL)
Public Member Functions
XMLNode Class Reference

#include <XMLNode.h>

Public Member Functions

template<>
size_t Read (const std::string &_name, const bool _req, const size_t &_default, const size_t &_min, const size_t &_max, const std::string &_desc)
 
Metadata Accessors
const std::string & Name () const
 Get the XMLNode name. More...
 
const std::string & Filename () const
 Get the XML filename. More...
 
std::string GetPath () const
 Get the directory path containing the XML file. More...
 
Content Accessors
std::string GetText () const
 Get the text between opening and closing tags. More...
 
Attribute Parsing
template<typename T >
Read (const std::string &_name, const bool _req, const T &_default, const T &_min, const T &_max, const std::string &_desc)
 
bool Read (const std::string &_name, const bool _req, const bool _default, const std::string &_desc)
 
std::string Read (const std::string &_name, const bool _req, const char *_default, const std::string &_desc)
 
std::string Read (const std::string &_name, const bool _req, const std::string &_default, const std::string &_desc)
 
Parsing Flow
void Ignore ()
 Ignore unrequested node/attribute errors for this node. More...
 
void WarnAll (const bool _warningsAsErrors=false)
 
std::string Where () const
 

Iteration

typedef std::vector< XMLNode >::iterator iterator
 
iterator begin ()
 Get an iterator to this node's first child. More...
 
iterator end ()
 Get an iterator to this node's last child. More...
 

Construction

 XMLNode (const std::string &_filename, const std::string &_desiredNode)
 
 XMLNode (const std::string &_filename, std::shared_ptr< tinyxml2::XMLDocument > doc, const std::string &_desiredNode)
 

Detailed Description

Wrapper class for XML parsing with TinyXML.

This is a wrapper class for XML handling with TinyXML. It is read only and supports trivial XML parsing.

Member Typedef Documentation

◆ iterator

typedef std::vector<XMLNode>::iterator XMLNode::iterator

Constructor & Destructor Documentation

◆ XMLNode() [1/2]

XMLNode::XMLNode ( const std::string &  _filename,
const std::string &  _desiredNode 
)

Construct an XML node object from an XML file.

Parameters
_filenameXML Filename
_desiredNodeDesired XML Node to make root of tree

Will throw ParseException when _desiredNode cannot be found or _filename is poorly formed input

◆ XMLNode() [2/2]

XMLNode::XMLNode ( const std::string &  _filename,
std::shared_ptr< tinyxml2::XMLDocument >  doc,
const std::string &  _desiredNode 
)

Construct an XML node object from an XML document.

Parameters
_filenameXML Filename (used for error messages)
_desiredNodeDesired XML Node to make root of tree

Will throw ParseException when _desiredNode cannot be found or doc is not valid

Member Function Documentation

◆ begin()

XMLNode::iterator XMLNode::begin ( )

Get an iterator to this node's first child.

◆ end()

XMLNode::iterator XMLNode::end ( )

Get an iterator to this node's last child.

◆ Filename()

const std::string & XMLNode::Filename ( ) const

Get the XML filename.

◆ GetPath()

std::string XMLNode::GetPath ( ) const

Get the directory path containing the XML file.

◆ GetText()

std::string XMLNode::GetText ( ) const

Get the text between opening and closing tags.

◆ Ignore()

void XMLNode::Ignore ( )

Ignore unrequested node/attribute errors for this node.

◆ Name()

const std::string & XMLNode::Name ( ) const

Get the XMLNode name.

◆ Read() [1/5]

bool XMLNode::Read ( const std::string &  _name,
const bool  _req,
const bool  _default,
const std::string &  _desc 
)

Read XML boolean attribute

Parameters
_nameName of attribute
_reqIs attribute required
_defaultDefault value of attribute
_descDescription of attribute
Returns
Value of attribute

Reads XML attribute value with _name. If _req is specified and no attribute is given, _default is returned. Otherwise, an error is reported and _desc is shown to the user.

◆ Read() [2/5]

std::string XMLNode::Read ( const std::string &  _name,
const bool  _req,
const char *  _default,
const std::string &  _desc 
)

Read XML string attribute

Returns
Value of attribute

Calls string version of function to avoid confusion with bool -> const char* conversion in compile.

◆ Read() [3/5]

template<>
size_t XMLNode::Read ( const std::string &  _name,
const bool  _req,
const size_t &  _default,
const size_t &  _min,
const size_t &  _max,
const std::string &  _desc 
)

◆ Read() [4/5]

std::string XMLNode::Read ( const std::string &  _name,
const bool  _req,
const std::string &  _default,
const std::string &  _desc 
)

Read XML string attribute

Parameters
_nameName of attribute
_reqIs attribute required
_defaultDefault value of attribute
_descDescription of attribute
Returns
Value of attribute

Reads XML attribute value with _name. If _req is specified and no attribute is given, _default is returned. Otherwise, an error is reported and _desc is shown to the user.

◆ Read() [5/5]

template<typename T >
T XMLNode::Read ( const std::string &  _name,
const bool  _req,
const T &  _default,
const T &  _min,
const T &  _max,
const std::string &  _desc 
)

Read XML attribute.

Template Parameters
TType of attribute
Parameters
_nameName of attribute
_reqIs attribute required
_defaultDefault value of attribute
_minMinimum value of attribute
_maxMaximum value of attribute
_descDescription of attribute
Returns
Value of attribute

Reads XML attribute value with _name. If _req is specified and no attribute is given, _default is returned, otherwise input value is required to be in the range [_min, _max]. Otherwise, an error is reported and _desc is shown to the user.

◆ WarnAll()

void XMLNode::WarnAll ( const bool  _warningsAsErrors = false)

Report warnings for XML tree rooted at this node

Parameters
_warningsAsErrorsTrue will throw exceptions for warnings

To be called after parsing phase. This will report warnings throughout entire XML document. Should only be called on root XML node. Warnings to be reported:

  • unknown/unparsed nodes
  • unrequested attribues

◆ Where()

std::string XMLNode::Where ( ) const

Generate string describing where the node is

Returns
String representing where node is

To be used with PMPLExceptions, specifically ParseException. Gives string with filename, row (line number), and column of XMLNode.


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