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

Model associations container class. More...

#include <GModelAssociations.hpp>

Inheritance diagram for GModelAssociations:
GContainer GBase

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...
 
GModelAssociationsoperator= (const GModelAssociations &associations)
 Assignment operator. More...
 
GModelAssociationoperator[] (const int &index)
 Return reference to association. More...
 
const GModelAssociationoperator[] (const int &index) const
 Return reference to association (const version) More...
 
GModelAssociationoperator[] (const std::string &name)
 Return reference to model association. More...
 
const GModelAssociationoperator[] (const std::string &name) const
 Return reference to model association (const version) More...
 
void clear (void)
 Clear object. More...
 
GModelAssociationsclone (void) const
 Clone instance. More...
 
std::string classname (void) const
 Return class name. More...
 
GModelAssociationat (const int &index)
 Return reference to model association. More...
 
const GModelAssociationat (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...
 
GModelAssociationappend (const GModelAssociation &association)
 Append model association to container. More...
 
GModelAssociationinsert (const int &index, const GModelAssociation &association)
 Insert model association into container. More...
 
GModelAssociationinsert (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...
 
GXmlElementget_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< GModelAssociationm_associations
 List of associations. More...
 

Detailed Description

Model associations container class.

Definition at line 45 of file GModelAssociations.hpp.

Constructor & Destructor Documentation

GModelAssociations::GModelAssociations ( void  )

Void constructor.

Definition at line 69 of file GModelAssociations.cpp.

References init_members().

Referenced by clone().

GModelAssociations::GModelAssociations ( const GXmlElement xml)
explicit

XML element constructor.

Parameters
[in]xmlXML 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.

Parameters
[in]associationsModel associations container.

Definition at line 104 of file GModelAssociations.cpp.

References copy_members(), and init_members().

GModelAssociations::~GModelAssociations ( void  )
virtual

Destructor.

Definition at line 120 of file GModelAssociations.cpp.

References free_members().

Member Function Documentation

GModelAssociation & GModelAssociations::append ( const GModelAssociation association)

Append model association to container.

Parameters
[in]associationModel association.
Returns
Reference to appended model association.
Exceptions
GException::invalid_valueName 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.

Parameters
[in]indexModel association index [0,...,size()-1].
Exceptions
GException::out_of_rangeModel 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)

Parameters
[in]indexModel association index [0,...,size()-1].
Exceptions
GException::out_of_rangeModel 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().

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

Return class name.

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

Implements GBase.

Definition at line 103 of file GModelAssociations.hpp.

void GModelAssociations::clear ( void  )
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().

GModelAssociations * GModelAssociations::clone ( void  ) const
virtual

Clone instance.

Returns
Pointer to deep copy of model associations container

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.

Parameters
[in]nameModel association name.
Returns
True if model association with specified 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().

void GModelAssociations::copy_members ( const GModelAssociations associations)
protected

Copy class members.

Parameters
[in]associationsModel 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.

Parameters
[in]associationsModel 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().

void GModelAssociations::free_members ( void  )
protected

Delete class members.

Definition at line 720 of file GModelAssociations.cpp.

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

GXmlElement * GModelAssociations::get_association_xml ( GXmlElement xml,
const std::string &  name 
) const
protected

Return pointer to model association with given name in XML element.

Parameters
[in]xmlXML element.
[in]nameModel association name.
Returns
Pointer to model association XML element.
Exceptions
GException::invalid_valueInvalid 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().

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

Return model association index by name.

Parameters
[in]nameModel ssociation name.
Returns
Model association index (-1 if not found)

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().

void GModelAssociations::init_members ( void  )
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.

Parameters
[in]indexModel association index [0,...,size()-1].
[in]associationModel association.
Returns
Reference to inserted model association.
Exceptions
GException::out_of_rangeModel association index is out of range.
GException::invalid_valueName 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.

Parameters
[in]nameModel association name.
[in]associationModel association.
Returns
Reference to inserted model association.
Exceptions
GException::invalid_argumentModel association with specified name not found in container.
GException::invalid_valueName 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().

bool GModelAssociations::is_empty ( void  ) const
inlinevirtual

Signals if there are no associations in container.

Returns
True if container is empty, false otherwise.

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.

Parameters
[in]associationsModel associations container.
Returns
Model associations container.

Definition at line 142 of file GModelAssociations.cpp.

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

GModelAssociation & GModelAssociations::operator[] ( const int &  index)
inline

Return reference to association.

Parameters
[in]indexAssociation 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.

const GModelAssociation & GModelAssociations::operator[] ( const int &  index) const
inline

Return reference to association (const version)

Parameters
[in]indexAssociation 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.

Parameters
[in]nameModel association name.
Exceptions
GException::invalid_argumentModel 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)

Parameters
[in]nameModel association name.
Exceptions
GException::invalid_argumentModel 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.

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

Print model associations.

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

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.

Parameters
[in]xmlXML 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().

void GModelAssociations::remove ( const int &  index)
virtual

Remove model association from container.

Parameters
[in]indexModel association index [0,...,size()-1].
Exceptions
GException::out_of_rangeModel 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.

Parameters
[in]nameModel association name.
Exceptions
GException::invalid_argumentModel 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.

void GModelAssociations::reserve ( const int &  num)
inlinevirtual

Reserves space for associations in container.

Parameters
[in]numNumber 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().

int GModelAssociations::size ( void  ) const
inlinevirtual

Return number of associations in container.

Returns
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.

Parameters
[in]xmlXML 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().

Member Data Documentation

std::vector<GModelAssociation> GModelAssociations::m_associations
protected

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