solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/patterns/CValue.h
Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  solarpowerlog
00003  Copyright (C) 2009  Tobias Frost
00004 
00005  This file is part of solarpowerlog.
00006 
00007  Solarpowerlog is free software; However, it is dual-licenced
00008  as described in the file "COPYING".
00009 
00010  For this file (CValue.h), the license terms are:
00011 
00012  You can redistribute it and/or  modify it under the terms of the GNU Lesser
00013  General Public License (LGPL) as published by the Free Software Foundation;
00014  either version 3 of the License, or (at your option) any later version.
00015 
00016  This program is distributed in the hope that it will be useful, but
00017  WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  Lesser General Public License for more details.
00020 
00021  You should have received a copy of the GNU Library General Public
00022  License along with this proramm; if not, see
00023  <http://www.gnu.org/licenses/>.
00024  ----------------------------------------------------------------------------
00025  */
00026 
00037 #ifndef CVALUEX_H_
00038 #define CVALUEX_H_
00039 
00040 #ifdef HAVE_CONFIG_H
00041 #include "config.h"
00042 #endif
00043 
00044 #include "IValue.h"
00045 
00046 #include <iostream>
00047 #include <sstream>
00048 
00049 template<class T>
00050 class CValue : public IValue
00051 {
00052 
00053 public:
00054      CValue()
00055      {
00056      }
00057 
00058      void Set( T value )
00059      {
00060           this->value = value;
00061      }
00062 
00063      T Get( void ) const
00064      {
00065           return value;
00066      }
00067 
00068      virtual void operator=( const T& val )
00069      {
00070           value = val;
00071      }
00072 
00073      virtual void operator=( const CValue<T> &val )
00074      {
00075           value = val.Get();
00076      }
00077 
00078      virtual operator std::string()
00079      {
00080           std::stringstream ss;
00081           ss << value;
00082           return ss.str();
00083      }
00084 
00085 private:
00086      T value;
00087 
00088 };
00089 
00090 #endif /* CVALUEX_H_ */