The Gnome Chemistry Utils 0.13.3
value.h
Go to the documentation of this file.
00001 /* 
00002  * Gnome Chemistry Utils
00003  * value.h 
00004  *
00005  * Copyright (C) 2002-2008 Jean Bréfort <jean.brefort@normalesup.org>
00006  *
00007  * This program is free software; you can redistribute it and/or 
00008  * modify it under the terms of the GNU General Public License as 
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
00021  */
00022 
00023 #ifndef GCU_VALUE_H
00024 #define GCU_VALUE_H
00025 
00026 #include "chemistry.h"
00027 #include <string>
00028 #include <map>
00029 #include <string>
00030 #include <stdexcept>
00031 
00033 namespace gcu
00034 {
00035 
00039 class Value
00040 {
00041 public:
00045         Value ();
00049         virtual ~Value ();
00050 
00054         virtual char const *GetAsString () const;
00055 
00059         virtual double GetAsDouble () const;
00060 };
00061 
00065 class SimpleValue: public Value
00066 {
00067 friend class Element;
00068 
00069 public:
00073         SimpleValue ();
00079         SimpleValue (GcuValue value);
00083         virtual ~SimpleValue ();
00084 
00088         char const *GetAsString () const;
00092         double GetAsDouble () const;
00096         GcuValue const GetValue () {return val;}
00103         SimpleValue operator+ (SimpleValue const &value) const;
00110         SimpleValue operator* (int n) const;
00111 
00112 private:
00113         GcuValue val;
00114         std::string str;
00115 };
00120 class DimensionalValue: public Value
00121 {
00122 friend class Element;
00123 
00124 public:
00128         DimensionalValue ();
00132         virtual ~DimensionalValue ();
00133 
00137         char const *GetAsString () const;
00141         double GetAsDouble () const;
00149         DimensionalValue operator+ (DimensionalValue const &value) const throw (std::invalid_argument);
00156         DimensionalValue operator* (int n) const;
00160         GcuDimensionalValue const GetValue () const {return val;}
00161 
00162 private:
00163         GcuDimensionalValue val;
00164         std::string str;
00165 };
00166 
00170 class StringValue: public Value
00171 {
00172 friend class Element;
00173 
00174 public:
00178         StringValue ();
00182         virtual ~StringValue ();
00183 
00187         char const *GetAsString () const;
00188 
00189 private:
00190         std::string val;
00191 };
00192 
00196 class LocalizedStringValue: public Value
00197 {
00198 friend class Element;
00199 
00200 public:
00204         LocalizedStringValue ();
00208         virtual ~LocalizedStringValue ();
00209 
00214         char const *GetAsString () const;
00220         char const *GetLocalizedString (char const *lang) const;
00221 
00222 private:
00223         std::map <std::string, std::string> vals;
00224 };
00225 
00226 }       // namespace gcu
00227 
00228 #endif  //      GCU_VALUE_H