00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __MACCESSOR_HH
00021 #define __MACCESSOR_HH
00022
00023
00025
00026
00027
00029
00030 #define TOON_CHECK_ROW TOON_ASSERT(r < Rows && r >= 0, TooNError::BadRowIndex)
00031 #define TOON_CHECK_COL TOON_ASSERT(c < Cols && c >= 0, TooNError::BadColIndex)
00032
00033
00034
00035
00036 template <int Rows,int Cols, class AllocZone>
00037 class FixedMAccessor<Rows,Cols,RowMajor,AllocZone> : public AllocZone {
00038 public:
00039 inline FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) TOON_THROW {
00040 TOON_CHECK_ROW;
00041 return reinterpret_cast<FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(my_values[r*Cols]);
00042 }
00043 inline const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) const TOON_THROW {
00044 TOON_CHECK_ROW;
00045 return reinterpret_cast<const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(my_values[r*Cols]);
00046 }
00047
00048 inline double& operator()(int r, int c) TOON_THROW {
00049 TOON_CHECK_ROW;
00050 TOON_CHECK_COL;
00051 return my_values[r*Cols+c];
00052 }
00053
00054 inline const double& operator()(int r, int c) const TOON_THROW
00055 {
00056 TOON_CHECK_ROW;
00057 TOON_CHECK_COL;
00058 return my_values[r*Cols+c];
00059 }
00060
00061 static inline int num_rows() throw() {return Rows;}
00062 static inline int num_cols() throw() {return Cols;}
00063 static inline int num_skip() throw() {return Cols;}
00064 typedef RowMajor layout;
00065
00066
00067 inline FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >& T() {
00068 return reinterpret_cast<FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >&>(*my_values);
00069 }
00070 inline const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >& T() const {
00071 return reinterpret_cast<const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >&>(*my_values);
00072 }
00073
00074
00075 template<int Rstart, int Cstart, int Rsize, int Csize>
00076 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >& slice(){
00077 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >&>
00078 (my_values[Rstart*Cols+Cstart]);
00079 }
00080
00081 template<int Rstart, int Cstart, int Rsize, int Csize>
00082 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >& slice() const {
00083 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >&>
00084 (my_values[Rstart*Cols+Cstart]);
00085 }
00086 };
00087
00088
00089
00090 template <int Rows,int Cols, class AllocZone>
00091 class FixedMAccessor<Rows,Cols,ColMajor,AllocZone> : public AllocZone {
00092 public:
00093 FixedVector<Cols, SkipAccessor<Cols, Rows> >& operator[](int r) TOON_THROW{
00094 TOON_CHECK_ROW;
00095 return reinterpret_cast<FixedVector<Cols, SkipAccessor<Cols, Rows> >&>(my_values[r]);
00096 }
00097
00098 const FixedVector<Cols, SkipAccessor<Cols, Rows> >& operator[](int r) const TOON_THROW{
00099 TOON_CHECK_ROW;
00100 return reinterpret_cast<const FixedVector<Cols, SkipAccessor<Cols, Rows> >&>(my_values[r]);
00101 }
00102
00103 inline double& operator()(int r, int c) TOON_THROW
00104 {
00105 TOON_CHECK_ROW;
00106 TOON_CHECK_COL;
00107 return my_values[c*Rows+r];
00108 }
00109
00110 inline const double& operator()(int r, int c)const TOON_THROW
00111 {
00112 TOON_CHECK_ROW;
00113 TOON_CHECK_COL;
00114 return my_values[c*Rows+r];
00115 }
00116
00117 static inline int num_rows(){return Rows;}
00118 static inline int num_cols(){return Cols;}
00119 static inline int num_skip(){return Rows;}
00120 typedef ColMajor layout;
00121
00122
00123 inline FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >& T() {
00124 return reinterpret_cast<FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >&>(*my_values);
00125 }
00126 inline const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >& T() const {
00127 return reinterpret_cast<const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >&>(*my_values);
00128 }
00129
00130
00131 template<int Rstart, int Cstart, int Rsize, int Csize>
00132 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >& slice(){
00133 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >&>
00134 (my_values[Cstart*Rows+Rstart]);
00135 }
00136
00137 template<int Rstart, int Cstart, int Rsize, int Csize>
00138 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >& slice()const{
00139 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >&>
00140 (my_values[Cstart*Rows+Rstart]);
00141 }
00142 };
00143
00144
00145
00146
00147
00148 template<int Rows, int Cols, int Skip>
00149 class SkipMAccessor<Rows,Cols,Skip,RowMajor> {
00150 public:
00151 inline FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) TOON_THROW{
00152 TOON_CHECK_ROW;
00153 return reinterpret_cast<FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(my_values[r*Skip]);
00154 }
00155 inline const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) const TOON_THROW{
00156 TOON_CHECK_ROW;
00157 return reinterpret_cast<const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(my_values[r*Skip]);
00158 }
00159
00160 inline double& operator()(int r, int c) TOON_THROW
00161 {
00162 TOON_CHECK_ROW;
00163 TOON_CHECK_COL;
00164 return my_values[r*Skip+c];
00165 }
00166
00167 inline const double& operator()(int r, int c) const TOON_THROW
00168 {
00169 TOON_CHECK_ROW;
00170 TOON_CHECK_COL;
00171 return my_values[r*Skip+c];
00172 }
00173
00174 static inline int num_rows(){return Rows;}
00175 static inline int num_cols(){return Cols;}
00176 static inline int num_skip(){return Skip;}
00177 typedef RowMajor layout;
00178
00179
00180 inline FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >& T() {
00181 return reinterpret_cast<FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >&>(*this);
00182 }
00183
00184 inline const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >& T() const {
00185 return reinterpret_cast<const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >&>(*this);
00186 }
00187
00188
00189 template<int Rstart, int Cstart, int Rsize, int Csize>
00190 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >& slice(){
00191 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >&>
00192 (my_values[Rstart*Skip+Cstart]);
00193 }
00194
00195 template<int Rstart, int Cstart, int Rsize, int Csize>
00196 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >& slice() const {
00197 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >&>
00198 (my_values[Rstart*Skip+Cstart]);
00199 }
00200
00201 protected:
00202 double my_values[Rows*Skip];
00203 };
00204
00205 template<int Rows, int Cols, int Skip>
00206 class SkipMAccessor<Rows, Cols, Skip, ColMajor> {
00207 public:
00208
00209 inline FixedVector<Cols, SkipAccessor<Cols, Skip> >& operator[](int r) TOON_THROW
00210 {
00211 TOON_CHECK_ROW;
00212 return reinterpret_cast<FixedVector<Cols, SkipAccessor<Cols, Skip> >&>(my_values[r]);
00213 }
00214
00215 inline const FixedVector<Cols, SkipAccessor<Cols, Skip> >& operator[](int r) const TOON_THROW{
00216 TOON_CHECK_ROW;
00217 return reinterpret_cast<const FixedVector<Cols, SkipAccessor<Cols, Skip> >&>(my_values[r]);
00218 }
00219
00220 inline double& operator()(int r, int c) TOON_THROW
00221 {
00222 TOON_CHECK_ROW;
00223 TOON_CHECK_COL;
00224 return my_values[c*Skip+r];
00225 }
00226
00227 inline const double& operator()(int r, int c)const TOON_THROW
00228 {
00229 TOON_CHECK_ROW;
00230 TOON_CHECK_COL;
00231 return my_values[c*Skip+r];
00232 }
00233
00234 static inline int num_rows(){return Rows;}
00235 static inline int num_cols(){return Cols;}
00236 static inline int num_skip(){return Skip;}
00237 typedef ColMajor layout;
00238
00239
00240 inline FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >& T() {
00241 return reinterpret_cast<FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >&>(*this);
00242 }
00243
00244 inline const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >& T() const {
00245 return reinterpret_cast<const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >&>(*this);
00246 }
00247
00248
00249 template<int Rstart, int Cstart, int Rsize, int Csize>
00250 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >& slice(){
00251 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >&>
00252 (my_values[Cstart*Skip+Rstart]);
00253 }
00254
00255 template<int Rstart, int Cstart, int Rsize, int Csize>
00256 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >& slice()const{
00257 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >&>
00258 (my_values[Cstart*Skip+Rstart]);
00259 }
00260
00261 protected:
00262 double my_values[Cols*Skip];
00263 };
00264
00265
00267
00268
00269
00271 #undef TOON_CHECK_ROW
00272 #undef TOON_CHECK_COL
00273 #define TOON_CHECK_ROW TOON_ASSERT(r < my_rows && r >= 0, TooNError::BadRowIndex)
00274 #define TOON_CHECK_COL TOON_ASSERT(c < my_cols && c >= 0, TooNError::BadColIndex)
00275
00276 template <>
00277 class DynamicMAccessor<RowMajor> {
00278 public:
00279 const RefVector operator[](int r) const TOON_THROW{
00280 TOON_CHECK_ROW;
00281 return RefVector(my_num_cols,my_values+r*my_num_cols);
00282 }
00283
00284 RefVector operator[](int r) TOON_THROW{
00285 TOON_CHECK_ROW;
00286 return RefVector(my_num_cols,my_values+r*my_num_cols);
00287 }
00288
00289 inline double& operator()(int r, int c)TOON_THROW
00290 {
00291 TOON_CHECK_ROW;
00292 TOON_CHECK_COL;
00293 return my_values[r*my_num_cols+c];
00294 }
00295
00296 inline const double& operator()(int r, int c)const TOON_THROW
00297 {
00298 TOON_CHECK_ROW;
00299 TOON_CHECK_COL;
00300 return my_values[r*my_num_cols+c];
00301 }
00302
00303 int num_rows()const{return my_num_rows;}
00304 int num_cols()const{return my_num_cols;}
00305 int num_skip()const{return my_num_cols;}
00306 typedef RowMajor layout;
00307
00308 inline DynamicMatrix<DynamicMAccessor<ColMajor> >& T() {
00309 return reinterpret_cast<DynamicMatrix<DynamicMAccessor<ColMajor> >&>(*this);
00310 }
00311 inline const DynamicMatrix<DynamicMAccessor<ColMajor> >& T() const {
00312 return reinterpret_cast<const DynamicMatrix<DynamicMAccessor<ColMajor> >&>(*this);
00313 }
00314
00315 protected:
00316 int my_num_rows;
00317 int my_num_cols;
00318 double* my_values;
00319 };
00320
00321 template <>
00322 class DynamicMAccessor<ColMajor> {
00323 public:
00324 const RefSkipVector operator[](int r) const TOON_THROW{
00325 TOON_CHECK_ROW;
00326 return RefSkipVector(my_num_cols,my_num_rows,my_values+r);
00327 }
00328
00329 RefSkipVector operator[](int r) TOON_THROW
00330 {
00331 TOON_CHECK_ROW;
00332 return RefSkipVector(my_num_cols,my_num_rows,my_values+r);
00333 }
00334
00335 inline double& operator()(int r, int c) TOON_THROW
00336 {
00337 TOON_CHECK_ROW;
00338 TOON_CHECK_COL;
00339 return my_values[c*my_num_rows+r];
00340 }
00341
00342 inline const double& operator()(int r, int c)const TOON_THROW
00343 {
00344 TOON_CHECK_ROW;
00345 TOON_CHECK_COL;
00346 return my_values[c*my_num_rows+r];
00347 }
00348
00349 int num_rows()const{return my_num_rows;}
00350 int num_cols()const{return my_num_cols;}
00351 int num_skip()const{return my_num_rows;}
00352 typedef ColMajor layout;
00353
00354 inline DynamicMatrix<DynamicMAccessor<RowMajor> >& T() {
00355 return reinterpret_cast<DynamicMatrix<DynamicMAccessor<RowMajor> >&>(*this);
00356 }
00357 inline const DynamicMatrix<DynamicMAccessor<RowMajor> >& T() const {
00358 return reinterpret_cast<const DynamicMatrix<DynamicMAccessor<RowMajor> >&>(*this);
00359 }
00360
00361 protected:
00362 int my_num_cols;
00363 int my_num_rows;
00364 double* my_values;
00365 };
00366
00368
00369 template <>
00370 class RefSkipMAccessor<RowMajor> {
00371 friend class RefSkipVector;
00372 public:
00373 RefSkipMAccessor(){};
00374
00375 const RefVector operator[](int r) const TOON_THROW{
00376 TOON_CHECK_ROW;
00377 return RefVector(my_num_cols,my_values+r*my_skip);
00378 }
00379
00380 RefVector operator[](int r) TOON_THROW{
00381 TOON_CHECK_ROW;
00382 return RefVector(my_num_cols,my_values+r*my_skip);
00383 }
00384
00385 inline double& operator()(int r, int c) TOON_THROW{
00386 TOON_CHECK_ROW;
00387 TOON_CHECK_COL;
00388 return my_values[r*my_skip+c];
00389 }
00390
00391 inline const double& operator()(int r, int c) const TOON_THROW {
00392 TOON_CHECK_ROW;
00393 TOON_CHECK_COL;
00394 return my_values[r*my_skip+c];
00395 }
00396
00397 int num_rows()const{return my_num_rows;}
00398 int num_cols()const{return my_num_cols;}
00399 int num_skip()const{return my_skip;}
00400 typedef RowMajor layout;
00401
00402 inline DynamicMatrix<RefSkipMAccessor<ColMajor> >& T() {
00403 return reinterpret_cast<DynamicMatrix<RefSkipMAccessor<ColMajor> >&>(*this);
00404 }
00405
00406 inline const DynamicMatrix<RefSkipMAccessor<ColMajor> >& T() const {
00407 return reinterpret_cast<const DynamicMatrix<RefSkipMAccessor<ColMajor> >&>(*this);
00408 }
00409
00410
00411 protected:
00412 int my_num_rows;
00413 int my_num_cols;
00414 int my_skip;
00415 double* my_values;
00416 };
00417
00418 template <>
00419 class RefSkipMAccessor<ColMajor> {
00420 friend class RefSkipVector;
00421 public:
00422 RefSkipMAccessor(){};
00423
00424 const RefSkipVector operator[](int r) const TOON_THROW{
00425 TOON_CHECK_ROW;
00426 return RefSkipVector(my_num_cols,my_skip,my_values+r);
00427 }
00428
00429 RefSkipVector operator[](int r) TOON_THROW{
00430 TOON_CHECK_ROW;
00431 return RefSkipVector(my_num_cols,my_skip,my_values+r);
00432 }
00433
00434 inline double& operator()(int r, int c) TOON_THROW
00435 {
00436 TOON_CHECK_ROW;
00437 TOON_CHECK_COL;
00438 return my_values[c*my_skip+r];
00439 }
00440
00441 inline const double& operator()(int r, int c) const TOON_THROW
00442 {
00443 TOON_CHECK_ROW;
00444 TOON_CHECK_COL;
00445 return my_values[c*my_skip+r];
00446
00447 int num_rows()const{return my_num_rows;}
00448 int num_cols()const{return my_num_cols;}
00449 int num_skip()const{return my_skip;}
00450 typedef ColMajor layout;
00451
00452 inline DynamicMatrix<RefSkipMAccessor<RowMajor> >& T() {
00453 return reinterpret_cast<DynamicMatrix<RefSkipMAccessor<RowMajor> >&>(*this);
00454 }
00455
00456 inline const DynamicMatrix<RefSkipMAccessor<RowMajor> >& T() const {
00457 return reinterpret_cast<const DynamicMatrix<RefSkipMAccessor<RowMajor> >&>(*this);
00458 }
00459
00460
00461 protected:
00462 int my_num_cols;
00463 int my_num_rows;
00464 int my_skip;
00465 double* my_values;
00466 };
00467
00468
00469
00470
00471 #undef TOON_CHECK_ROW
00472 #undef TOON_CHECK_COL
00473
00474
00475 #endif