herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
XML::Element Class Reference

Element represents a (tree of) XML elements. More...

#include <Element.h>

Classes

struct  Attribute
 Represent an attribute. More...
 

Public Member Functions

 Element ()
 The default constructor.
 
 Element (int newType, const std::string &newNameOrContent="")
 The standard constructor.
 
 Element (const Element &other)
 The copy constructor.
 
Elementoperator= (const Element &other)
 Assignment.
 
int type () const
 Return the type of this element.
 
const std::string & name () const
 Return the name of this element.
 
const std::string & content () const
 Return the content of this element.
 
std::string & content ()
 Access the content of this element.
 
template<class T >
Elementoperator<< (const T &t)
 Append to the content of this element.
 
bool hasAttributes () const
 Return true, if this element has attributes.
 
bool hasAttribute (const std::string &) const
 Return true, if this element contains an attribute of the given name.
 
const std::map< std::string, std::string > & attributes () const
 Return the attributes.
 
const std::string & attribute (const std::string &) const
 Return the attribute of the given name.
 
std::string & attribute (const std::string &)
 Access the attribute of the given name.
 
Elementoperator<< (const Attribute &)
 Append an attribute to this element.
 
template<class T >
void appendAttribute (const std::string &name, const T &t)
 Append an attribute to this element.
 
template<class T >
void getFromAttribute (const std::string &name, T &t) const
 Get a value from an attribute.
 
bool hasChildren () const
 Return true, if this element has children.
 
const std::list< Element > & children () const
 Return the list of children elements.
 
std::list< Element > & children ()
 Access the list of children elements.
 
Elementappend (const Element &)
 Append a child element to this element.
 
Elementprepend (const Element &)
 Prepend a child element to this element.
 
Elementoperator<< (const Element &)
 Append a child element to this element.
 
void insert (std::list< Element >::iterator, const Element &)
 Insert an element before the given position.
 
void erase (std::list< Element >::iterator)
 Erase an element at the given position.
 
std::list< Element >::const_iterator findFirst (int type, const std::string &name) const
 Find the first element of the given type and name.
 
std::pair< std::multimap< std::pair< int, std::string >, std::list< Element >::iterator >::const_iterator, std::multimap< std::pair< int, std::string >, std::list< Element >::iterator >::const_iterator > findAll (int type, const std::string &name) const
 Find all elements of the given type and name.
 

Private Member Functions

void index ()
 Index elements by type and name.
 
void assertContent () const
 Assert that this element got a character content.
 
void assertNamed () const
 Assert that this element is named.
 
void assertAttributes () const
 Assert that this element contains attributes.
 
void assertChildren () const
 Assert that this element contains children elements.
 

Private Attributes

int theType
 The type of this element.
 
std::string theNameOrContent
 The name or character content of the element.
 
std::map< std::string, std::string > theAttributes
 The attributes of this element.
 
std::list< ElementtheChildren
 The children elements of this element.
 
std::multimap< std::pair< int, std::string >, std::list< Element >::iterator > theIndex
 Index children elements by type and name.
 

Friends

bool operator== (const XML::Element &one, const XML::Element &two)
 Comparison operator.
 
bool operator!= (const XML::Element &one, const XML::Element &two)
 
XML::Element operator+ (const XML::Element &one, const XML::Element &two)
 Combine operator.
 

Detailed Description

Element represents a (tree of) XML elements.

Author
Simon Platzer

Definition at line 56 of file Element.h.

Constructor & Destructor Documentation

◆ Element() [1/2]

XML::Element::Element ( )
inline

The default constructor.

Definition at line 63 of file Element.h.

◆ Element() [2/2]

XML::Element::Element ( int  newType,
const std::string &  newNameOrContent = "" 
)
inlineexplicit

The standard constructor.

Definition at line 69 of file Element.h.

Member Function Documentation

◆ appendAttribute()

template<class T >
void XML::Element::appendAttribute ( const std::string &  name,
const T &  t 
)
inline

Append an attribute to this element.

Definition at line 216 of file Element.h.

References name().

◆ getFromAttribute()

template<class T >
void XML::Element::getFromAttribute ( const std::string &  name,
T &  t 
) const
inline

Get a value from an attribute.

Definition at line 224 of file Element.h.

References attribute(), and name().

◆ hasAttributes()

bool XML::Element::hasAttributes ( ) const
inline

Return true, if this element has attributes.

Definition at line 139 of file Element.h.

References XML::ElementTypes::Element, XML::ElementTypes::EmptyElement, and type().

◆ hasChildren()

bool XML::Element::hasChildren ( ) const
inline

Return true, if this element has children.

Definition at line 234 of file Element.h.

References XML::ElementTypes::Element, XML::ElementTypes::Root, and type().

◆ operator<<()

template<class T >
Element & XML::Element::operator<< ( const T &  t)
inline

Append to the content of this element.

Definition at line 126 of file Element.h.

References assertContent(), and theNameOrContent.

◆ type()

int XML::Element::type ( ) const
inline

Return the type of this element.

Definition at line 103 of file Element.h.

References theType.

Referenced by hasAttributes(), and hasChildren().

Friends And Related Function Documentation

◆ operator+

XML::Element operator+ ( const XML::Element one,
const XML::Element two 
)
friend

Combine operator.

Operator checks if type and name is equal otherwises throws exception

◆ operator==

bool operator== ( const XML::Element one,
const XML::Element two 
)
friend

Comparison operator.

Member Data Documentation

◆ theAttributes

std::map<std::string,std::string> XML::Element::theAttributes
private

The attributes of this element.

Definition at line 303 of file Element.h.

◆ theChildren

std::list<Element> XML::Element::theChildren
private

The children elements of this element.

Definition at line 308 of file Element.h.

◆ theIndex

std::multimap<std::pair<int,std::string>,std::list<Element>::iterator> XML::Element::theIndex
private

Index children elements by type and name.

Definition at line 313 of file Element.h.

◆ theNameOrContent

std::string XML::Element::theNameOrContent
private

The name or character content of the element.

Definition at line 298 of file Element.h.

Referenced by operator<<().

◆ theType

int XML::Element::theType
private

The type of this element.

Definition at line 293 of file Element.h.

Referenced by type().


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