# 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 ();
    00074         SimpleValue (GcuValue value);
    00078         virtual ~SimpleValue ();
    00079
    00083         char const *GetAsString () const;
    00087         double GetAsDouble () const;
    00091         GcuValue const GetValue () {return val;}
    00092         SimpleValue operator+ (SimpleValue const &value) const;
    00093         SimpleValue operator* (int n) const;
    00094
    00095 private:
    00096         GcuValue val;
    00097         std::string str;
    00098 };
    00103 class DimensionalValue: public Value
    00104 {
    00105 friend class Element;
    00106
    00107 public:
    00111         DimensionalValue ();
    00115         virtual ~DimensionalValue ();
    00116
    00120         char const *GetAsString () const;
    00124         double GetAsDouble () const;
    00125
    00126         DimensionalValue operator+ (DimensionalValue const &value) const throw (std::invalid_argument);
    00127         DimensionalValue operator* (int n) const;
    00131         GcuDimensionalValue const GetValue () const {return val;}
    00132
    00133 private:
    00134         GcuDimensionalValue val;
    00135         std::string str;
    00136 };
    00137
    00141 class StringValue: public Value
    00142 {
    00143 friend class Element;
    00144
    00145 public:
    00149         StringValue ();
    00153         virtual ~StringValue ();
    00154
    00158         char const *GetAsString () const;
    00159
    00160 private:
    00161         std::string val;
    00162 };
    00163
    00167 class LocalizedStringValue: public Value
    00168 {
    00169 friend class Element;
    00170
    00171 public:
    00175         LocalizedStringValue ();
    00179         virtual ~LocalizedStringValue ();
    00180
    00185         char const *GetAsString () const;
    00191         char const *GetLocalizedString (char const *lang) const;
    00192
    00193 private:
    00194         std::map <std::string, std::string> vals;
    00195 };
    00196
    00197 }       // namespace gcu
    00198
    00199 #endif  //      GCU_VALUE_H