GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GXmlAttribute.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GXmlAttribute.hpp - XML attribute class definition *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2016 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 GXmlAttribute.hpp
23  * @brief XML attribute class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GXMLATTRIBUTE_HPP
28 #define GXMLATTRIBUTE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GBase.hpp"
33 #include "GUrl.hpp"
34 
35 
36 /***********************************************************************//**
37  * @class GXmlAttribute
38  *
39  * @brief XML attribute class
40  *
41  * This class implements an attribute of an XML element. An attribute
42  * consists of a name-value pair. There can only be one attribute with a
43  * given name. Here an example of an XML element with attributes:
44  *
45  * <element type="singleton" name="gamma-ray">
46  *
47  * The element has two attributes:
48  * - @p type has a value of "singleton"
49  * - @p name has a value of "gamma-ray"
50  *
51  * The hyphens are stripped from the attribute value before storing in the
52  * name-value pair constructor. Hyphens are added when writing an attribute
53  * using the write() method. Allowed hyphens are " and '.
54  ***************************************************************************/
55 class GXmlAttribute : public GBase {
56 
57 public:
58  // Constructors and destructors
59  GXmlAttribute(void);
60  GXmlAttribute(const GXmlAttribute& attr);
61  GXmlAttribute(const std::string& name, const std::string& value);
62  virtual ~GXmlAttribute(void);
63 
64  // Operators
66 
67  // Methods
68  void clear(void);
69  GXmlAttribute* clone(void) const;
70  std::string classname(void) const;
71  void write(GUrl& url) const;
72  const std::string& name(void) const;
73  const std::string& value(void) const;
74  void name(const std::string& name);
75  void value(const std::string& value);
76  std::string print(const GChatter& chatter = NORMAL) const;
77 
78 protected:
79  // Protected methods
80  void init_members(void);
81  void copy_members(const GXmlAttribute& attr);
82  void free_members(void);
83 
84  // Protected data members
85  std::string m_name; //!< Attribute name
86  std::string m_value; //!< Attribute value
87 };
88 
89 
90 /***********************************************************************//**
91  * @brief Return class name
92  *
93  * @return String containing the class name ("GXmlAttribute").
94  ***************************************************************************/
95 inline
96 std::string GXmlAttribute::classname(void) const
97 {
98  return ("GXmlAttribute");
99 }
100 
101 
102 /***********************************************************************//**
103  * @brief Return attribute name
104  *
105  * @return Attribute name.
106  ***************************************************************************/
107 inline
108 const std::string& GXmlAttribute::name(void) const
109 {
110  return (m_name);
111 }
112 
113 
114 /***********************************************************************//**
115  * @brief Set attribute name
116  *
117  * @param[in] name Attribute name.
118  ***************************************************************************/
119 inline
120 void GXmlAttribute::name(const std::string& name)
121 {
122  m_name = name;
123  return;
124 }
125 
126 
127 /***********************************************************************//**
128  * @brief Return attribute value
129  *
130  * @return Attribute value.
131  ***************************************************************************/
132 inline
133 const std::string& GXmlAttribute::value(void) const
134 {
135  return (m_value);
136 }
137 
138 /***********************************************************************//**
139  * @brief Set attribute value
140  *
141  * @param[in] value Attribute value.
142  ***************************************************************************/
143 inline
144 void GXmlAttribute::value(const std::string& value)
145 {
146  m_value = value;
147  return;
148 }
149 
150 #endif /* GXMLATTRIBUTE_HPP */
void copy_members(const GXmlAttribute &attr)
Copy class members.
Definition of interface for all GammaLib classes.
XML attribute class.
std::string m_value
Attribute value.
void clear(void)
Clear element attribute.
void write(GUrl &url) const
Write attribute into URL.
Abstract URL base class interface definition.
Abstract URL base class.
Definition: GUrl.hpp:44
virtual ~GXmlAttribute(void)
Destructor.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
const std::string & name(void) const
Return attribute name.
std::string print(const GChatter &chatter=NORMAL) const
Print element attribute.
GChatter
Definition: GTypemaps.hpp:33
GXmlAttribute * clone(void) const
Clone element attribute.
GXmlAttribute & operator=(const GXmlAttribute &attr)
Assignment operator.
std::string classname(void) const
Return class name.
std::string m_name
Attribute name.
GXmlAttribute(void)
Void constructor.
const std::string & value(void) const
Return attribute value.
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.