GammaLib
2.0.0
|
Model association class. More...
#include <GModelAssociation.hpp>
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... | |
GModelAssociation & | operator= (const GModelAssociation &association) |
Assignment operator. More... | |
void | clear (void) |
Clear model association. More... | |
GModelAssociation * | clone (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... | |
GXmlElement * | get_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... | |
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.
GModelAssociation::GModelAssociation | ( | void | ) |
Void constructor.
Definition at line 62 of file GModelAssociation.cpp.
References init_members().
Referenced by clone().
|
explicit |
Association name constructor.
[in] | name | Association name. |
Construct a model association from an association name.
Definition at line 79 of file GModelAssociation.cpp.
References init_members(), and name().
|
explicit |
XML element constructor.
[in] | xml | XML 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.
[in] | association | Model association. |
Definition at line 117 of file GModelAssociation.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 100 of file GModelAssociation.hpp.
|
virtual |
Clear model association.
Implements GBase.
Definition at line 185 of file GModelAssociation.cpp.
References free_members(), and init_members().
|
virtual |
Clone model association.
Implements GBase.
Definition at line 203 of file GModelAssociation.cpp.
References GModelAssociation().
|
protected |
Copy class members.
[in] | association | Model 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.
[in] | name | Property name |
GException::invalid_argument | Property 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().
|
protected |
Delete class members.
Definition at line 466 of file GModelAssociation.cpp.
Referenced by clear(), operator=(), and ~GModelAssociation().
|
protected |
Return property index by name.
[in] | name | Property name. |
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().
|
protected |
Return pointer to property with given name in XML element.
[in] | xml | XML element. |
[in] | name | Property name. |
GException::invalid_value | Invalid 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().
|
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=().
|
inline |
Signals if there are no association properties.
Signals if the association has no properties.
Definition at line 128 of file GModelAssociation.hpp.
References m_names.
|
inline |
Return 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().
|
inline |
Set association name.
[in] | name | Association name. |
Definition at line 152 of file GModelAssociation.hpp.
GModelAssociation & GModelAssociation::operator= | ( | const GModelAssociation & | association | ) |
Assignment operator.
[in] | association | Model association. |
Definition at line 155 of file GModelAssociation.cpp.
References copy_members(), free_members(), and init_members().
Print model association.
[in] | chatter | Chattiness. |
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.
[in] | name | Property name |
[in] | value | Property value |
[in] | error | Property error |
GException::invalid_argument | Property 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.
[in] | xml | XML 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().
|
inline |
Return 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.
[in] | name | Property name |
GException::invalid_argument | Property 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.
[in] | xml | XML 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().
|
protected |
Property errors.
Definition at line 90 of file GModelAssociation.hpp.
Referenced by copy_members(), error(), init_members(), print(), property(), read(), and write().
|
protected |
Association name.
Definition at line 87 of file GModelAssociation.hpp.
Referenced by copy_members(), init_members(), and name().
|
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().
|
protected |
Property values.
Definition at line 89 of file GModelAssociation.hpp.
Referenced by copy_members(), init_members(), print(), property(), read(), value(), and write().