GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelAssociation Class Reference

Model association class. More...

#include <GModelAssociation.hpp>

Inheritance diagram for GModelAssociation:
GBase

Public Member Functions

 GModelAssociation (void)
 Void constructor. More...
 
 GModelAssociation (const std::string &name)
 Association name constructor. More...
 
 GModelAssociation (const GXmlElement &xml)
 XML element constructor. More...
 
 GModelAssociation (const GModelAssociation &association)
 Copy constructor. More...
 
virtual ~GModelAssociation (void)
 Destructor. More...
 
GModelAssociationoperator= (const GModelAssociation &association)
 Assignment operator. More...
 
void clear (void)
 Clear model association. More...
 
GModelAssociationclone (void) const
 Clone model association. More...
 
std::string classname (void) const
 Return class name. More...
 
int size (void) const
 Return number of association properties. More...
 
bool is_empty (void) const
 Signals if there are no association properties. More...
 
const std::string & name (void) const
 Return association name. More...
 
void name (const std::string &name)
 Set association name. More...
 
const std::string & value (const std::string &name) const
 Return property value. More...
 
const std::string & error (const std::string &name) const
 Return property error. More...
 
void property (const std::string &name, const std::string &value, const std::string &error="")
 Set property value and (optionally) error. More...
 
void read (const GXmlElement &xml)
 Read model association from XML document. More...
 
void write (GXmlElement &xml) const
 Write model association into XML element. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print model association. 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 GModelAssociation &association)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
int get_index (const std::string &name) const
 Return property index by name. More...
 
GXmlElementget_property_xml (GXmlElement &xml, const std::string &name) const
 Return pointer to property with given name in XML element. More...
 

Protected Attributes

std::string m_name
 Association name. More...
 
std::vector< std::string > m_names
 Property names. More...
 
std::vector< std::string > m_values
 Property values. More...
 
std::vector< std::string > m_errors
 Property errors. More...
 

Detailed Description

Model association class.

The GModelAssociation class stores association information for a model. Each association has a name and an arbitrary number properties.

Definition at line 47 of file GModelAssociation.hpp.

Constructor & Destructor Documentation

GModelAssociation::GModelAssociation ( void  )

Void constructor.

Definition at line 62 of file GModelAssociation.cpp.

References init_members().

Referenced by clone().

GModelAssociation::GModelAssociation ( const std::string &  name)
explicit

Association name constructor.

Parameters
[in]nameAssociation name.

Construct a model association from an association name.

Definition at line 79 of file GModelAssociation.cpp.

References init_members(), and name().

GModelAssociation::GModelAssociation ( const GXmlElement xml)
explicit

XML element constructor.

Parameters
[in]xmlXML element.

Construct a model association from an XML element.

Definition at line 99 of file GModelAssociation.cpp.

References init_members(), and read().

GModelAssociation::GModelAssociation ( const GModelAssociation association)

Copy constructor.

Parameters
[in]associationModel association.

Definition at line 117 of file GModelAssociation.cpp.

References copy_members(), and init_members().

GModelAssociation::~GModelAssociation ( void  )
virtual

Destructor.

Definition at line 133 of file GModelAssociation.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GBase.

Definition at line 100 of file GModelAssociation.hpp.

void GModelAssociation::clear ( void  )
virtual

Clear model association.

Implements GBase.

Definition at line 185 of file GModelAssociation.cpp.

References free_members(), and init_members().

GModelAssociation * GModelAssociation::clone ( void  ) const
virtual

Clone model association.

Returns
Pointer to deep copy of model association.

Implements GBase.

Definition at line 203 of file GModelAssociation.cpp.

References GModelAssociation().

void GModelAssociation::copy_members ( const GModelAssociation association)
protected

Copy class members.

Parameters
[in]associationModel association.

Definition at line 450 of file GModelAssociation.cpp.

References m_errors, m_name, m_names, and m_values.

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

const std::string & GModelAssociation::error ( const std::string &  name) const

Return property error.

Parameters
[in]nameProperty name
Returns
Property error.
Exceptions
GException::invalid_argumentProperty name not found

Returns the error of the property with the specified name.

Definition at line 248 of file GModelAssociation.cpp.

References G_ERROR, get_index(), and m_errors.

Referenced by read().

void GModelAssociation::free_members ( void  )
protected

Delete class members.

Definition at line 466 of file GModelAssociation.cpp.

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

int GModelAssociation::get_index ( const std::string &  name) const
protected

Return property index by name.

Parameters
[in]nameProperty name.
Returns
Property index (-1 if not found)

Returns the index of the property with the specified name. If no property with the specified name is found the method returns -1.

Definition at line 482 of file GModelAssociation.cpp.

References m_names, and size().

Referenced by error(), property(), and value().

GXmlElement * GModelAssociation::get_property_xml ( GXmlElement xml,
const std::string &  name 
) const
protected

Return pointer to property with given name in XML element.

