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 <pelib/RawData.hpp> 00022 #include <pelib/Matrix.hpp> 00023 #include <pelib/CastException.hpp> 00024 00025 #ifndef PELIB_RAWMATRIX 00026 #define PELIB_RAWMATRIX 00027 00028 #ifdef debug 00029 #undef debug 00030 #endif 00031 00032 #if 0 00033 #include <iostream> 00034 #define debug(var) std::cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << var << "\"" << std::endl; 00035 #else 00036 #define debug(var) 00037 #endif 00038 00039 using namespace std; 00040 00041 namespace pelib 00042 { 00044 template <class Col, class Row, class Value> 00045 class RawMatrix: public RawData 00046 { 00047 typedef std::map<Col, Value> RowType; 00048 typedef std::map<Row, RowType> MatrixType; 00049 00050 public: 00052 virtual 00053 RawMatrix* 00054 clone() const 00055 { 00056 return new RawMatrix(); 00057 } 00058 00060 virtual 00061 void 00062 dump(std::ostream &o, const AlgebraData *data) const 00063 { 00064 const Matrix<Col, Row, Value> *matrix = dynamic_cast<const Matrix<Col, Row, Value>*>(data); 00065 if(matrix == NULL) throw CastException("parameter \"data\" was not of type \"Matrix<Col, Row, Value>\"."); 00066 map<Col, map<Row, Value> > record = matrix->getValues(); 00067 for(typename map<Col, map<Row, Value> >::const_iterator i = record.begin(); i != record.end(); i++) 00068 { 00069 for(typename map<Row, Value>::const_iterator j = i->second.begin(); j != i->second.end(); j++) 00070 { 00071 o << j->second << " "; 00072 //cerr << i->first << " " << j->first << " " << j->second << " "; 00073 } 00074 00075 o << endl; 00076 } 00077 } 00078 00079 protected: 00080 private: 00081 }; 00082 } 00083 00084 #undef debug 00085 #endif