GammaLib
2.0.0
|
XML element node class. More...
#include <GXmlElement.hpp>
Public Member Functions | |
GXmlElement (void) | |
Void constructor. More... | |
GXmlElement (const GXmlElement &node) | |
Copy constructor. More... | |
GXmlElement (const std::string &segment) | |
Segment constructor. More... | |
GXmlElement (const std::string &name, const int &value) | |
Integer value constructor. More... | |
GXmlElement (const std::string &name, const double &value) | |
Floating point value constructor. More... | |
GXmlElement (const std::string &name, const std::string &value) | |
String value constructor. More... | |
virtual | ~GXmlElement (void) |
Destructor. More... | |
GXmlElement & | operator= (const GXmlElement &node) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear XML element. More... | |
virtual GXmlElement * | clone (void) const |
Clone XML element. More... | |
virtual std::string | classname (void) const |
Return class name. More... | |
const std::string & | name (void) const |
Return XML element name. More... | |
void | name (const std::string &name) |
Set XML element name. More... | |
std::string | value (void) const |
Return string value. More... | |
std::string | string (void) const |
Return string value. More... | |
double | real (void) const |
Return floating point value. More... | |
int | integer (void) const |
Return integer value. More... | |
int | attributes (void) const |
Return number of attributes. More... | |
const GXmlAttribute * | attribute (const int &index) const |
Return attribute. More... | |
std::string | attribute (const std::string &name) const |
Return attribute value. More... | |
void | attribute (const std::string &name, const std::string &value) |
Set attribute value. More... | |
bool | has_attribute (const std::string &name) const |
Check if element has a given attribute. More... | |
void | remove_attribute (const std::string &name) |
Remove attribute from element. More... | |
virtual void | write (GUrl &url, const int &indent=0) const |
Write element into URL. More... | |
virtual NodeType | type (void) const |
Return XML node type. More... | |
virtual std::string | print (const GChatter &chatter=NORMAL, const int &indent=0) const |
Print XML element. More... | |
Public Member Functions inherited from GXmlNode | |
GXmlNode (void) | |
Void constructor. More... | |
GXmlNode (const GXmlNode &node) | |
Copy constructor. More... | |
virtual | ~GXmlNode (void) |
Destructor. More... | |
GXmlNode & | operator= (const GXmlNode &node) |
Assignment operator. More... | |
GXmlNode * | operator[] (const int &index) |
Return pointer to XML child node. More... | |
const GXmlNode * | operator[] (const int &index) const |
Return pointer to XML child node (const version) More... | |
virtual int | size (void) const |
Return number of child nodes. More... | |
virtual bool | is_empty (void) const |
Signals if node has no child nodes. More... | |
virtual GXmlNode * | set (const int &index, const GXmlNode &node) |
Set XML child node. More... | |
virtual GXmlNode * | append (const GXmlNode &node) |
Append XML child node. More... | |
virtual GXmlElement * | append (const std::string &segment) |
Append XML element child node. More... | |
virtual GXmlNode * | insert (const int &index, const GXmlNode &node) |
Insert XML child node. More... | |
virtual void | remove (const int &index) |
Remove XML child node. More... | |
virtual void | reserve (const int &num) |
Reserve space for child nodes. More... | |
virtual void | extend (const GXmlNode &node) |
Append all XML child nodes from another XML node. More... | |
GXmlNode * | parent (void) const |
Return parent XML node. More... | |
void | parent (GXmlNode *parent) |
Set parent of XML node. More... | |
GFilename | filename (void) const |
Return filename of XML file. More... | |
virtual int | elements (void) const |
Return number of GXMLElement children of node. More... | |
virtual int | elements (const std::string &name) const |
Return number of GXMLElement children with a given name. More... | |
virtual GXmlElement * | element (const int &index) |
Return pointer to GXMLElement child. More... | |
virtual const GXmlElement * | element (const int &index) const |
Return pointer to GXMLElement child (const variant) More... | |
virtual GXmlElement * | element (const std::string &name) |
Return pointer on child walking down a hierarchy of tags. More... | |
virtual const GXmlElement * | element (const std::string &name) const |
Return pointer on child walking down a hierarchy of tags (const version) More... | |
virtual GXmlElement * | element (const std::string &name, const int &index) |
Return pointer on GXMLElement child of a given name. More... | |
virtual const GXmlElement * | element (const std::string &name, const int &index) const |
Return pointer on GXMLElement child of a given name (const variant) More... | |
virtual std::string | print (const GChatter &chatter=NORMAL) const |
Print XML node in string. More... | |
Public Member Functions inherited from GContainer | |
virtual | ~GContainer (void) |
Destructor. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GXmlElement &node) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | parse_start (const std::string &segment) |
Parse element start segment string. More... | |
void | parse_stop (const std::string &segment) |
Parse element stop segment string. More... | |
void | parse_attribute (size_t *pos, const std::string &segment) |
Parse element attribute. More... | |
Protected Member Functions inherited from GXmlNode | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GXmlNode &node) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
int | extract_index (std::string &tag) const |
Extract index from tag. More... | |
Protected Attributes | |
std::string | m_name |
Element name. More... | |
std::vector< GXmlAttribute * > | m_attr |
Attributes. More... | |
Protected Attributes inherited from GXmlNode | |
GXmlNode * | m_parent |
Pointer on parent node. More... | |
std::vector< GXmlNode * > | m_nodes |
Pointer to child nodes. More... | |
Friends | |
class | GXml |
Additional Inherited Members | |
Public Types inherited from GXmlNode | |
enum | NodeType { NT_DOCUMENT, NT_ELEMENT, NT_COMMENT, NT_UNKNOWN, NT_TEXT, NT_DECLARATION, NT_PI, NT_TYPECOUNT } |
XML element node class.
This class implements an XML element with it's associated attributes.
Definition at line 48 of file GXmlElement.hpp.
GXmlElement::GXmlElement | ( | void | ) |
Void constructor.
Definition at line 65 of file GXmlElement.cpp.
References init_members().
Referenced by clone().
GXmlElement::GXmlElement | ( | const GXmlElement & | node | ) |
Copy constructor.
[in] | node | XML element. |
Definition at line 80 of file GXmlElement.cpp.
References copy_members(), and init_members().
|
explicit |
Segment constructor.
[in] | segment | XML segment. |
Constructs a XML element from a text segment
. The text segment is parsed and the element name and attributes are extracted using the parse_start() method.
Definition at line 102 of file GXmlElement.cpp.
References init_members(), and parse_start().
GXmlElement::GXmlElement | ( | const std::string & | name, |
const int & | value | ||
) |
Integer value constructor.
[in] | name | Element name. |
[in] | value | Integer value. |
Constructs a XML value element of the form
<name>value</name>
Definition at line 125 of file GXmlElement.cpp.
References GXmlNode::append(), init_members(), m_name, name(), and gammalib::str().
GXmlElement::GXmlElement | ( | const std::string & | name, |
const double & | value | ||
) |
Floating point value constructor.
[in] | name | Element name. |
[in] | value | Floating point value. |
Constructs a XML value element of the form
<name>value</name>
Definition at line 152 of file GXmlElement.cpp.
References GXmlNode::append(), init_members(), m_name, name(), and gammalib::str().
GXmlElement::GXmlElement | ( | const std::string & | name, |
const std::string & | value | ||
) |
String value constructor.
[in] | name | Element name. |
[in] | value | String value. |
Constructs a XML value element of the form
<name>value</name>
Definition at line 179 of file GXmlElement.cpp.
References GXmlNode::append(), init_members(), m_name, and name().
|
virtual |
const GXmlAttribute * GXmlElement::attribute | ( | const int & | index | ) | const |
Return attribute.
[in] | index | Attribute index [0,...,attributes()[. |
GException::out_of_range | Index out of range. |
Definition at line 328 of file GXmlElement.cpp.
References attributes(), G_ATTRIBUTE, and m_attr.
Referenced by GCTAModelSpatialRegistry::alloc(), GModelSpectralRegistry::alloc(), GModelTemporalRegistry::alloc(), GModelSpatialRegistry::alloc(), GVOTable::field_from_fits_column(), GModelAssociations::get_association_xml(), GModelAssociation::get_property_xml(), GXml::process_markup(), GLATObservation::read(), GCOMModelDRM::read(), GModelAssociation::read(), GModelSpatialComposite::read(), GCTAModelSpatialMultiplicative::read(), GCTARoi::read(), GSPIObservation::read(), GModelSpectralComposite::read(), GModelSpectralMultiplicative::read(), GCTAPointing::read(), GCTAModelRadialPolynom::read(), GModelSpatialDiffuseMap::read(), GTimeReference::read(), GModelTemporalLightCurve::read(), GCTAModelSpatialLookup::read(), GSPIModelDataSpace::read(), GModelSpectralTable::read(), GModelSpatialDiffuseCube::read(), GModelSpectralFunc::read(), GCTAResponseIrf::read(), GCTAObservation::read(), GGti::read(), GCOMObservation::read(), GCTAResponseCube::read(), GModelPar::read(), GModelTemporalPhaseCurve::read(), GCTAOnOffObservation::read(), GEbounds::read(), GObservations::read(), GModels::read(), GModel::read_attributes(), GModel::read_scales(), GCTAModelSkyCube::read_xml_spatial(), GDaemon::update_countries_data(), GDaemon::update_daily(), GDaemon::update_versions_data(), GLATObservation::write(), GCTAModelSpatialGaussSpectrum::write(), GMWLObservation::write(), GCOMModelDRM::write(), GCTAModelIrfBackground::write(), GModelAssociation::write(), GModelSpatialComposite::write(), GCOMModelDRBPhibarNodes::write(), GCTAModelSpatialMultiplicative::write(), GCOMModelDRBPhibarBins::write(), GCTAModelAeffBackground::write(), GCTARoi::write(), GSPIObservation::write(), GCTAModelCubeBackground::write(), GModelSpectralComposite::write(), GModelSpectralMultiplicative::write(), GCTAModelRadialAcceptance::write(), GCTAPointing::write(), GModelSpatialDiffuseMap::write(), GTimeReference::write(), GCTAModelBackground::write(), GModelTemporalLightCurve::write(), GCTAModelSpatialLookup::write(), GSPIModelDataSpace::write(), GCTAModelSkyCube::write(), GModelSpectralTable::write(), GModelSpatialDiffuseCube::write(), GModelSpectralFunc::write(), GCTAResponseIrf::write(), GCTAObservation::write(), GTestSuites::write(), GGti::write(), GCOMObservation::write(), GCTAResponseCube::write(), GModelPar::write(), GModelTemporalPhaseCurve::write(), GCTAOnOffObservation::write(), GEbounds::write(), GObservations::write(), GModelSky::write(), GModel::write_attributes(), GModel::write_scales(), GCTAModelSkyCube::write_xml_spatial(), gammalib::xml_check_type(), gammalib::xml_get_attr(), gammalib::xml_get_par(), gammalib::xml_has_par(), gammalib::xml_need_par(), and GCTAModelRadialAcceptance::xml_radial().
std::string GXmlElement::attribute | ( | const std::string & | name | ) | const |
Return attribute value.
[in] | name | Attribute name. |
Returns the value of the attribute name
. If the requested attribute was not found an empty string is returned.
Definition at line 352 of file GXmlElement.cpp.
void GXmlElement::attribute | ( | const std::string & | name, |
const std::string & | value | ||
) |
Set attribute value.
[in] | name | Attribute name. |
[in] | value | Attribute value. |
Sets an attribute of the element. If the attribute name exists the value is modified. If the attribute does not yet exist it is created and added to the list of attributes.
Note that this logical assures that only one attribute with a given name will exist in the element.
Definition at line 383 of file GXmlElement.cpp.
References m_attr, name(), GXmlAttribute::name(), and GXmlAttribute::value().
|
inline |
Return number of attributes.
Definition at line 194 of file GXmlElement.hpp.
References m_attr.
Referenced by attribute().
|
inlinevirtual |
Return class name.
Implements GXmlNode.
Definition at line 109 of file GXmlElement.hpp.
|
virtual |
Clear XML element.
Resets the XML element to a clean initial state.
Implements GXmlNode.
Definition at line 256 of file GXmlElement.cpp.
References free_members(), GXmlNode::free_members(), init_members(), and GXmlNode::init_members().
|
virtual |
Clone XML element.
Implements GXmlNode.
Definition at line 276 of file GXmlElement.cpp.
References GXmlElement().
|
protected |
Copy class members.
[in] | node | XML element. |
This method copies all class members. XML attributes are cloned.
Definition at line 610 of file GXmlElement.cpp.
References m_attr, and m_name.
Referenced by GXmlElement(), and operator=().
|
protected |
Delete class members.
As container classes that hold pointers need to handle themselves the proper deallocation of memory, we loop here over all pointers and make sure that we deallocate the associated nodes.
Definition at line 633 of file GXmlElement.cpp.
References m_attr.
Referenced by clear(), operator=(), and ~GXmlElement().
bool GXmlElement::has_attribute | ( | const std::string & | name | ) | const |
Check if element has a given attribute.
[in] | name | Attribute name. |
Checks whether the element contains an attribute with name
. If the attribute was found true is returned, false otherwise.
Definition at line 421 of file GXmlElement.cpp.
References m_attr, and name().
Referenced by GModelSpatialComposite::read(), GCTARoi::read(), GSPIObservation::read(), GCTAPointing::read(), GModelSpatialDiffuseMap::read(), GTimeReference::read(), GCTAResponseIrf::read(), GGti::read(), GCOMObservation::read(), GModelTemporalPhaseCurve::read(), GEbounds::read(), GModel::read_attributes(), GDaemon::update_countries_data(), GDaemon::update_daily(), GDaemon::update_versions_data(), GModelSpatialComposite::write(), and gammalib::xml_get_attr().
|
protected |
Initialise class members.
Definition at line 592 of file GXmlElement.cpp.
References m_attr, and m_name.
Referenced by clear(), GXmlElement(), and operator=().
|
inline |
Return integer value.
Definition at line 170 of file GXmlElement.hpp.
References gammalib::toint(), and value().
|
inline |
Return XML element name.
Definition at line 121 of file GXmlElement.hpp.
References m_name.
Referenced by attribute(), GXmlNode::element(), GXmlElement(), has_attribute(), name(), GXml::parse(), parse_attribute(), parse_stop(), remove_attribute(), GDaemon::update_countries_data(), GDaemon::update_daily(), GDaemon::update_versions_data(), and GTestSuites::write().
|
inline |
Set XML element name.
[in] | name | XML element name. |
Definition at line 133 of file GXmlElement.hpp.
GXmlElement & GXmlElement::operator= | ( | const GXmlElement & | node | ) |
Assignment operator.
[in] | node | XML element. |
Definition at line 221 of file GXmlElement.cpp.
References copy_members(), free_members(), init_members(), and GXmlNode::operator=().
|
protected |
Parse element attribute.
[in] | pos | Start position in string. |
[in] | segment | Segment string. |
GException::invalid_value | XML syntax error. |
Parse the segment string for one attribute, and if attribute was found, attach it to element.
Definition at line 786 of file GXmlElement.cpp.
References G_PARSE_ATTRIBUTE, m_attr, name(), and value().
Referenced by parse_start(), and GXml::process_markup().
|
protected |
Parse element start segment string.
[in] | segment | Segment string. |
GException::xml_syntax_error | XML syntax error. |
Parse the segment string and set class members based on the information that is found. The method also performs syntax checking. It does not require brackets to be set.
Definition at line 658 of file GXmlElement.cpp.
References G_PARSE_START, m_name, and parse_attribute().
Referenced by GXmlElement().
|
protected |
Parse element stop segment string.
[in] | segment | Segment string. |
GException::xml_syntax_error | XML syntax error. |
Parse the stop segment string and verify the syntax.
Definition at line 723 of file GXmlElement.cpp.
References G_PARSE_STOP, m_name, and name().
Referenced by GXml::process_markup().
|
virtual |
Print XML element.
[in] | chatter | Chattiness. |
[in] | indent | Text indentation. |
Implements GXmlNode.
Definition at line 553 of file GXmlElement.cpp.
References gammalib::fill(), g_indent, m_attr, m_name, GXmlNode::m_nodes, and SILENT.
Referenced by GModelPar::read().
|
inline |
Return floating point value.
Definition at line 158 of file GXmlElement.hpp.
References gammalib::todouble(), and value().
void GXmlElement::remove_attribute | ( | const std::string & | name | ) |
Remove attribute from element.
[in] | name | Attribute name. |
Remove the attribute with name
from the XML element. If the requested attribute was not found the method does nothing.
Definition at line 447 of file GXmlElement.cpp.
|
inline |
Return string value.
Definition at line 146 of file GXmlElement.hpp.
References value().
|
inlinevirtual |
Return XML node type.
Implements GXmlNode.
Definition at line 182 of file GXmlElement.hpp.
References GXmlNode::NT_ELEMENT.
Referenced by write().
std::string GXmlElement::value | ( | void | ) | const |
Return string value.
GException::invalid_value | Element does not contain a single text element. |
Returns the string value of the text element in case that the element contains one text element. An exception is returned in case that the element does not contain a text element.
Definition at line 295 of file GXmlElement.cpp.
References G_VALUE, GXmlNode::size(), gammalib::str(), and GXmlText::text().
Referenced by attribute(), integer(), parse_attribute(), real(), string(), GDaemon::update_countries_header(), and GDaemon::update_daily().
|
virtual |
Write element into URL.
[in] | url | Unified Resource Locator. |
[in] | indent | Text indentation. |
Writes the element into a Unified Resource Locator.
Implements GXmlNode.
Definition at line 481 of file GXmlElement.cpp.
References g_indent, GXmlNode::is_empty(), m_attr, m_name, GXmlNode::m_nodes, GXmlNode::NT_TEXT, GUrl::printf(), and type().
|
friend |
Definition at line 51 of file GXmlElement.hpp.
|
protected |
Attributes.
Definition at line 99 of file GXmlElement.hpp.
Referenced by attribute(), attributes(), copy_members(), free_members(), has_attribute(), init_members(), parse_attribute(), print(), remove_attribute(), and write().
|
protected |
Element name.
Definition at line 98 of file GXmlElement.hpp.
Referenced by copy_members(), GXmlElement(), init_members(), name(), parse_start(), parse_stop(), print(), and write().