GammaLib
2.1.0.dev
|
Abstract XML node base class. More...
#include <GXmlNode.hpp>
Public Types | |
enum | NodeType { NT_DOCUMENT, NT_ELEMENT, NT_COMMENT, NT_UNKNOWN, NT_TEXT, NT_DECLARATION, NT_PI, NT_TYPECOUNT } |
Public Member Functions | |
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 void | clear (void)=0 |
Clear object. More... | |
virtual GXmlNode * | clone (void) const =0 |
Clones object. More... | |
virtual std::string | classname (void) const =0 |
Return class name. 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 void | write (GUrl &url, const int &indent) const =0 |
virtual NodeType | type (void) const =0 |
virtual std::string | print (const GChatter &chatter=NORMAL, const int &indent=0) const =0 |
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 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 | |
GXmlNode * | m_parent |
Pointer on parent node. More... | |
std::vector< GXmlNode * > | m_nodes |
Pointer to child nodes. More... | |
Abstract XML node base class.
This class defines the interface for all XML nodes. Each XML node can be the container for a number of child nodes. The GXmlNode class is thus designed as a container class that holds a list of pointers of type GXmlNode. This allows implementing an arbitrary complex tree structure.
The only member of this class is a list of XML node pointers. GXmlNode handles the proper allocation and deallocation of the node memory.
Most methods are identical to those of the GXml class. Please refer to the documentation of this class for a description of the methods.
Definition at line 57 of file GXmlNode.hpp.
enum GXmlNode::NodeType |
Enumerator | |
---|---|
NT_DOCUMENT | |
NT_ELEMENT | |
NT_COMMENT | |
NT_UNKNOWN | |
NT_TEXT | |
NT_DECLARATION | |
NT_PI | |
NT_TYPECOUNT |
Definition at line 71 of file GXmlNode.hpp.
GXmlNode::GXmlNode | ( | void | ) |
GXmlNode::GXmlNode | ( | const GXmlNode & | node | ) |
Copy constructor.
[in] | node | XML node. |
Definition at line 80 of file GXmlNode.cpp.
References copy_members(), and init_members().
|
virtual |
Append XML child node.
[in] | node | XML child node. |
GException::invalid_argument | Not allowed to append root node. |
GException::invalid_value | Not allowed to append to a text, comment or PI node. |
Appends XML child node by making a deep copy of the node and storing its pointer.
Definition at line 287 of file GXmlNode.cpp.
References clone(), G_APPEND2, m_nodes, NT_COMMENT, NT_DOCUMENT, NT_PI, NT_TEXT, and type().
Referenced by GXml::append(), GDaemon::create_xml(), GVOTable::data_from_fits_table(), GModelAssociations::get_association_xml(), GVOHub::get_callback_url(), GModelAssociation::get_property_xml(), GXmlElement::GXmlElement(), GXml::process_markup(), GVOTable::read(), GModels::save(), GDaemon::update_countries_data(), GDaemon::update_countries_header(), GDaemon::update_daily(), GDaemon::update_dates(), GDaemon::update_versions_data(), GLATObservation::write(), GCTAModelSpatialGaussSpectrum::write(), GCOMModelDRM::write(), GCTAModelIrfBackground::write(), GModelSpatialComposite::write(), GCOMModelDRBPhibarNodes::write(), GCTAModelAeffBackground::write(), GCOMModelDRBPhibarBins::write(), GCTAModelSpatialMultiplicative::write(), GModelAssociations::write(), GModelSpectralComposite::write(), GCTAModelCubeBackground::write(), GCTAModelRadialAcceptance::write(), GModelSpectralMultiplicative::write(), GModelSpectralExponential::write(), GCTAModelBackground::write(), GModelSpectralBins::write(), GCTAModelSkyCube::write(), GSPIModelDataSpace::write(), GTestSuites::write(), GCOMObservation::write(), GModelSpectralNodes::write(), GObservations::write(), GModelSky::write(), GModel::write_scales(), and gammalib::xml_need_par().
|
virtual |
Append XML element child node.
[in] | segment | XML child node. |
GException::invalid_value | Not allowed to append to a text, comment or PI node. |
Appends XML element that is constructed from a text segment
. The text segment is parsed and the element name and attributes are extracted using the GXmlElement::parse_start() method. The method returns a pointer to the XML element child node that has been appended.
Definition at line 349 of file GXmlNode.cpp.
References G_APPEND1, m_nodes, NT_COMMENT, NT_PI, NT_TEXT, and type().
|
pure virtual |
Return class name.
Returns the class name for non-abstract classes in a human readable way.
Implements GBase.
Implemented in GXmlDocument, GXmlElement, GXmlComment, GXmlPI, and GXmlText.
|
pure virtual |
Clear object.
Sets the object to a clean initial state. After calling the method the object will be in the same state as it were if an empty instance of the object would have been created.
Implements GBase.
Implemented in GXmlDocument, GXmlElement, GXmlComment, GXmlPI, and GXmlText.
|
pure virtual |
Clones object.
Creates a deep copy of the object and returns a pointer to the object.
Implements GBase.
Implemented in GXmlDocument, GXmlElement, GXmlComment, GXmlPI, and GXmlText.
|
protected |
Copy class members.
[in] | node | XML node. |
Definition at line 898 of file GXmlNode.cpp.
References m_nodes, and m_parent.
Referenced by GXmlNode(), and operator=().
|
virtual |
Return pointer to GXMLElement child.
[in] | index | Node index [0,...,elements()-1]. |
GException::out_of_range | Child element index is out of range. |
Returns a pointer to the child number index
of the XML node. An exception will be thrown if the index
is not valid.
Definition at line 640 of file GXmlNode.cpp.
Referenced by element(), GXml::element(), GModelAssociations::get_association_xml(), GModelAssociation::get_property_xml(), GVOClient::get_response_value(), GVOHub::get_response_value(), GVOHub::get_subscriptions(), GModelSky::GModelSky(), GLATObservation::read(), GCTAModelSpatialGaussSpectrum::read(), GModelAssociation::read(), GCTAModelIrfBackground::read(), GModelSpatialComposite::read(), GCTAModelAeffBackground::read(), GCTAModelSpatialMultiplicative::read(), GCOMModelDRBPhibarBins::read(), GCOMModelDRBPhibarNodes::read(), GModelAssociations::read(), GModelSpectralComposite::read(), GCTAModelCubeBackground::read(), GCTAModelRadialAcceptance::read(), GModelSpectralMultiplicative::read(), GCTAModelRadialPolynom::read(), GModelSpectralExponential::read(), GCTAModelBackground::read(), GModelSpectralBins::read(), GCTAModelSkyCube::read(), GSPIModelDataSpace::read(), GCTAObservation::read(), GCOMObservation::read(), GModelSpectralNodes::read(), GObservations::read(), GModelSky::read(), GModels::read(), GModel::read_scales(), GVOClient::response_error_code(), GVOClient::response_error_message(), GModels::save(), GDaemon::update_countries_data(), GDaemon::update_countries_header(), GDaemon::update_daily(), GDaemon::update_dates(), GDaemon::update_versions_data(), GLATObservation::write(), GCTAModelSpatialGaussSpectrum::write(), GCOMModelDRM::write(), GCTAModelIrfBackground::write(), GModelSpatialComposite::write(), GCOMModelDRBPhibarNodes::write(), GCTAModelAeffBackground::write(), GCTAModelSpatialMultiplicative::write(), GCOMModelDRBPhibarBins::write(), GModelAssociations::write(), GCTAModelCubeBackground::write(), GModelSpectralComposite::write(), GModelSpectralMultiplicative::write(), GCTAModelRadialAcceptance::write(), GModelSpectralExponential::write(), GCTAModelBackground::write(), GModelSpectralBins::write(), GSPIModelDataSpace::write(), GCTAModelSkyCube::write(), GCOMObservation::write(), GModelSpectralNodes::write(), GModelSky::write(), GModel::write_scales(), gammalib::xml_get_name_value_pair(), gammalib::xml_get_par(), gammalib::xml_has_par(), and gammalib::xml_need_par().
|
virtual |
Return pointer to GXMLElement child (const variant)
[in] | index | Node index [0,...,elements()[. |
GException::out_of_range | Child element index is out of range. |
Returns a pointer to the child number index
of the XML node. An exception will be thrown if the index
is not valid.
Definition at line 659 of file GXmlNode.cpp.
References element(), elements(), G_ELEMENT1, m_nodes, NT_ELEMENT, and type().
|
virtual |
Return pointer on child walking down a hierarchy of tags.
[in] | name | Child element hierarchy. |
GException::invalid_argument | Hierarchy string invalid. |
Returns a pointer to the child element described by a hierarchy of the following syntax
params > param[1] > value > struct
The > symbols indicate subsequent hierarchy levels, the square brackets provides the index in case that multiple tags with the same name exist at a given hierarchy level. Omitting the index means that the first tag with the specified name is accessed.
If the specified element does not exist the method returns a NULL pointer.
Definition at line 707 of file GXmlNode.cpp.
References element().
|
virtual |
Return pointer on child walking down a hierarchy of tags (const version)
[in] | name | Child element hierarchy. |
GException::invalid_argument | Hierarchy string invalid. |
Returns a pointer to the child element described by a hierarchy of the following syntax
params > param[1] > value > struct
The > symbols indicate subsequent hierarchy levels, the square brackets provides the index in case that multiple tags with the same name exist at a given hierarchy level. Omitting the index means that the first tag with the specified name is accessed.
If the specified element does not exist the method returns a NULL pointer.
Definition at line 736 of file GXmlNode.cpp.
References element(), elements(), extract_index(), gammalib::split(), and gammalib::strip_whitespace().
|
virtual |
Return pointer on GXMLElement child of a given name.
[in] | name | Name of child element. |
[in] | index | Node index [0,...,elements(name)[. |
GException::xml_name_not_found | Child element name not found. |
GException::out_of_range | Child element index is out of range. |
Returns a pointer to the child number index
with name
of the XML node. An exception will be thrown if the index
is not valid.
Definition at line 791 of file GXmlNode.cpp.
References element().
|
virtual |
Return pointer on GXMLElement child of a given name (const variant)
[in] | name | Name of child element. |
[in] | index | Node index [0,...,elements(name)[. |
GException::invalid_value | Child element name not found. |
GException::out_of_range | Child element index is out of range. |
Returns a pointer to the child number index
with name
of the XML node. An exception will be thrown if the index
is not valid.
Definition at line 813 of file GXmlNode.cpp.
References element(), elements(), G_ELEMENT3, m_nodes, GXmlElement::name(), NT_ELEMENT, and type().
|
virtual |
Return number of GXMLElement children of node.
Returns the number of GXMLElement child elements of the XML node. GXMLElement child elements are nodes of type NT_ELEMENT.
Definition at line 586 of file GXmlNode.cpp.
References m_nodes, NT_ELEMENT, and type().
Referenced by element(), elements(), GXml::elements(), GModelAssociations::get_association_xml(), GModelAssociation::get_property_xml(), GVOClient::get_response_value(), GVOHub::get_response_value(), GVOHub::get_subscriptions(), GLATObservation::read(), GModelAssociation::read(), GCTAModelIrfBackground::read(), GModelSpatialComposite::read(), GCTAModelAeffBackground::read(), GCOMModelDRBPhibarNodes::read(), GCTAModelSpatialMultiplicative::read(), GCOMModelDRBPhibarBins::read(), GModelAssociations::read(), GModelSpectralComposite::read(), GCTAModelCubeBackground::read(), GCTAModelRadialAcceptance::read(), GModelSpectralMultiplicative::read(), GCTAModelRadialPolynom::read(), GModelSpectralExponential::read(), GCTAModelBackground::read(), GModelSpectralBins::read(), GCTAModelSkyCube::read(), GSPIModelDataSpace::read(), GCTAObservation::read(), GCOMObservation::read(), GModelSpectralNodes::read(), GObservations::read(), GModelSky::read(), GModels::read(), GModel::read_scales(), GDaemon::update_countries_data(), GDaemon::update_countries_header(), GDaemon::update_daily(), GDaemon::update_versions_data(), GLATObservation::write(), GCTAModelSpatialGaussSpectrum::write(), GCOMModelDRM::write(), GCTAModelIrfBackground::write(), GModelSpatialComposite::write(), GCOMModelDRBPhibarNodes::write(), GCTAModelAeffBackground::write(), GCOMModelDRBPhibarBins::write(), GCTAModelSpatialMultiplicative::write(), GModelAssociations::write(), GModelSpectralComposite::write(), GCTAModelCubeBackground::write(), GModelSpectralMultiplicative::write(), GCTAModelRadialAcceptance::write(), GCTAModelBackground::write(), GModelSpectralBins::write(), GCTAModelSkyCube::write(), GSPIModelDataSpace::write(), GCOMObservation::write(), GModelSpectralNodes::write(), GModelSky::write(), GModel::write_scales(), gammalib::xml_check_parnum(), gammalib::xml_get_par(), gammalib::xml_has_par(), and gammalib::xml_need_par().
|
virtual |
Return number of GXMLElement children with a given name.
[in] | name | Name of GXMLElement elements. |
name
.Returns the number of GXMLElement child elements of the XML node that have a given name
. GXMLElement child elements are nodes of type NT_ELEMENT.
Definition at line 611 of file GXmlNode.cpp.
References elements(), m_nodes, NT_ELEMENT, and type().
|
virtual |
Append all XML child nodes from another XML node.
[in] | node | XML node. |
Append all XML child nodes found in node
to the actual object. Nodes are copied deeply so that they live now on their on in the actual object.
Definition at line 510 of file GXmlNode.cpp.
References clone(), is_empty(), m_nodes, reserve(), and size().
Referenced by GXml::extend().
|
protected |
Extract index from tag.
[in,out] | tag | Tag. |
GException::invalid_argument | Tag string invalid. |
Extracts the index from a tag string of the following syntax
param[1]
The value within the squared brackets provides the index of the element. If the squared brackets are omitted, an index of 0 will be returned.
Definition at line 950 of file GXmlNode.cpp.
References G_EXTRACT_INDEX, and gammalib::toint().
Referenced by element().
GFilename GXmlNode::filename | ( | void | ) | const |
Return filename of XML file.
Returns the file name of the XML file by moving up the XML file hierarchy to the root. In case that the XML node cannot move up to the root XML node an empty file name is returned (this may happen if the XML node is an orphan node). The file name will also be empty if the XML file has not been read from disk or written to disk.
Definition at line 546 of file GXmlNode.cpp.
References GXmlDocument::filename(), and parent().
Referenced by gammalib::xml_file_expand(), and gammalib::xml_file_reduce().
|
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 921 of file GXmlNode.cpp.
References m_nodes.
Referenced by GXmlPI::clear(), GXmlText::clear(), GXmlComment::clear(), GXmlDocument::clear(), GXmlElement::clear(), operator=(), and ~GXmlNode().
|
protected |
Initialise class members.
Definition at line 880 of file GXmlNode.cpp.
References m_nodes, and m_parent.
Referenced by GXmlPI::clear(), GXmlText::clear(), GXmlComment::clear(), GXmlDocument::clear(), GXmlElement::clear(), GXmlNode(), and operator=().
Insert XML child node.
[in] | index | Child node index [0,...,size()[. |
[in] | node | XML child node. |
GException::invalid_argument | Not allowed to append root node. |
GException::invalid_value | Not allowed to append to a text, comment or PI node. |
GException::out_of_range | Child node index is out of range. |
Inserts the XML child node
before the node with the specified index
. A deep copy of the node will be made and the pointer to this node will be stored.
Definition at line 407 of file GXmlNode.cpp.
References clone(), G_INSERT, is_empty(), m_nodes, NT_COMMENT, NT_DOCUMENT, NT_PI, NT_TEXT, size(), and type().
Referenced by GXml::insert().
|
inlinevirtual |
Signals if node has no child nodes.
Implements GContainer.
Definition at line 145 of file GXmlNode.hpp.
References m_nodes.
Referenced by extend(), insert(), GXml::is_empty(), GXml::process_markup(), GDaemon::update_dates(), and GXmlElement::write().
Assignment operator.
[in] | node | XML node. |
Definition at line 118 of file GXmlNode.cpp.
References copy_members(), free_members(), and init_members().
Referenced by GXmlPI::operator=(), GXmlText::operator=(), GXmlComment::operator=(), GXmlElement::operator=(), and GXmlDocument::operator=().
GXmlNode * GXmlNode::operator[] | ( | const int & | index | ) |
Return pointer to XML child node.
[in] | index | Child node index [0,...,size()[. |
index
.GException::out_of_range | Child node index is out of range. |
Returns a pointer to the XML child node with the specified index
.
Definition at line 150 of file GXmlNode.cpp.
const GXmlNode * GXmlNode::operator[] | ( | const int & | index | ) | const |
Return pointer to XML child node (const version)
[in] | index | Child node index [0,...,size()[. |
index
.GException::out_of_range | Child node index is out of range. |
Returns a const pointer to the XML child node with the specified index
.
Definition at line 176 of file GXmlNode.cpp.
|
inline |
Return parent XML node.
Definition at line 170 of file GXmlNode.hpp.
References m_parent.
Referenced by filename(), parent(), and GXml::process_markup().
|
inline |
Set parent of XML node.
[in] | parent | Parent of XML node. |
Definition at line 182 of file GXmlNode.hpp.
|
pure virtual |
Implemented in GXmlElement, GXmlDocument, GXmlComment, GXmlPI, and GXmlText.
Referenced by print().
Print XML node in string.
[in] | chatter | Chattiness. |
Implements GBase.
Definition at line 861 of file GXmlNode.cpp.
References print().
|
virtual |
Remove XML child node.
[in] | index | Child node index [0,...,size()[. |
GException::out_of_range | Child node index is out of range. |
Remove XML child node at index
.
Implements GContainer.
Definition at line 481 of file GXmlNode.cpp.
References G_REMOVE, m_nodes, and size().
Referenced by GXml::remove(), and GCOMObservation::write().
|
inlinevirtual |
Reserve space for child nodes.
[in] | num | Number of child nodes for which space should be reserved. |
Implements GContainer.
Definition at line 157 of file GXmlNode.hpp.
References m_nodes.
Referenced by extend(), and GXml::reserve().
Set XML child node.
[in] | index | Child node index [0,...,size()[. |
[in] | node | XML child node. |
GException::invalid_argument | Not allowed to append root node. |
GException::invalid_value | Not allowed to append to a text, comment or PI node. |
GException::out_of_range | Child node index is out of range. |
Set XML child node. A deep copy of the node will be made and the pointer to this node will be stored.
Definition at line 214 of file GXmlNode.cpp.
References clone(), G_SET, m_nodes, NT_COMMENT, NT_DOCUMENT, NT_PI, NT_TEXT, size(), and type().
Referenced by GXml::set().
|
inlinevirtual |
Return number of child nodes.
Implements GContainer.
Definition at line 133 of file GXmlNode.hpp.
References m_nodes.
Referenced by extend(), insert(), operator[](), GXml::process_markup(), remove(), set(), GXml::size(), and GXmlElement::value().
|
pure virtual |
Implemented in GXmlElement, GXmlDocument, GXmlComment, GXmlPI, and GXmlText.
Referenced by append(), element(), elements(), insert(), and set().
|
pure virtual |
Implemented in GXmlElement, GXmlDocument, GXmlComment, GXmlPI, and GXmlText.
|
protected |
Pointer to child nodes.
Definition at line 123 of file GXmlNode.hpp.
Referenced by append(), copy_members(), element(), elements(), extend(), free_members(), init_members(), insert(), is_empty(), operator[](), GXmlDocument::print(), GXmlElement::print(), remove(), reserve(), set(), size(), GXmlDocument::write(), and GXmlElement::write().
|
protected |
Pointer on parent node.
Definition at line 122 of file GXmlNode.hpp.
Referenced by copy_members(), init_members(), and parent().