mt
 All Classes Files Functions Enumerations Groups Pages
element.h
1 /***************************************************************************
2  * Copyright (C) 2006 by Adolfo Rodriguez *
3  * adolfo.rodriguez@upc.edu *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
22 
23 // HEADER GUARD
24 #ifndef MT_ELEMENT_H
25 #define MT_ELEMENT_H
26 
27 // C++ STANDARD HEADERS
28 #include <iostream>
29 #include <string>
30 
31 // MT LIBRARY HEADERS
32 #include <mt/mt_variant.h>
33 
34 
36 
37 namespace mt
38 {
39 
40 
42 
47 
48 class Element
49 {
50 
51 public:
52 
53 // LIFECYCLE
54 
55  Element();
56 
58  Element(const MtVariant& geom,
59  const std::string& el_name = "");
60 
61  template<class T>
62  Element(const T& val,
63  const std::string& el_name = "");
64 
65  // Compiler generated copy constructor is being used
66 
67  // Compiler generated destructor is being used
68 
69 
70 // OPERATORS
71 
72  // Compiler generated assignment operator is being used
73 
74  bool operator==(const Element& el) const;
75 
76  bool operator!=(const Element& el) const;
77 
78 // ACCESS
79 
81  const MtVariant getGeometry() const;
82  MtVariant& getGeometryRef();
83  const MtVariant& getGeometryRef() const;
84 
86  const std::string getName() const;
87  std::string& getNameRef();
88  const std::string& getNameRef() const;
89 
91  void setGeometry(const MtVariant& geom);
92 
94  void setName(const std::string& el_name);
95 
96 
97 private:
98 
99 // MEMBERS
100  MtVariant m_geom;
101  std::string m_el_name;
102 };
103 
104 
106 
107 // OPERATORS
108 
109 std::ostream& operator<<(std::ostream& os,
110  const Element& el);
111 
112 
114 
115 // LIFECYCLE
116 
117 inline Element::Element() {}
118 
119 inline Element::Element(const MtVariant& geom,
120  const std::string& el_name) :
121 
122  m_geom (geom),
123  m_el_name (el_name) {}
124 
125 template<class T> inline
126 Element::Element(const T& val,
127  const std::string& el_name) :
128 
129  m_geom (MtVariant(val)),
130  m_el_name (el_name) {}
131 
132 
133 // OPERATORS
134 
135 inline bool Element::operator==(const Element& el) const
136 {
137  return (m_geom == el.getGeometry() &&
138  m_el_name == el.getName());
139 }
140 
141 
142 inline bool Element::operator!=(const Element& el) const
143 {
144  return !(*this == el);
145 }
146 
147 
148 // ACCESS
149 
150 inline const MtVariant Element::getGeometry() const
151 {
152  return m_geom;
153 }
154 
155 
156 inline MtVariant& Element::getGeometryRef()
157 {
158  return m_geom;
159 }
160 
161 
162 inline const MtVariant& Element::getGeometryRef() const
163 {
164  return m_geom;
165 }
166 
167 
168 inline const std::string Element::getName() const
169 {
170  return m_el_name;
171 }
172 
173 
174 inline std::string& Element::getNameRef()
175 {
176  return m_el_name;
177 }
178 
179 
180 inline const std::string& Element::getNameRef() const
181 {
182  return m_el_name;
183 }
184 
185 
186 inline void Element::setGeometry(const MtVariant& geom)
187 {
188  m_geom = geom;
189 }
190 
191 
192 inline void Element::setName(const std::string& el_name)
193 {
194  m_el_name = el_name;
195 }
196 
197 
199 
200 // OPERATORS
201 
202 inline std::ostream& operator<<(std::ostream& os,
203  const Element& el)
204 {
205  return os << el.getName() << ":\n"
206  << el.getGeometry();
207 }
208 
209 
210 } // mt
211 
212 #endif // MT_ELEMENT_H