Value.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * Copyright (C) 2009-2010 Cassio Neri Moreira
00004  *
00005  * This file is part of the KeyValue library.
00006  *
00007  * The KeyValue library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * The KeyValue library 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 GNU General
00015  * Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with KeyValue. If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  **************************************************************************/
00021 
00028 #ifndef KEYVALUE_VALUE_VALUE_H_
00029 #define KEYVALUE_VALUE_VALUE_H_
00030 
00031 #include <iosfwd>
00032 
00033 #include <boost/variant.hpp>
00034 
00035 #include "keyvalue/value/Matrix.h"
00036 #include "keyvalue/value/Single.h"
00037 #include "keyvalue/value/Vector.h"
00038 
00039 namespace keyvalue {
00040 
00044 namespace value {
00045 
00051 class Value {
00052 
00053 public:
00054 
00055   typedef boost::variant<Single, Vector, Matrix> DataType_;
00056 
00061   Value();
00062 
00070   Value(const DataType_& data);
00071 
00079   template <typename Rhs>
00080   Value(const Rhs& rhs);
00081 
00091   template <typename Rhs>
00092   Value&
00093   operator=(const Rhs& rhs);
00094 
00098   bool
00099   operator==(const Value& rhs) const;
00100 
00109   template <typename Type>
00110   const Type*
00111   get() const;
00112 
00116   template <typename Type>
00117   Type*
00118   get();
00119 
00120 private:
00121 
00122   DataType_ data_;
00123 
00124 }; // class Value
00125 
00131 std::ostream&
00132 operator<<(std::ostream& os, const Value& rhs);
00133 
00146 template <typename Rhs>
00147 struct Parent;
00148 
00149 template <>
00150 struct Parent<Value::DataType_> {
00151   typedef Value Type_;
00152 };
00153 
00154 template <>
00155 struct Parent<Single> {
00156   typedef Value::DataType_ Type_;
00157 };
00158 
00159 template <>
00160 struct Parent<Vector> {
00161   typedef Value::DataType_ Type_;
00162 };
00163 
00164 template <>
00165 struct Parent<Matrix> {
00166   typedef Value::DataType_ Type_;
00167 };
00168 
00169 /*--------------------------------------------------------------------------
00170  * Value()
00171  *------------------------------------------------------------------------*/
00172 
00173 template <typename Rhs>
00174 Value::Value(const Rhs& rhs) :
00175   data_(Value(typename Parent<Rhs>::Type_(rhs)).data_) {
00180 }
00181 
00182 /*--------------------------------------------------------------------------
00183  * operator=()
00184  *------------------------------------------------------------------------*/
00185 
00186 template <typename Rhs>
00187 Value&
00188 Value::operator=(const Rhs& rhs) {
00193   return *this = typename Parent<Rhs>::Type_(rhs);
00194 }
00195 
00196 } // namespace value
00197 } // namespace keyvalue
00198 
00199 #endif // KEYVALUE_VALUE_VALUE_H_

Generated on Sat Mar 20 15:08:29 2010 for KeyValue by  doxygen 1.6.1