pelib
2.0.0
|
00001 /* 00002 Copyright 2015 Nicolas Melot 00003 00004 This file is part of Pelib. 00005 00006 Pelib is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 Pelib is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with Pelib. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 #include <iostream> 00022 #include <cstdlib> 00023 #include <fstream> 00024 #include <sstream> 00025 #include <string> 00026 #include <boost/regex.hpp> 00027 #include <iomanip> 00028 00029 #include <pelib/AlgebraData.hpp> 00030 #include <pelib/PelibException.hpp> 00031 00032 #ifndef PELIB_SCALAR 00033 #define PELIB_SCALAR 00034 00035 namespace pelib 00036 { 00038 template <class Value> 00039 class Scalar: public AlgebraData 00040 { 00041 public: 00043 Scalar(const std::string name, const Value value, precision prec = leave) : AlgebraData(name, prec) 00044 { 00045 this->value = value; 00046 } 00047 00049 Scalar(const Scalar<Value>* scalar) : AlgebraData(scalar->getName(), scalar->getPrecision()) 00050 { 00051 // Do nothing 00052 } 00053 00055 virtual 00056 Scalar* 00057 clone() const 00058 { 00059 return new Scalar<Value>(name, value, prec); 00060 } 00061 00063 virtual 00064 const Value& 00065 getValue() const 00066 { 00067 return value; 00068 } 00069 00070 void 00071 merge(const AlgebraData* ptr) 00072 { 00073 // Only allow merging if both this and ptr are of same name and type 00074 if(ptr->getName().compare(this->getName()) == 0 && std::string(typeid(*ptr).name()).compare(typeid(Scalar<Value>).name()) == 0) 00075 { 00076 Scalar<Value> *scalar = (Scalar<Value>*)ptr; 00077 this->value = scalar->getValue(); 00078 } 00079 else 00080 { 00081 throw PelibException(std::string("Cannot merge data \"") + ptr->getName() + "\" with " + typeid(Value).name() + " scalar of name \"" + this->getName() + "\"."); 00082 } 00083 } 00084 protected: 00086 Value value; 00087 private: 00088 }; 00089 } 00090 00091 #endif