GammaLib
2.1.0.dev
|
Model associations container class. More...
#include <GModelAssociations.hpp>
Public Member Functions | |
GModelAssociations (void) | |
Void constructor. More... | |
GModelAssociations (const GXmlElement &xml) | |
XML element constructor. More... | |
GModelAssociations (const GModelAssociations &associations) | |
Copy constructor. More... | |
virtual | ~GModelAssociations (void) |
Destructor. More... | |
GModelAssociations & | operator= (const GModelAssociations &associations) |
Assignment operator. More... | |
GModelAssociation & | operator[] (const int &index) |
Return reference to association. More... | |
const GModelAssociation & | operator[] (const int &index) const |
Return reference to association (const version) More... | |
GModelAssociation & | operator[] (const std::string &name) |
Return reference to model association. More... | |
const GModelAssociation & | operator[] (const std::string &name) const |
Return reference to model association (const version) More... | |
void | clear (void) |
Clear object. More... | |
GModelAssociations * | clone (void) const |
Clone instance. More... | |
std::string | classname (void) const |
Return class name. More... | |
GModelAssociation & | at (const int &index) |
Return reference to model association. More... | |
const GModelAssociation & | at (const int &index) const |
Return reference to model association (const version) More... | |
int | size (void) const |
Return number of associations in container. More... | |
bool | is_empty (void) const |
Signals if there are no associations in container. More... | |
GModelAssociation & | append (const GModelAssociation &association) |
Append model association to container. More... | |
GModelAssociation & | insert (const int &index, const GModelAssociation &association) |
Insert model association into container. More... | |
GModelAssociation & | insert (const std::string &name, const GModelAssociation &association) |
Insert model association into container. More... | |
void | remove (const int &index) |
Remove model association from container. More... | |
void | remove (const std::string &name) |
Remove model association from container. More... | |
void | reserve (const int &num) |
Reserves space for associations in container. More... | |
void | extend (const GModelAssociations &associations) |
Append model association container. More... | |
bool | contains (const std::string &name) const |
Signals if model association name exists. More... | |
void | read (const GXmlElement &xml) |
Read model associations from XML document. More... | |
void | write (GXmlElement &xml) const |
Write models into XML element. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print model associations. 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 GModelAssociations &associations) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
int | get_index (const std::string &name) const |
Return model association index by name. More... | |
GXmlElement * | get_association_xml (GXmlElement &xml, const std::string &name) const |
Return pointer to model association with given name in XML element. More... | |
Protected Attributes | |
std::vector< GModelAssociation > | m_associations |
List of associations. More... | |
Model associations container class.
Definition at line 45 of file GModelAssociations.hpp.
GModelAssociations::GModelAssociations | ( | void | ) |
Void constructor.
Definition at line 69 of file GModelAssociations.cpp.
References init_members().
Referenced by clone().
|
explicit |
XML element constructor.
[in] | xml | XML element. |
Construct a model associations container from an XML element.
Definition at line 86 of file GModelAssociations.cpp.
References init_members(), and read().
GModelAssociations::GModelAssociations | ( | const GModelAssociations & | associations | ) |
Copy constructor.
[in] | associations | Model associations container. |
Definition at line 104 of file GModelAssociations.cpp.
References copy_members(), and init_members().
|
virtual |
GModelAssociation & GModelAssociations::append | ( | const GModelAssociation & | association | ) |
Append model association to container.
[in] | association | Model association. |
GException::invalid_value | Name of model association exists already in container. |
Appends model association to the container.
Definition at line 297 of file GModelAssociations.cpp.
References G_APPEND, get_index(), m_associations, GModelAssociation::name(), size(), and gammalib::str().
Referenced by read().
GModelAssociation & GModelAssociations::at | ( | const int & | index | ) |
Return reference to model association.
[in] | index | Model association index [0,...,size()-1]. |
GException::out_of_range | Model association index is out of range. |
Returns a reference to the model association with the specified index
.
Definition at line 254 of file GModelAssociations.cpp.
const GModelAssociation & GModelAssociations::at | ( | const int & | index | ) | const |
Return reference to model association (const version)
[in] | index | Model association index [0,...,size()-1]. |
GException::out_of_range | Model association index is out of range. |
Returns a const reference to the model association with the specified index
.
Definition at line 272 of file GModelAssociations.cpp.
References G_AT, m_associations, and size().
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 103 of file GModelAssociations.hpp.
|
virtual |
Clear object.
Removes all model associations from the container.
Implements GBase.
Definition at line 218 of file GModelAssociations.cpp.
References free_members(), and init_members().
Referenced by GModel::init_members().
|
virtual |
Clone instance.
Makes a deep copy of the model associations container instance.
Implements GBase.
Definition at line 238 of file GModelAssociations.cpp.
References GModelAssociations().
bool GModelAssociations::contains | ( | const std::string & | name | ) | const |
Signals if model association name exists.
[in] | name | Model association name. |
name
exists.Searches all model association names for a match with the specified name
. If the specified name has been found, true is returned.
Definition at line 535 of file GModelAssociations.cpp.
References get_index().
|
protected |
Copy class members.
[in] | associations | Model association container. |
Definition at line 707 of file GModelAssociations.cpp.
References m_associations.
Referenced by GModelAssociations(), and operator=().
void GModelAssociations::extend | ( | const GModelAssociations & | associations | ) |
Append model association container.
[in] | associations | Model association container. |
Append model association container to the container.
Definition at line 485 of file GModelAssociations.cpp.
References G_EXTEND, get_index(), is_empty(), m_associations, reserve(), size(), and gammalib::str().
|
protected |
Delete class members.
Definition at line 720 of file GModelAssociations.cpp.
Referenced by clear(), operator=(), and ~GModelAssociations().
|
protected |
Return pointer to model association with given name in XML element.
[in] | xml | XML element. |
[in] | name | Model association name. |
GException::invalid_value | Invalid XML format encountered. |
Returns pointer to model association with given name
in XML element. If the name
is not found, a model association with the given name
is added.
The function checks for multiple occurences of a model association and throws an exception in case that more than one association with a given name is found.
Definition at line 773 of file GModelAssociations.cpp.
References GXmlNode::append(), GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), G_GET_ASSOCIATION_XML, gammalib::number(), and gammalib::str().
Referenced by write().
|
protected |
Return model association index by name.
[in] | name | Model ssociation name. |
Returns model association index based on the specified name
. If no model association with the specified name
is found the method returns -1.
Definition at line 737 of file GModelAssociations.cpp.
References m_associations, and size().
Referenced by append(), contains(), extend(), insert(), operator[](), and remove().
|
protected |
Initialise class members.
Definition at line 692 of file GModelAssociations.cpp.
References m_associations.
Referenced by clear(), GModelAssociations(), and operator=().
GModelAssociation & GModelAssociations::insert | ( | const int & | index, |
const GModelAssociation & | association | ||
) |
Insert model association into container.
[in] | index | Model association index [0,...,size()-1]. |
[in] | association | Model association. |
GException::out_of_range | Model association index is out of range. |
GException::invalid_value | Name of model association exists already in container. |
Inserts a model
association into the container before the model association with the specified index
.
Definition at line 333 of file GModelAssociations.cpp.
References G_INSERT1, get_index(), is_empty(), m_associations, GModelAssociation::name(), size(), and gammalib::str().
GModelAssociation & GModelAssociations::insert | ( | const std::string & | name, |
const GModelAssociation & | association | ||
) |
Insert model association into container.
[in] | name | Model association name. |
[in] | association | Model association. |
GException::invalid_argument | Model association with specified name not found in container. |
GException::invalid_value | Name of model association exists already in container. |
Inserts a model
association into the container before the model association with the specified name
.
Definition at line 387 of file GModelAssociations.cpp.
References G_INSERT2, get_index(), m_associations, GModelAssociation::name(), and gammalib::str().
|
inlinevirtual |
Signals if there are no associations in container.
Signals if the association container does not contain any association.
Implements GContainer.
Definition at line 159 of file GModelAssociations.hpp.
References m_associations.
Referenced by extend(), insert(), GModel::print_attributes(), and write().
GModelAssociations & GModelAssociations::operator= | ( | const GModelAssociations & | associations | ) |
Assignment operator.
[in] | associations | Model associations container. |
Definition at line 142 of file GModelAssociations.cpp.
References copy_members(), free_members(), and init_members().
|
inline |
Return reference to association.
[in] | index | Association index [0,...,size()-1]. |
Returns a reference to the association with the specified index
.
Definition at line 117 of file GModelAssociations.hpp.
References m_associations.
|
inline |
Return reference to association (const version)
[in] | index | Association index [0,...,size()-1]. |
Returns a const reference to the association with the specified index
.
Definition at line 131 of file GModelAssociations.hpp.
References m_associations.
GModelAssociation & GModelAssociations::operator[] | ( | const std::string & | name | ) |
Return reference to model association.
[in] | name | Model association name. |
GException::invalid_argument | Model association with specified name not found in container. |
Returns a reference to the model with the specified name
.
Definition at line 173 of file GModelAssociations.cpp.
const GModelAssociation & GModelAssociations::operator[] | ( | const std::string & | name | ) | const |
Return reference to model association (const version)
[in] | name | Model association name. |
GException::invalid_argument | Model association with specified name not found in container. |
Returns a const reference to the model with the specified name
.
Definition at line 190 of file GModelAssociations.cpp.
References G_ACCESS, get_index(), and m_associations.
Print model associations.
[in] | chatter | Chattiness. |
Prints all model associations into a string.
Implements GBase.
Definition at line 656 of file GModelAssociations.cpp.
References m_associations, gammalib::parformat(), SILENT, size(), and gammalib::str().
void GModelAssociations::read | ( | const GXmlElement & | xml | ) |
Read model associations from XML document.
[in] | xml | XML element. |
Read model associations from the XML element. The XML element is expected to have the following structure
<associations> <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> </associations>
This method does nothing if no "associations" tag is present in the XML element.
Definition at line 565 of file GModelAssociations.cpp.
References append(), GXmlNode::element(), GXmlNode::elements(), and m_associations.
Referenced by GModelAssociations(), and GModel::read_attributes().
|
virtual |
Remove model association from container.
[in] | index | Model association index [0,...,size()-1]. |
GException::out_of_range | Model association index is out of range. |
Remove model association of specified index
from container.
Implements GContainer.
Definition at line 430 of file GModelAssociations.cpp.
References G_REMOVE1, m_associations, and size().
void GModelAssociations::remove | ( | const std::string & | name | ) |
Remove model association from container.
[in] | name | Model association name. |
GException::invalid_argument | Model association with specified name not found in container. |
Remove model association of specified name
from container.
Definition at line 458 of file GModelAssociations.cpp.
References G_REMOVE2, get_index(), and m_associations.
|
inlinevirtual |
Reserves space for associations in container.
[in] | num | Number of associations |
Reserves space for num
associations in the container.
Implements GContainer.
Definition at line 173 of file GModelAssociations.hpp.
References m_associations.
Referenced by extend().
|
inlinevirtual |
Return number of associations in container.
Returns the number of associations in the container.
Implements GContainer.
Definition at line 145 of file GModelAssociations.hpp.
References m_associations.
Referenced by append(), at(), extend(), get_index(), insert(), print(), GModel::print_attributes(), remove(), and write().
void GModelAssociations::write | ( | GXmlElement & | xml | ) | const |
Write models into XML element.
[in] | xml | XML element. |
Write model associations into the first "associations" element that is found in the XML element. In case that no "associations" element exists, one is added to the XML element. The written XML element has the following structure
<associations> <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> </associations>
This method does nothing if there are no associations in the instance.
Definition at line 621 of file GModelAssociations.cpp.
References GXmlNode::append(), GXmlNode::element(), GXmlNode::elements(), get_association_xml(), is_empty(), m_associations, and size().
Referenced by GModel::write_attributes().
|
protected |
List of associations.
Definition at line 93 of file GModelAssociations.hpp.
Referenced by append(), at(), copy_members(), extend(), get_index(), init_members(), insert(), is_empty(), operator[](), print(), read(), remove(), reserve(), size(), and write().