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 #include <map> 00029 #include <set> 00030 00031 #include <pelib/AlgebraData.hpp> 00032 #include <pelib/Record.hpp> 00033 #include <pelib/constraints.hpp> 00034 00035 #ifndef PELIB_ALGEBRA 00036 #define PELIB_ALGEBRA 00037 namespace pelib 00038 { 00042 class Algebra : public Record 00043 { 00044 public: 00046 Algebra(); 00047 00049 Algebra(const std::map<std::string, const AlgebraData * const> &elements); 00050 00052 Algebra(const Algebra &rhs); 00053 Algebra(const Algebra *rhs); 00054 00056 virtual ~Algebra(); 00057 00059 const std::map<std::string, const AlgebraData * const>& 00060 getAllRecords() const; 00061 00063 virtual Algebra 00064 merge(const Algebra&) const; 00065 00066 00068 template<class T> 00069 std::map<std::string, const T* const> 00070 getRecords() const 00071 { 00072 // Make sure T is derived from AlgebraData 00073 Derived_from<T, AlgebraData>(); 00074 00075 // Build a new map containing all elements from records that could be casted to Algebra 00076 std::map<std::string, const T * const> record; 00077 00078 for (std::map<std::string, const AlgebraData * const>::const_iterator i = records.begin(); i != records.end(); i++) 00079 { 00080 // Try to cast this type 00081 00082 00083 const AlgebraData *ptr = i->second; 00084 00085 T* elem = dynamic_cast<T*>(ptr); 00086 00087 if(elem != NULL) 00088 { 00089 record.insert(std::pair<std::string, const T * const>(i->first, elem)); 00090 } 00091 } 00092 00093 return record; 00094 } 00095 00097 template<class T> 00098 const T * const 00099 find(std::string key) const 00100 { 00101 // Make sure T is derived from AlgebraData 00102 Derived_from<T, AlgebraData>(); 00103 00104 typename std::map<std::string, const AlgebraData * const>::const_iterator iter = records.find(key); 00105 if(iter != records.end()) 00106 { 00107 const T * const elem = dynamic_cast<const T * const >(iter->second); 00108 00109 if(elem != NULL) 00110 { 00111 return elem; 00112 } 00113 else 00114 { 00115 return NULL; 00116 } 00117 } 00118 else 00119 { 00120 return NULL; 00121 } 00122 } 00123 00125 Algebra filter(const std::set<std::string> &list) const; 00126 00128 void insert(const Data *data) {} 00129 00131 virtual void insert(const pelib::AlgebraData *data); 00132 00134 virtual void 00135 remove(const std::string name); 00136 00138 virtual 00139 Algebra& 00140 operator=(const Algebra &rhs); 00141 00142 virtual Algebra* clone() const; 00143 00144 protected: 00146 std::map<std::string, const AlgebraData * const> records; 00147 00149 void 00150 deleteRecords(); 00151 private: 00152 }; 00153 } 00154 00155 #endif