GammaLib 2.0.0
Loading...
Searching...
No Matches
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 _______________________________________________ */
36class 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 ***************************************************************************/
47class GModelAssociation : public GBase {
48
49public:
50 // Constructors and destructors
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
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
77protected:
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 ***************************************************************************/
99inline
100std::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 ***************************************************************************/
113inline
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 ***************************************************************************/
127inline
129{
130 return (m_names.empty());
131}
132
133
134/***********************************************************************//**
135 * @brief Return association name
136 *
137 * @return Association name.
138 ***************************************************************************/
139inline
140const 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 ***************************************************************************/
151inline
152void GModelAssociation::name(const std::string& name)
153{
154 m_name = name;
155 return;
156}
157#endif /* GMODELASSOCIATION_HPP */
Definition of interface for all GammaLib classes.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Model association class.
void free_members(void)
Delete class members.
void copy_members(const GModelAssociation &association)
Copy class members.
const std::string & error(const std::string &name) const
Return property error.
int size(void) const
Return number of association properties.
void write(GXmlElement &xml) const
Write model association into XML element.
GModelAssociation * clone(void) const
Clone model association.
void property(const std::string &name, const std::string &value, const std::string &error="")
Set property value and (optionally) error.
const std::string & name(void) const
Return association name.
std::vector< std::string > m_values
Property values.
std::string print(const GChatter &chatter=NORMAL) const
Print model association.
GModelAssociation(void)
Void constructor.
const std::string & value(const std::string &name) const
Return property value.
int get_index(const std::string &name) const
Return property index by name.
GModelAssociation & operator=(const GModelAssociation &association)
Assignment operator.
std::vector< std::string > m_names
Property names.
void read(const GXmlElement &xml)
Read model association from XML document.
virtual ~GModelAssociation(void)
Destructor.
bool is_empty(void) const
Signals if there are no association properties.
std::vector< std::string > m_errors
Property errors.
std::string m_name
Association name.
std::string classname(void) const
Return class name.
void clear(void)
Clear model association.
GXmlElement * get_property_xml(GXmlElement &xml, const std::string &name) const
Return pointer to property with given name in XML element.
void init_members(void)
Initialise class members.
XML element node class.