GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelAssociation.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelAssociation.hpp - Model association 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 GModelAssociation.hpp
23  * @brief Model association class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELASSOCIATION_HPP
28 #define GMODELASSOCIATION_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GBase.hpp"
34 
35 /* __ Forward declarations _______________________________________________ */
36 class GXmlElement;
37 
38 
39 /***********************************************************************//**
40  * @class GModelAssociation
41  *
42  * @brief Model association class
43  *
44  * The GModelAssociation class stores association information for a model.
45  * Each association has a name and an arbitrary number properties.
46  ***************************************************************************/
47 class GModelAssociation : public GBase {
48 
49 public:
50  // Constructors and destructors
51  GModelAssociation(void);
52  explicit GModelAssociation(const std::string& name);
53  explicit GModelAssociation(const GXmlElement& xml);
54  GModelAssociation(const GModelAssociation& association);
55  virtual ~GModelAssociation(void);
56 
57  // Operators
58  GModelAssociation& operator=(const GModelAssociation& association);
59 
60  // Methods
61  void clear(void);
62  GModelAssociation* clone(void) const;
63  std::string classname(void) const;
64  int size(void) const;
65  bool is_empty(void) const;
66  const std::string& name(void) const;
67  void name(const std::string& name);
68  const std::string& value(const std::string& name) const;
69  const std::string& error(const std::string& name) const;
70  void property(const std::string& name,
71  const std::string& value,
72  const std::string& error = "");
73  void read(const GXmlElement& xml);
74  void write(GXmlElement& xml) const;
75  std::string print(const GChatter& chatter = NORMAL) const;
76 
77 protected:
78  // Protected methods
79  void init_members(void);
80  void copy_members(const GModelAssociation& association);
81  void free_members(void);
82  int get_index(const std::string& name) const;
84  const std::string& name) const;
85 
86  // Protected data members
87  std::string m_name; //!< Association name
88  std::vector<std::string> m_names; //!< Property names
89  std::vector<std::string> m_values; //!< Property values
90  std::vector<std::string> m_errors; //!< Property errors
91 };
92 
93 
94 /***********************************************************************//**
95  * @brief Return class name
96  *
97  * @return String containing the class name ("GModelAssociation").
98  ***************************************************************************/
99 inline
100 std::string GModelAssociation::classname(void) const
101 {
102  return ("GModelAssociation");
103 }
104 
105 
106 /***********************************************************************//**
107  * @brief Return number of association properties
108  *
109  * @return Number of association properties.
110  *
111  * Returns the number of association properties.
112  ***************************************************************************/
113 inline
114 int GModelAssociation::size(void) const
115 {
116  return (int)m_names.size();
117 }
118 
119 
120 /***********************************************************************//**
121  * @brief Signals if there are no association properties
122  *
123  * @return True if the association has no properties, false otherwise.
124  *
125  * Signals if the association has no properties.
126  ***************************************************************************/
127 inline
129 {
130  return (m_names.empty());
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Return association name
136  *
137  * @return Association name.
138  ***************************************************************************/
139 inline
140 const std::string& GModelAssociation::name(void) const
141 {
142  return (m_name);
143 }
144 
145 
146 /***********************************************************************//**
147  * @brief Set association name
148  *
149  * @param[in] name Association name.
150  ***************************************************************************/
151 inline
152 void GModelAssociation::name(const std::string& name)
153 {
154  m_name = name;
155  return;
156 }
157 #endif /* GMODELASSOCIATION_HPP */
std::string m_name
Association name.
int size(void) const
Return number of association properties.
void clear(void)
Clear model association.
bool is_empty(void) const
Signals if there are no association properties.
Definition of interface for all GammaLib classes.
XML element node class.
Definition: GXmlElement.hpp:48
const std::string & value(const std::string &name) const
Return property value.
GXmlElement * get_property_xml(GXmlElement &xml, const std::string &name) const
Return pointer to property with given name in XML element.
Model association class.
std::string print(const GChatter &chatter=NORMAL) const
Print model association.
virtual ~GModelAssociation(void)
Destructor.
std::vector< std::string > m_names
Property names.
std::vector< std::string > m_values
Property values.
GModelAssociation(void)
Void constructor.
void read(const GXmlElement &xml)
Read model association from XML document.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
const std::string & error(const std::string &name) const
Return property error.
GChatter
Definition: GTypemaps.hpp:33
std::vector< std::string > m_errors
Property errors.
GModelAssociation * clone(void) const
Clone model association.
std::string classname(void) const
Return class name.
int get_index(const std::string &name) const
Return property index by name.
GModelAssociation & operator=(const GModelAssociation &association)
Assignment operator.
void copy_members(const GModelAssociation &association)
Copy class members.
const std::string & name(void) const
Return association name.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
void write(GXmlElement &xml) const
Write model association into XML element.
void property(const std::string &name, const std::string &value, const std::string &error="")
Set property value and (optionally) error.