GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GXmlAttribute Class Reference

XML attribute class. More...

#include <GXmlAttribute.hpp>

Inheritance diagram for GXmlAttribute:
GBase

Public Member Functions

 GXmlAttribute (void)
 Void constructor. More...
 
 GXmlAttribute (const GXmlAttribute &attr)
 Copy constructor. More...
 
 GXmlAttribute (const std::string &name, const std::string &value)
 Name-Value pair constructor. More...
 
virtual ~GXmlAttribute (void)
 Destructor. More...
 
GXmlAttributeoperator= (const GXmlAttribute &attr)
 Assignment operator. More...
 
void clear (void)
 Clear element attribute. More...
 
GXmlAttributeclone (void) const
 Clone element attribute. More...
 
std::string classname (void) const
 Return class name. More...
 
void write (GUrl &url) const
 Write attribute into URL. More...
 
const std::string & name (void) const
 Return attribute name. More...
 
const std::string & value (void) const
 Return attribute value. More...
 
void name (const std::string &name)
 Set attribute name. More...
 
void value (const std::string &value)
 Set attribute value. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print element attribute. 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 GXmlAttribute &attr)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Protected Attributes

std::string m_name
 Attribute name. More...
 
std::string m_value
 Attribute value. More...
 

Detailed Description

XML attribute class.

This class implements an attribute of an XML element. An attribute consists of a name-value pair. There can only be one attribute with a given name. Here an example of an XML element with attributes:

<element type="singleton" name="gamma-ray">

The element has two attributes:

  • type has a value of "singleton"
  • name has a value of "gamma-ray"

The hyphens are stripped from the attribute value before storing in the name-value pair constructor. Hyphens are added when writing an attribute using the write() method. Allowed hyphens are " and '.

Definition at line 55 of file GXmlAttribute.hpp.

Constructor & Destructor Documentation

GXmlAttribute::GXmlAttribute ( void  )

Void constructor.

Definition at line 53 of file GXmlAttribute.cpp.

References init_members().

Referenced by clone().

GXmlAttribute::GXmlAttribute ( const GXmlAttribute attr)

Copy constructor.

Parameters
[in]attrElement attribute.

Definition at line 68 of file GXmlAttribute.cpp.

References copy_members(), and init_members().

GXmlAttribute::GXmlAttribute ( const std::string &  name,
const std::string &  value 
)

Name-Value pair constructor.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

Construct attribute form a name and a value. Predefined entities (e.g. ") in attribute values are automatically converted into normal characters. The constructor strips any existing " or ' leading and trailing hyphens from the value string.

Definition at line 92 of file GXmlAttribute.cpp.

References init_members(), name(), value(), and gammalib::xml2str().

GXmlAttribute::~GXmlAttribute ( void  )
virtual

Destructor.

Definition at line 126 of file GXmlAttribute.cpp.

References free_members().

Member Function Documentation

std::string GXmlAttribute::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GXmlAttribute").

Implements GBase.

Definition at line 96 of file GXmlAttribute.hpp.

void GXmlAttribute::clear ( void  )
virtual

Clear element attribute.

Resets element attribute to a clean initial state.

Implements GBase.

Definition at line 180 of file GXmlAttribute.cpp.

References free_members(), and init_members().

Referenced by GXmlDocument::init_members().

GXmlAttribute * GXmlAttribute::clone ( void  ) const
virtual

Clone element attribute.

Returns
Pointer to deep copy of an element attribute.

Implements GBase.

Definition at line 198 of file GXmlAttribute.cpp.

References GXmlAttribute().

void GXmlAttribute::copy_members ( const GXmlAttribute attr)
protected

Copy class members.

Parameters
[in]attrElement attribute.

Definition at line 275 of file GXmlAttribute.cpp.

References m_name, and m_value.

Referenced by GXmlAttribute(), and operator=().

void GXmlAttribute::free_members ( void  )
protected

Delete class members.

Definition at line 289 of file GXmlAttribute.cpp.

Referenced by clear(), operator=(), and ~GXmlAttribute().

void GXmlAttribute::init_members ( void  )
protected

Initialise class members.

Definition at line 259 of file GXmlAttribute.cpp.

References m_name, and m_value.

Referenced by clear(), GXmlAttribute(), and operator=().

const std::string & GXmlAttribute::name ( void  ) const
inline

Return attribute name.

Returns
Attribute name.

Definition at line 108 of file GXmlAttribute.hpp.

References m_name.

Referenced by GXmlElement::attribute(), GXmlAttribute(), GXmlDocument::init_members(), and name().

void GXmlAttribute::name ( const std::string &  name)
inline

Set attribute name.

Parameters
[in]nameAttribute name.

Definition at line 120 of file GXmlAttribute.hpp.

References m_name, and name().

GXmlAttribute & GXmlAttribute::operator= ( const GXmlAttribute attr)

Assignment operator.

Parameters
[in]attrElement attribute.
Returns
Element attribute.

Definition at line 148 of file GXmlAttribute.cpp.

References copy_members(), free_members(), and init_members().

std::string GXmlAttribute::print ( const GChatter chatter = NORMAL) const
virtual

Print element attribute.

Parameters
[in]chatterChattiness.
Returns
String containing element attribute.

Implements GBase.

Definition at line 232 of file GXmlAttribute.cpp.

References m_name, m_value, and SILENT.

const std::string & GXmlAttribute::value ( void  ) const
inline

Return attribute value.

Returns
Attribute value.

Definition at line 133 of file GXmlAttribute.hpp.

References m_value.

Referenced by GXmlElement::attribute(), GXmlDocument::encoding(), GXmlAttribute(), GXmlDocument::init_members(), GXmlDocument::standalone(), value(), GXmlDocument::version(), and write().

void GXmlAttribute::value ( const std::string &  value)
inline

Set attribute value.

Parameters
[in]valueAttribute value.

Definition at line 144 of file GXmlAttribute.hpp.

References m_value, and value().

void GXmlAttribute::write ( GUrl url) const

Write attribute into URL.

Parameters
[in]urlUnified Resource Locator.

Writes the element attribute into the url. Special characters are automatically transformed into predefined entities (e.g. ").

Definition at line 213 of file GXmlAttribute.cpp.

References m_name, m_value, GUrl::printf(), gammalib::str2xml(), and value().

Referenced by GXmlDocument::write().

Member Data Documentation

std::string GXmlAttribute::m_name
protected

Attribute name.

Definition at line 85 of file GXmlAttribute.hpp.

Referenced by copy_members(), init_members(), name(), print(), and write().

std::string GXmlAttribute::m_value
protected

Attribute value.

Definition at line 86 of file GXmlAttribute.hpp.

Referenced by copy_members(), init_members(), print(), value(), and write().


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