Parameters
[in]xmlXML element.
[in]nameProperty name.
Returns
Pointer to property XML element.
Exceptions
GException::invalid_valueInvalid XML format encountered.

Returns pointer to property with given name in XML element. If the name is not found, a property with the given name is added.

The function checks for multiple occurences of a property and throws an exception in case that more than one property with a given name is found.

Definition at line 516 of file GModelAssociation.cpp.

References GXmlNode::append(), GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), G_GET_PROPERTY_XML, name(), gammalib::number(), property(), and gammalib::str().

Referenced by write().

void GModelAssociation::init_members ( void  )
protected

Initialise class members.

Definition at line 432 of file GModelAssociation.cpp.

References m_errors, m_name, m_names, and m_values.

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

bool GModelAssociation::is_empty ( void  ) const
inline

Signals if there are no association properties.

Returns
True if the association has no properties, false otherwise.

Signals if the association has no properties.

Definition at line 128 of file GModelAssociation.hpp.

References m_names.

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

Return association name.

Returns
Association name.

Definition at line 140 of file GModelAssociation.hpp.

References m_name.

Referenced by GModelAssociations::append(), get_property_xml(), GModelAssociation(), GModelAssociations::insert(), name(), print(), read(), and write().

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

Set association name.

Parameters
[in]nameAssociation name.

Definition at line 152 of file GModelAssociation.hpp.

References m_name, and name().

GModelAssociation & GModelAssociation::operator= ( const GModelAssociation association)

Assignment operator.

Parameters
[in]associationModel association.
Returns
Model association.

Definition at line 155 of file GModelAssociation.cpp.

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

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

Print model association.

Parameters
[in]chatterChattiness.
Returns
String containing model association information.

Implements GBase.

Definition at line 392 of file GModelAssociation.cpp.

References m_errors, m_names, m_values, name(), gammalib::parformat(), SILENT, size(), and gammalib::str().

void GModelAssociation::property ( const std::string &  name,
const std::string &  value,
const std::string &  error = "" 
)

Set property value and (optionally) error.

Parameters
[in]nameProperty name
[in]valueProperty value
[in]errorProperty error
Exceptions
GException::invalid_argumentProperty with specified name exists aleady

Sets the value and optionally the error of the property with the specified name.

Definition at line 277 of file GModelAssociation.cpp.

References G_PROPERTY, get_index(), m_errors, m_names, and m_values.

Referenced by get_property_xml(), and read().

void GModelAssociation::read ( const GXmlElement xml)

Read model association from XML document.

Parameters
[in]xmlXML element.

Read model association from the XML element. The XML element is expected to have the following structure

<association name="Crab">
    <property name="RA" value="83.6331"/>
    <property name="DEC" value="22.0145"/>
    <property name="distance" value="0.0123"/>
    <property name="probability" value="0.978"/>
</association>

Properties need to have unique names. If properties with identical names are encountered, and exception is thrown.

Definition at line 315 of file GModelAssociation.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), error(), m_errors, m_names, m_values, name(), property(), and value().

Referenced by GModelAssociation().

int GModelAssociation::size ( void  ) const
inline

Return number of association properties.

Returns
Number of association properties.

Returns the number of association properties.

Definition at line 114 of file GModelAssociation.hpp.

References m_names.

Referenced by get_index(), print(), and write().

const std::string & GModelAssociation::value ( const std::string &  name) const

Return property value.

Parameters
[in]nameProperty name
Returns
Property value.
Exceptions
GException::invalid_argumentProperty name not found

Returns the value of the property with the specified name.

Definition at line 221 of file GModelAssociation.cpp.

References G_VALUE, get_index(), and m_values.

Referenced by read().

void GModelAssociation::write ( GXmlElement xml) const

Write model association into XML element.

Parameters
[in]xmlXML element.

Write model association into the XML element. The following structure will be written

<association name="Crab">
    <property name="RA" value="83.6331"/>
    <property name="DEC" value="22.0145"/>
    <property name="distance" value="0.0123"/>
    <property name="probability" value="0.978"/>
</association>

Definition at line 366 of file GModelAssociation.cpp.

References GXmlElement::attribute(), get_property_xml(), m_errors, m_names, m_values, name(), and size().

Member Data Documentation

std::vector<std::string> GModelAssociation::m_errors
protected

Property errors.

Definition at line 90 of file GModelAssociation.hpp.

Referenced by copy_members(), error(), init_members(), print(), property(), read(), and write().

std::string GModelAssociation::m_name
protected

Association name.

Definition at line 87 of file GModelAssociation.hpp.

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

std::vector<std::string> GModelAssociation::m_names
protected

Property names.

Definition at line 88 of file GModelAssociation.hpp.

Referenced by copy_members(), get_index(), init_members(), is_empty(), print(), property(), read(), size(), and write().

std::vector<std::string> GModelAssociation::m_values
protected

Property values.

Definition at line 89 of file GModelAssociation.hpp.

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


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