solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/patterns/IValue.cpp
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 (IValue.cpp), the license terms are:
00011 
00012  You can redistribute it and/or modify it under the terms of the GNU
00013  General Public License as published by the Free Software Foundation; either
00014  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 
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036 
00037 #include "IValue.h"
00038 #include "CValue.h"
00039 
00040 #include <iostream>
00041 #include <assert.h>
00042 
00043 using namespace std;
00044 
00045 IValue::IValue()
00046 {
00047 }
00048 
00049 IValue::factory_types IValue::GetType( void ) const
00050 {
00051      return type;
00052 }
00053 
00054 IValue *IValue::Factory( const factory_types newtype )
00055 {
00056      IValue *tmp = NULL;
00057 
00058      switch (newtype) {
00059 
00060      case bool_type:
00061           tmp = new CValue<bool> ;
00062           ((CValue<bool>*) tmp) ->Set(false);
00063           break;
00064 
00065      case int_type:
00066           tmp = new CValue<int> ;
00067           ((CValue<int>*) tmp) ->Set(0);
00068           break;
00069 
00070      case float_type:
00071           tmp = new CValue<float> ;
00072           ((CValue<float>*) tmp) ->Set(0.0);
00073           break;
00074 
00075      case string_type:
00076           tmp = new CValue<std::string> ;
00077           ((CValue<std::string>*) tmp)->Set("");
00078           break;
00079 
00080      default:
00081 
00082           //std::cerr << "BUG: " << __FILE__ << ":" << __LINE__
00083           //   << " --> Queried for unknown CValue type " << newtype
00084           //   << std::endl;
00085           assert(false);
00086           break;
00087      }
00088 
00089      if (!tmp) {
00090           return NULL;
00091      }
00092 
00093      tmp->type = newtype;
00094      return tmp;
00095 }
00096 
00097 IValue::~IValue()
00098 {
00099 }