Go to the documentation of this file.00001
00002
00003
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _CHOMP_STRUCT_FLATMATR_H_
00037 #define _CHOMP_STRUCT_FLATMATR_H_
00038
00039 #include <new>
00040
00041 namespace chomp {
00042 namespace homology {
00043
00044
00045
00046
00047
00048
00054 template <class element>
00055 class flatMatrix
00056 {
00057 public:
00061 flatMatrix (int size): n (size), tab (new element [n * n]) {return;}
00062
00064 flatMatrix (const flatMatrix<element> &M):
00065 n (M. n), tab (new element [n * n])
00066 {
00067 int memSize = n * n;
00068 for (int i = 0; i < memSize; ++ i)
00069 tab [i] = M. tab [i];
00070 return;
00071 }
00072
00075 flatMatrix &operator = (const flatMatrix<element> &M)
00076 {
00077 if (n != M. n)
00078 throw "Different matrix sizes in operator =.";
00079 int memSize = n * n;
00080 for (int i = 0; i < memSize; ++ i)
00081 tab [i] = M. tab [i];
00082 return *this;
00083 }
00084
00086 ~flatMatrix () {delete [] tab;}
00087
00089 class row
00090 {
00091 public:
00093 row (int _offset, element *_v):
00094 offset (_offset), v (_v) {}
00095
00097 element &operator [] (int j) {return v [offset + j];}
00098
00099 protected:
00102 int offset;
00103
00106 element *v;
00107 };
00108
00110 row operator [] (int i)
00111 {return row (n * i, tab);}
00112
00114 class const_row
00115 {
00116 public:
00118 const_row (int _offset, const element *_v):
00119 offset (_offset), v (_v) {}
00120
00122 const element &operator [] (int m) {return v [offset + m];}
00123
00124 protected:
00127 int offset;
00128
00131 const element *v;
00132 };
00133
00135 const_row operator [] (int i ) const
00136 {return const_row (n * i, tab);}
00137
00139 void clear (const element &elem)
00140 {
00141 int size = n * n;
00142 for (int i = 0; i < size; ++ i)
00143 tab [i] = elem;
00144 return;
00145 }
00146
00148 void swap (flatMatrix<element> &M)
00149 {
00150 int this_n = n;
00151 element *this_tab = tab;
00152 n = M. n;
00153 tab = M. tab;
00154 M. n = this_n;
00155 M. tab = this_tab;
00156 return;
00157 }
00158
00161 const element *memory () const {return tab;}
00162
00165 element *memory () {return tab;}
00166
00167 protected:
00169 int n;
00170
00172 element *tab;
00173
00174 };
00175
00176
00177 }
00178 }
00179
00180 #endif // _CHOMP_STRUCT_FLATMATR_H_
00181
00183