The Gnome Chemistry Utils  0.14.0
value.h
Go to the documentation of this file.
1 /*
2  * Gnome Chemistry Utils
3  * value.h
4  *
5  * Copyright (C) 2002-2008 Jean Bréfort <jean.brefort@normalesup.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 3 of the
10  * License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef GCU_VALUE_H
24 #define GCU_VALUE_H
25 
26 #include "chemistry.h"
27 #include <string>
28 #include <map>
29 #include <string>
30 #include <stdexcept>
31 
33 namespace gcu
34 {
35 
39 class Value
40 {
41 public:
45  Value ();
49  virtual ~Value ();
50 
54  virtual char const *GetAsString () const;
55 
59  virtual double GetAsDouble () const;
60 };
61 
65 class SimpleValue: public Value
66 {
67 friend class Element;
68 
69 public:
73  SimpleValue ();
79  SimpleValue (GcuValue value);
83  virtual ~SimpleValue ();
84 
88  char const *GetAsString () const;
92  double GetAsDouble () const;
96  GcuValue const GetValue () {return val;}
103  SimpleValue operator+ (SimpleValue const &value) const;
110  SimpleValue operator* (int n) const;
111 
112 private:
113  GcuValue val;
114  std::string str;
115 };
120 class DimensionalValue: public Value
121 {
122 friend class Element;
123 
124 public:
128  DimensionalValue ();
132  virtual ~DimensionalValue ();
133 
137  char const *GetAsString () const;
141  double GetAsDouble () const;
149  DimensionalValue operator+ (DimensionalValue const &value) const throw (std::invalid_argument);
156  DimensionalValue operator* (int n) const;
160  GcuDimensionalValue const GetValue () const {return val;}
161 
162 private:
164  std::string str;
165 };
166 
170 class StringValue: public Value
171 {
172 friend class Element;
173 
174 public:
178  StringValue ();
182  virtual ~StringValue ();
183 
187  char const *GetAsString () const;
188 
189 private:
190  std::string val;
191 };
192 
197 {
198 friend class Element;
199 
200 public:
208  virtual ~LocalizedStringValue ();
209 
214  char const *GetAsString () const;
220  char const *GetLocalizedString (char const *lang) const;
221 
222 private:
223  std::map <std::string, std::string> vals;
224 };
225 
226 } // namespace gcu
227 
228 #endif // GCU_VALUE_H