UQTk: Uncertainty Quantification Toolkit  3.1.1
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
XMLElement Class Reference

#include <XMLElement.h>

Inheritance diagram for XMLElement:
Object

Public Member Functions

 XMLElement (const std::string &)
 Construct a new xml element object and give it a label. More...
 
virtual ~XMLElement ()
 Destructor. More...
 
const std::string & label () const
 Get the label of this node. More...
 
void set_label (const std::string &)
 Assign a new label to this node. More...
 
int count_attributes () const
 
RefPtr< XMLAttributeListattributes ()
 Get access to the attribute list. More...
 
void set_attributes (RefPtr< XMLAttributeList >)
 Assign an attribute list to this element. More...
 
int count_children () const
 Utility function to check how many children this element has. More...
 
RefPtr< XMLElementget_child (int)
 
RefPtr< XMLElementget_child (const std::string &)
 
void add_child (RefPtr< XMLElement >)
 
void add_child_rpt (RefPtr< XMLElement >)
 Same as add_child, but this allows for repeating children. More...
 
void clear_children ()
 Erase all child elements from this node. More...
 
int count_content () const
 
const std::string & get_content_line (int)
 
void add_content_line (const std::string &)
 Add a line of content. More...
 
void clear_content ()
 Clear all text content. More...
 
- Public Member Functions inherited from Object
 Object ()
 Construct a new reference counted object with a zero reference count. More...
 
virtual ~Object ()
 Destroy this object. More...
 
long int reference_count () const
 Returns the number of references that are held to this object. More...
 

Private Member Functions

 XMLElement (const XMLElement &)
 
XMLElementoperator= (const XMLElement &)
 
void recurse (RefPtr< XMLElement >, std::set< RefPtr< XMLElement > >)
 

Private Attributes

std::string label_
 The iterator type returned for list of children. More...
 
RefPtr< XMLAttributeListattributes_
 The list of attributes associated with this element. More...
 
std::vector< RefPtr< XMLElement > > children_
 The list of children associated with this element. More...
 
std::vector< std::string > content_
 The list of content associated with this element. More...
 

Friends

template<class T >
class RefPtr
 
template<class T >
class ConstRefPtr
 

Additional Inherited Members

- Protected Member Functions inherited from Object
long int reference_grab () const
 
long int reference_release () const
 

Detailed Description

This is the implementation of a node in an XML parse tree. Each node contains the following three containers, any (or all) of which may be empty.

attributes (XMLAttributeList): Contains attributes (key/value pairs). children (Vector<XMLElement>): Contains children of this node. content (Vector<std::string>): Contains content (text) data.

The implementation is very limited. In particular, the following advanced features are missing:

encoding: Support for character types other than char/std::string. comments: Allowing comment blocks to accompany each element. other xml types (control statements, etc.).

This implementation is heavily based on Kevin Long's XMLObject.

Constructor & Destructor Documentation

◆ XMLElement() [1/2]

XMLElement::XMLElement ( const std::string &  lbl)

Construct a new xml element object and give it a label.

◆ XMLElement() [2/2]

XMLElement::XMLElement ( const XMLElement )
private

Blocked copy constructor.

Exceptions
MyException.

◆ ~XMLElement()

XMLElement::~XMLElement ( )
virtual

Destructor.

Member Function Documentation

◆ add_child()

void XMLElement::add_child ( RefPtr< XMLElement kid)

Add a child to the back of the list. Ignored if the child is already in the list.

Exceptions
MyExceptionif adding the child would result in a cyclic relationship.
MyExceptionif the child holds a NULL pointer.

◆ add_child_rpt()

void XMLElement::add_child_rpt ( RefPtr< XMLElement kid)

Same as add_child, but this allows for repeating children.

◆ add_content_line()

void XMLElement::add_content_line ( const std::string &  text)

Add a line of content.

◆ attributes()

RefPtr< XMLAttributeList > XMLElement::attributes ( )

Get access to the attribute list.

◆ clear_children()

void XMLElement::clear_children ( )

Erase all child elements from this node.

◆ clear_content()

void XMLElement::clear_content ( )

Clear all text content.

◆ count_attributes()

int XMLElement::count_attributes ( ) const

Utility function to check how many attributes this element has. This amounts to the same as calling '.attributes().size()'

◆ count_children()

int XMLElement::count_children ( ) const

Utility function to check how many children this element has.

◆ count_content()

int XMLElement::count_content ( ) const

Utility function to check how many lines of text content are associated with this element.

◆ get_child() [1/2]

RefPtr< XMLElement > XMLElement::get_child ( const std::string &  lbl)

Find the first instance of a child with a given label and return a pointer to it.

Note
Since child labels do not need to be unique, there may be multiple instances matching children
Exceptions
MyExceptionif the child label can not be found
Todo:
Make this more elegant with the STL find_if function

◆ get_child() [2/2]

RefPtr< XMLElement > XMLElement::get_child ( int  index)

Get the child with the given index.

Exceptions
MyExceptionif the index is invalid.

◆ get_content_line()

const std::string & XMLElement::get_content_line ( int  index)

Get a line of content by index.

Exceptions
MyExceptionif the index is out of range.

◆ label()

const std::string & XMLElement::label ( ) const

Get the label of this node.

◆ operator=()

XMLElement & XMLElement::operator= ( const XMLElement )
private

Blocked assignment operator.

Exceptions
MyExcepiton.

◆ recurse()

void XMLElement::recurse ( RefPtr< XMLElement kid,
std::set< RefPtr< XMLElement > >  seen 
)
private

A private routine called recursively to ensure that we don't have a cyclic relationship.

◆ set_attributes()

void XMLElement::set_attributes ( RefPtr< XMLAttributeList att)

Assign an attribute list to this element.

◆ set_label()

void XMLElement::set_label ( const std::string &  lbl)

Assign a new label to this node.

Friends And Related Function Documentation

◆ ConstRefPtr

template<class T >
friend class ConstRefPtr
friend

◆ RefPtr

template<class T >
friend class RefPtr
friend

Member Data Documentation

◆ attributes_

RefPtr<XMLAttributeList> XMLElement::attributes_
private

The list of attributes associated with this element.

◆ children_

std::vector< RefPtr<XMLElement> > XMLElement::children_
private

The list of children associated with this element.

◆ content_

std::vector<std::string> XMLElement::content_
private

The list of content associated with this element.

◆ label_

std::string XMLElement::label_
private

The iterator type returned for list of children.

The label of this element.


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