GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelAssociations.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelAssociations.hpp - Model associations container class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2020 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GModelAssociations.hpp
23  * @brief Model associations container class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELASSOCIATIONS_HPP
28 #define GMODELASSOCIATIONS_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GContainer.hpp"
34 #include "GModelAssociation.hpp"
35 
36 /* __ Forward declarations _______________________________________________ */
37 class GXmlElement;
38 
39 
40 /***********************************************************************//**
41  * @class GModelAssociations
42  *
43  * @brief Model associations container class
44  ***************************************************************************/
46 
47 public:
48  // Constructors and destructors
49  GModelAssociations(void);
50  explicit GModelAssociations(const GXmlElement& xml);
51  GModelAssociations(const GModelAssociations& associations);
52  virtual ~GModelAssociations(void);
53 
54  // Operators
55  GModelAssociations& operator=(const GModelAssociations& associations);
56  GModelAssociation& operator[](const int& index);
57  const GModelAssociation& operator[](const int& index) const;
58  GModelAssociation& operator[](const std::string& name);
59  const GModelAssociation& operator[](const std::string& name) const;
60 
61  // Methods
62  void clear(void);
63  GModelAssociations* clone(void) const;
64  std::string classname(void) const;
65  GModelAssociation& at(const int& index);
66  const GModelAssociation& at(const int& index) const;
67  int size(void) const;
68  bool is_empty(void) const;
69  GModelAssociation& append(const GModelAssociation& association);
70  GModelAssociation& insert(const int& index,
71  const GModelAssociation& association);
72  GModelAssociation& insert(const std::string& name,
73  const GModelAssociation& association);
74  void remove(const int& index);
75  void remove(const std::string& name);
76  void reserve(const int& num);
77  void extend(const GModelAssociations& associations);
78  bool contains(const std::string& name) const;
79  void read(const GXmlElement& xml);
80  void write(GXmlElement& xml) const;
81  std::string print(const GChatter& chatter = NORMAL) const;
82 
83 protected:
84  // Protected methods
85  void init_members(void);
86  void copy_members(const GModelAssociations& associations);
87  void free_members(void);
88  int get_index(const std::string& name) const;
90  const std::string& name) const;
91 
92  // Proteced members
93  std::vector<GModelAssociation> m_associations; //!< List of associations
94 };
95 
96 
97 /***********************************************************************//**
98  * @brief Return class name
99  *
100  * @return String containing the class name ("GModelAssociations").
101  ***************************************************************************/
102 inline
103 std::string GModelAssociations::classname(void) const
104 {
105  return ("GModelAssociations");
106 }
107 
108 
109 /***********************************************************************//**
110  * @brief Return reference to association
111  *
112  * @param[in] index Association index [0,...,size()-1].
113  *
114  * Returns a reference to the association with the specified @p index.
115  ***************************************************************************/
116 inline
118 {
119  return (m_associations[index]);
120 }
121 
122 
123 /***********************************************************************//**
124  * @brief Return reference to association (const version)
125  *
126  * @param[in] index Association index [0,...,size()-1].
127  *
128  * Returns a const reference to the association with the specified @p index.
129  ***************************************************************************/
130 inline
131 const GModelAssociation& GModelAssociations::operator[](const int& index) const
132 {
133  return (m_associations[index]);
134 }
135 
136 
137 /***********************************************************************//**
138  * @brief Return number of associations in container
139  *
140  * @return Number of associations in container.
141  *
142  * Returns the number of associations in the container.
143  ***************************************************************************/
144 inline
146 {
147  return (int)m_associations.size();
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Signals if there are no associations in container
153  *
154  * @return True if container is empty, false otherwise.
155  *
156  * Signals if the association container does not contain any association.
157  ***************************************************************************/
158 inline
160 {
161  return (m_associations.empty());
162 }
163 
164 
165 /***********************************************************************//**
166  * @brief Reserves space for associations in container
167  *
168  * @param[in] num Number of associations
169  *
170  * Reserves space for @p num associations in the container.
171  ***************************************************************************/
172 inline
173 void GModelAssociations::reserve(const int& num)
174 {
175  m_associations.reserve(num);
176  return;
177 }
178 
179 #endif /* GMODELASSOCIATIONS_HPP */
int size(void) const
Return number of associations in container.
GModelAssociations & operator=(const GModelAssociations &associations)
Assignment operator.
GModelAssociation & insert(const int &index, const GModelAssociation &association)
Insert model association into container.
XML element node class.
Definition: GXmlElement.hpp:48
void clear(void)
Clear object.
std::string print(const GChatter &chatter=NORMAL) const
Print model associations.
Model association class.
void write(GXmlElement &xml) const
Write models into XML element.
bool contains(const std::string &name) const
Signals if model association name exists.
GModelAssociation & append(const GModelAssociation &association)
Append model association to container.
void init_members(void)
Initialise class members.
virtual ~GModelAssociations(void)
Destructor.
GModelAssociation & operator[](const int &index)
Return reference to association.
void copy_members(const GModelAssociations &associations)
Copy class members.
GModelAssociations(void)
Void constructor.
GChatter
Definition: GTypemaps.hpp:33
int get_index(const std::string &name) const
Return model association index by name.
GModelAssociations * clone(void) const
Clone instance.
void read(const GXmlElement &xml)
Read model associations from XML document.
bool is_empty(void) const
Signals if there are no associations in container.
Model association class definition.
std::string classname(void) const
Return class name.
void reserve(const int &num)
Reserves space for associations in container.
Model associations container class.
Definition of interface for container classes.
GXmlElement * get_association_xml(GXmlElement &xml, const std::string &name) const
Return pointer to model association with given name in XML element.
std::vector< GModelAssociation > m_associations
List of associations.
void extend(const GModelAssociations &associations)
Append model association container.
Interface class for container classes.
Definition: GContainer.hpp:52
GModelAssociation & at(const int &index)
Return reference to model association.
void free_members(void)
Delete class members.