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
00031
00032
00033
00035 #define TOON_CHECK_ROW TOON_ASSERT(r < my_num_rows && r >= 0, TooNError::BadRowIndex)
00036 #define TOON_CHECK_COL TOON_ASSERT(c < my_num_cols && c >= 0, TooNError::BadColIndex)
00037
00038
00040
00041 template <>
00042 class RefSkipMAccessor<RowMajor> {
00043 public:
00044 typedef DynamicMatrix<RefSkipMAccessor<RowMajor> > RefSkipMatrixRM;
00045 RefSkipMAccessor(){};
00046
00047 const RefVector operator[](int r) const TOON_THROW{
00048 TOON_CHECK_ROW;
00049 return makeRefVector(my_num_cols,this->my_values+r*my_skip);
00050 }
00051
00052 RefVector operator[](int r) TOON_THROW{
00053 TOON_CHECK_ROW;
00054 return makeRefVector(my_num_cols,this->my_values+r*my_skip);
00055 }
00056
00057 inline double& operator()(int r, int c) TOON_THROW{
00058 TOON_CHECK_ROW;
00059 TOON_CHECK_COL;
00060 return this->my_values[r*my_skip+c];
00061 }
00062
00063 inline const double& operator()(int r, int c) const TOON_THROW{
00064 TOON_CHECK_ROW;
00065 TOON_CHECK_COL;
00066 return this->my_values[r*my_skip+c];
00067 }
00068
00069 int num_rows()const throw() {return my_num_rows;}
00070 int num_cols()const throw() {return my_num_cols;}
00071 int num_skip()const throw() {return my_skip;}
00072 typedef RowMajor layout;
00073
00074 inline DynamicMatrix<RefSkipMAccessor<ColMajor> >& T() {
00075 return reinterpret_cast<DynamicMatrix<RefSkipMAccessor<ColMajor> >&>(*this);
00076 }
00077
00078 inline const DynamicMatrix<RefSkipMAccessor<ColMajor> >& T() const {
00079 return reinterpret_cast<const DynamicMatrix<RefSkipMAccessor<ColMajor> >&>(*this);
00080 }
00081
00082
00083 template<int Rstart, int Cstart, int Rsize, int Csize>
00084 inline RefSkipMatrixRM slice(){
00085 RefSkipMatrixRM ret;
00086 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart*this->my_skip + Cstart);
00087 return ret;
00088 }
00089
00090 template<int Rstart, int Cstart, int Rsize, int Csize>
00091 inline const RefSkipMatrixRM slice() const {
00092 RefSkipMatrixRM ret;
00093 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart*this->my_skip + Cstart);
00094 return ret;
00095 }
00096
00097 inline RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00098 RefSkipMatrixRM ret;
00099 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart*this->my_skip + Cstart);
00100 return ret;
00101 }
00102
00103 inline const RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00104 RefSkipMatrixRM ret;
00105 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart*this->my_skip + Cstart);
00106 return ret;
00107 }
00108 inline void set(int nr, int nc, int sk, double* v) { my_num_rows = nr; my_num_cols = nc; my_skip = sk; my_values = v; }
00109 protected:
00110 int my_num_rows;
00111 int my_num_cols;
00112 int my_skip;
00113 double* my_values;
00114 };
00115
00116 template <>
00117 class RefSkipMAccessor<ColMajor> {
00118 public:
00119 typedef DynamicMatrix<RefSkipMAccessor<ColMajor> > RefSkipMatrixCM;
00120
00121 RefSkipMAccessor(){};
00122
00123 const RefSkipVector operator[](int r) const TOON_THROW{
00124 TOON_CHECK_ROW;
00125 return makeRefSkipVector(my_num_cols,my_skip,this->my_values+r);
00126 }
00127
00128 RefSkipVector operator[](int r) TOON_THROW{
00129 TOON_CHECK_ROW;
00130 return makeRefSkipVector(my_num_cols,my_skip,this->my_values+r);
00131 }
00132
00133 inline double& operator()(int r, int c) TOON_THROW
00134 {
00135 TOON_CHECK_ROW;
00136 TOON_CHECK_COL;
00137 return this->my_values[c*my_skip+r];
00138 }
00139
00140 inline const double& operator()(int r, int c)const TOON_THROW
00141 {
00142 TOON_CHECK_ROW;
00143 TOON_CHECK_COL;
00144 return this->my_values[c*my_skip+r];
00145 }
00146
00147
00148 int num_rows()const throw() {return my_num_rows;}
00149 int num_cols()const throw() {return my_num_cols;}
00150 int num_skip()const throw() {return my_skip;}
00151 typedef ColMajor layout;
00152
00153 inline DynamicMatrix<RefSkipMAccessor<RowMajor> >& T() {
00154 return reinterpret_cast<DynamicMatrix<RefSkipMAccessor<RowMajor> >&>(*this);
00155 }
00156
00157 inline const DynamicMatrix<RefSkipMAccessor<RowMajor> >& T() const {
00158 return reinterpret_cast<const DynamicMatrix<RefSkipMAccessor<RowMajor> >&>(*this);
00159 }
00160
00161
00162 template<int Rstart, int Cstart, int Rsize, int Csize>
00163 inline RefSkipMatrixCM slice(){
00164 RefSkipMatrixCM ret;
00165 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart + Cstart*this->my_skip);
00166 return ret;
00167 }
00168
00169 template<int Rstart, int Cstart, int Rsize, int Csize>
00170 inline const RefSkipMatrixCM slice() const {
00171 RefSkipMatrixCM ret;
00172 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart + Cstart*this->my_skip);
00173 return ret;
00174 }
00175
00176 inline RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00177 RefSkipMatrixCM ret;
00178 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart + Cstart*this->my_skip);
00179 return ret;
00180 }
00181
00182 inline const RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00183 RefSkipMatrixCM ret;
00184 ret.set(Rsize, Csize, this->my_skip, this->my_values + Rstart + Cstart*this->my_skip);
00185 return ret;
00186 }
00187 inline void set(int nr, int nc, int sk, double* v) { my_num_rows = nr; my_num_cols = nc; my_skip = sk; my_values = v; }
00188
00189 protected:
00190 int my_num_cols;
00191 int my_num_rows;
00192 int my_skip;
00193 double* my_values;
00194 };
00195
00196 typedef RefSkipMAccessor<RowMajor>::RefSkipMatrixRM RefSkipMatrixRM;
00197 typedef RefSkipMAccessor<ColMajor>::RefSkipMatrixCM RefSkipMatrixCM;
00198 inline RefSkipMatrixRM makeRefSkipMatrixRM(int nr, int nc, int sk, double* v) { RefSkipMatrixRM ret; ret.set(nr,nc,sk,v); return ret; }
00199 inline RefSkipMatrixCM makeRefSkipMatrixCM(int nr, int nc, int sk, double* v) { RefSkipMatrixCM ret; ret.set(nr,nc,sk,v); return ret; }
00200
00201 template <>
00202 class DynamicMAccessor<RowMajor> {
00203 public:
00204 const RefVector operator[](int r) const TOON_THROW{
00205 TOON_CHECK_ROW;
00206 return makeRefVector(my_num_cols,this->my_values+r*my_num_cols);
00207 }
00208
00209 RefVector operator[](int r) TOON_THROW{
00210 TOON_CHECK_ROW;
00211 return makeRefVector(my_num_cols,this->my_values+r*my_num_cols);
00212 }
00213
00214 inline double& operator()(int r, int c)TOON_THROW
00215 {
00216 TOON_CHECK_ROW;
00217 TOON_CHECK_COL;
00218 return this->my_values[r*my_num_cols+c];
00219 }
00220
00221 inline const double& operator()(int r, int c)const TOON_THROW
00222 {
00223 TOON_CHECK_ROW;
00224 TOON_CHECK_COL;
00225 return this->my_values[r*my_num_cols+c];
00226 }
00227
00228 int num_rows()const throw() {return my_num_rows;}
00229 int num_cols()const throw() {return my_num_cols;}
00230 int num_skip()const throw() {return my_num_cols;}
00231 typedef RowMajor layout;
00232
00233 inline DynamicMatrix<DynamicMAccessor<ColMajor> >& T() {
00234 return reinterpret_cast<DynamicMatrix<DynamicMAccessor<ColMajor> >&>(*this);
00235 }
00236 inline const DynamicMatrix<DynamicMAccessor<ColMajor> >& T() const {
00237 return reinterpret_cast<const DynamicMatrix<DynamicMAccessor<ColMajor> >&>(*this);
00238 }
00239
00240
00241 template<int Rstart, int Cstart, int Rsize, int Csize>
00242 inline RefSkipMatrixRM slice(){
00243 return makeRefSkipMatrixRM(Rsize, Csize, this->my_num_cols, this->my_values + Rstart*this->my_num_cols + Cstart);
00244 }
00245
00246 template<int Rstart, int Cstart, int Rsize, int Csize>
00247 inline const RefSkipMatrixRM slice() const {
00248 return makeRefSkipMatrixRM(Rsize, Csize, this->my_num_cols, this->my_values + Rstart*this->my_num_cols + Cstart);
00249 }
00250
00251 inline RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00252 return makeRefSkipMatrixRM(Rsize, Csize, this->my_num_cols, this->my_values + Rstart*this->my_num_cols + Cstart);
00253 }
00254
00255 inline const RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00256 return makeRefSkipMatrixRM(Rsize, Csize, this->my_num_cols, this->my_values + Rstart*this->my_num_cols + Cstart);
00257 }
00258 inline void set(int nr, int nc, double* v) { my_num_rows = nr; my_num_cols = nc; my_values = v; }
00259 protected:
00260 int my_num_rows;
00261 int my_num_cols;
00262 double* my_values;
00263 };
00264
00265 template <>
00266 class DynamicMAccessor<ColMajor> {
00267 public:
00268 const RefSkipVector operator[](int r) const TOON_THROW{
00269 TOON_CHECK_ROW;
00270 return makeRefSkipVector(my_num_cols,my_num_rows,this->my_values+r);
00271 }
00272
00273 RefSkipVector operator[](int r) TOON_THROW
00274 {
00275 TOON_CHECK_ROW;
00276 return makeRefSkipVector(my_num_cols,my_num_rows,this->my_values+r);
00277 }
00278
00279 inline double& operator()(int r, int c) TOON_THROW
00280 {
00281 TOON_CHECK_ROW;
00282 TOON_CHECK_COL;
00283 return this->my_values[c*my_num_rows+r];
00284 }
00285
00286 inline const double& operator()(int r, int c)const TOON_THROW
00287 {
00288 TOON_CHECK_ROW;
00289 TOON_CHECK_COL;
00290 return this->my_values[c*my_num_rows+r];
00291 }
00292
00293 int num_rows()const throw() {return my_num_rows;}
00294 int num_cols()const throw() {return my_num_cols;}
00295 int num_skip()const throw() {return my_num_rows;}
00296 typedef ColMajor layout;
00297
00298 inline DynamicMatrix<DynamicMAccessor<RowMajor> >& T() {
00299 return reinterpret_cast<DynamicMatrix<DynamicMAccessor<RowMajor> >&>(*this);
00300 }
00301 inline const DynamicMatrix<DynamicMAccessor<RowMajor> >& T() const {
00302 return reinterpret_cast<const DynamicMatrix<DynamicMAccessor<RowMajor> >&>(*this);
00303 }
00304
00305
00306 template<int Rstart, int Cstart, int Rsize, int Csize>
00307 inline RefSkipMatrixCM slice(){
00308 return makeRefSkipMatrixCM(Rsize, Csize, this->my_num_rows, this->my_values + Rstart + Cstart*this->my_num_rows);
00309 }
00310
00311 template<int Rstart, int Cstart, int Rsize, int Csize>
00312 inline const RefSkipMatrixCM slice() const {
00313 return makeRefSkipMatrixCM(Rsize, Csize, this->my_num_rows, this->my_values + Rstart + Cstart*this->my_num_rows);
00314 }
00315
00316 inline RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00317 return makeRefSkipMatrixCM(Rsize, Csize, this->my_num_rows, this->my_values + Rstart + Cstart*this->my_num_rows);
00318 }
00319
00320 inline const RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00321 return makeRefSkipMatrixCM(Rsize, Csize, this->my_num_rows, this->my_values + Rstart + Cstart*this->my_num_rows);
00322 }
00323
00324 inline void set(int nr, int nc, double* v) { my_num_rows = nr; my_num_cols = nc; my_values = v; }
00325 protected:
00326 int my_num_cols;
00327 int my_num_rows;
00328 double* my_values;
00329 };
00330
00331 typedef DynamicMatrix<DynamicMAccessor<RowMajor> > RefMatrixRM;
00332 typedef DynamicMatrix<DynamicMAccessor<ColMajor> > RefMatrixCM;
00333 inline RefMatrixRM makeRefMatrixRM(int nr, int nc, double* v) { RefMatrixRM ret; ret.set(nr,nc,v); return ret; }
00334 inline RefMatrixCM makeRefMatrixCM(int nr, int nc, double* v) { RefMatrixCM ret; ret.set(nr,nc,v); return ret; }
00335
00336 #undef TOON_CHECK_ROW
00337 #undef TOON_CHECK_COL
00338 #define TOON_CHECK_ROW TOON_ASSERT(r < Rows && r >= 0, TooNError::BadRowIndex)
00339 #define TOON_CHECK_COL TOON_ASSERT(c < Cols && c >= 0, TooNError::BadColIndex)
00340
00341
00342
00343
00344 template<int Rows, int Cols, int Skip>
00345 class SkipMAccessor<Rows,Cols,Skip,RowMajor> {
00346 public:
00347 inline FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) TOON_THROW{
00348 TOON_CHECK_ROW;
00349 return reinterpret_cast<FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(this->my_values[r*Skip]);
00350 }
00351 inline const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) const TOON_THROW{
00352 TOON_CHECK_ROW;
00353 return reinterpret_cast<const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(this->my_values[r*Skip]);
00354 }
00355
00356 inline double& operator()(int r, int c) TOON_THROW
00357 {
00358 TOON_CHECK_ROW;
00359 TOON_CHECK_COL;
00360 return this->my_values[r*Skip+c];
00361 }
00362
00363 inline const double& operator()(int r, int c) const TOON_THROW
00364 {
00365 TOON_CHECK_ROW;
00366 TOON_CHECK_COL;
00367 return this->my_values[r*Skip+c];
00368 }
00369
00370 static inline int num_rows() throw() {return Rows;}
00371 static inline int num_cols() throw() {return Cols;}
00372 static inline int num_skip() throw() {return Skip;}
00373 typedef RowMajor layout;
00374
00375
00376 inline FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >& T() {
00377 return reinterpret_cast<FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >&>(*this);
00378 }
00379
00380 inline const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >& T() const {
00381 return reinterpret_cast<const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,ColMajor> >&>(*this);
00382 }
00383
00384
00385 template<int Rstart, int Cstart, int Rsize, int Csize>
00386 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >& slice() {
00387 FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >::dummy();
00388 util::Assert<(Rstart+Rsize <= Rows)>();
00389 util::Assert<(Cstart+Csize <= Cols)>();
00390 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >&>
00391 (this->my_values[Rstart*Skip+Cstart]);
00392 }
00393
00394 template<int Rstart, int Cstart, int Rsize, int Csize>
00395 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >& slice() const {
00396 FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >::dummy();
00397 util::Assert<(Rstart+Rsize <= Rows)>();
00398 util::Assert<(Cstart+Csize <= Cols)>();
00399 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,RowMajor> >&>
00400 (this->my_values[Rstart*Skip+Cstart]);
00401 }
00402
00403 inline RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00404 return makeRefSkipMatrixRM(Rsize, Csize, Skip, this->my_values + Rstart*Skip + Cstart);
00405 }
00406
00407 inline const RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00408 return makeRefSkipMatrixRM(Rsize, Csize, Skip, this->my_values + Rstart*Skip + Cstart);
00409 }
00410
00411
00412 protected:
00413 double my_values[Rows*Skip];
00414 };
00415
00416 template<int Rows, int Cols, int Skip>
00417 class SkipMAccessor<Rows, Cols, Skip, ColMajor> {
00418 public:
00419
00420 inline FixedVector<Cols, SkipAccessor<Cols, Skip> >& operator[](int r) TOON_THROW
00421 {
00422 TOON_CHECK_ROW;
00423 return reinterpret_cast<FixedVector<Cols, SkipAccessor<Cols, Skip> >&>(this->my_values[r]);
00424 }
00425
00426 inline const FixedVector<Cols, SkipAccessor<Cols, Skip> >& operator[](int r) const TOON_THROW{
00427 TOON_CHECK_ROW;
00428 return reinterpret_cast<const FixedVector<Cols, SkipAccessor<Cols, Skip> >&>(this->my_values[r]);
00429 }
00430
00431 inline double& operator()(int r, int c) TOON_THROW
00432 {
00433 TOON_CHECK_ROW;
00434 TOON_CHECK_COL;
00435 return my_values[c*Skip+r];
00436 }
00437
00438 inline const double& operator()(int r, int c)const TOON_THROW
00439 {
00440 TOON_CHECK_ROW;
00441 TOON_CHECK_COL;
00442 return this->my_values[c*Skip+r];
00443 }
00444
00445 static inline int num_rows() throw() {return Rows;}
00446 static inline int num_cols() throw() {return Cols;}
00447 static inline int num_skip() throw() {return Skip;}
00448 typedef ColMajor layout;
00449
00450
00451 inline FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >& T() {
00452 return reinterpret_cast<FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >&>(*this);
00453 }
00454
00455 inline const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >& T() const {
00456 return reinterpret_cast<const FixedMatrix<Cols,Rows,SkipMAccessor<Cols,Rows,Skip,RowMajor> >&>(*this);
00457 }
00458
00459
00460 template<int Rstart, int Cstart, int Rsize, int Csize>
00461 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >& slice(){
00462 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >&>
00463 (this->my_values[Cstart*Skip+Rstart]);
00464 }
00465
00466 template<int Rstart, int Cstart, int Rsize, int Csize>
00467 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >& slice()const{
00468 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Skip,ColMajor> >&>
00469 (this->my_values[Cstart*Skip+Rstart]);
00470 }
00471
00472 inline RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00473 return makeRefSkipMatrixCM(Rsize, Csize, Skip, this->my_values + Rstart + Cstart*Skip);
00474 }
00475
00476 inline const RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00477 return makeRefSkipMatrixCM(Rsize, Csize, Skip, this->my_values + Rstart + Cstart*Skip);
00478 }
00479
00480 protected:
00481 double my_values[Cols*Skip];
00482 };
00483
00484
00485 template <int Rows,int Cols, class AllocZone>
00486 class FixedMAccessor<Rows,Cols,RowMajor,AllocZone> : public AllocZone {
00487 public:
00488 inline FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) TOON_THROW {
00489 TOON_CHECK_ROW;
00490 return reinterpret_cast<FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(this->my_values[r*Cols]);
00491 }
00492 inline const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >& operator[](int r) const TOON_THROW {
00493 TOON_CHECK_ROW;
00494 return reinterpret_cast<const FixedVector<Cols,FixedVAccessor<Cols,Stack<Cols> > >&>(this->my_values[r*Cols]);
00495 }
00496
00497 inline double& operator()(int r, int c) TOON_THROW {
00498 TOON_CHECK_ROW;
00499 TOON_CHECK_COL;
00500 return this->my_values[r*Cols+c];
00501 }
00502
00503 inline const double& operator()(int r, int c) const TOON_THROW
00504 {
00505 TOON_CHECK_ROW;
00506 TOON_CHECK_COL;
00507 return this->my_values[r*Cols+c];
00508 }
00509
00510 static inline int num_rows() throw() {return Rows;}
00511 static inline int num_cols() throw() {return Cols;}
00512 static inline int num_skip() throw() {return Cols;}
00513 typedef RowMajor layout;
00514
00515
00516 inline FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >& T() {
00517 FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >::dummy();
00518 return reinterpret_cast<FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >&>(*this->my_values);
00519 }
00520 inline const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >& T() const {
00521 FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >::dummy();
00522 return reinterpret_cast<const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,ColMajor,Stack<Rows*Cols> > >&>(*this->my_values);
00523 }
00524
00525
00526 template<int Rstart, int Cstart, int Rsize, int Csize>
00527 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >& slice(){
00528 typedef FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> > ST;
00529 util::Assert<(Rstart+Rsize <= Rows)>();
00530 util::Assert<(Cstart+Csize <= Cols)>();
00531 ST::dummy();
00532 return reinterpret_cast<ST&>(this->my_values[Rstart*Cols+Cstart]);
00533 }
00534
00535 template<int Rstart, int Cstart, int Rsize, int Csize>
00536 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >& slice() const {
00537 util::Assert<(Rstart+Rsize <= Rows)>();
00538 util::Assert<(Cstart+Csize <= Cols)>();
00539 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Cols,RowMajor> >&>
00540 (this->my_values[Rstart*Cols+Cstart]);
00541 }
00542
00543 inline RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00544 return makeRefSkipMatrixRM(Rsize, Csize, Cols, this->my_values + Rstart*Cols + Cstart);
00545 }
00546
00547 inline const RefSkipMatrixRM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00548 return makeRefSkipMatrixRM(Rsize, Csize, Cols, this->my_values + Rstart*Cols + Cstart);
00549 }
00550
00551 };
00552
00553
00554
00555 template <int Rows,int Cols, class AllocZone>
00556 class FixedMAccessor<Rows,Cols,ColMajor,AllocZone> : public AllocZone {
00557 public:
00558 FixedVector<Cols, SkipAccessor<Cols, Rows> >& operator[](int r) TOON_THROW{
00559 TOON_CHECK_ROW;
00560 FixedVector<Cols, SkipAccessor<Cols, Rows> >::dummy();
00561 return reinterpret_cast<FixedVector<Cols, SkipAccessor<Cols, Rows> >&>(this->my_values[r]);
00562 }
00563
00564 const FixedVector<Cols, SkipAccessor<Cols, Rows> >& operator[](int r) const TOON_THROW{
00565 TOON_CHECK_ROW;
00566 return reinterpret_cast<const FixedVector<Cols, SkipAccessor<Cols, Rows> >&>(this->my_values[r]);
00567 }
00568
00569 inline double& operator()(int r, int c) TOON_THROW
00570 {
00571 TOON_CHECK_ROW;
00572 TOON_CHECK_COL;
00573 return this->my_values[c*Rows+r];
00574 }
00575
00576 inline const double& operator()(int r, int c)const TOON_THROW
00577 {
00578 TOON_CHECK_ROW;
00579 TOON_CHECK_COL;
00580 return this->my_values[c*Rows+r];
00581 }
00582
00583 static inline int num_rows() throw() {return Rows;}
00584 static inline int num_cols() throw() {return Cols;}
00585 static inline int num_skip() throw() {return Rows;}
00586 typedef ColMajor layout;
00587
00588
00589 inline FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >& T() {
00590 FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >::dummy();
00591 return reinterpret_cast<FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >&>(*this->my_values);
00592 }
00593 inline const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >& T() const {
00594 FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >::dummy();
00595 return reinterpret_cast<const FixedMatrix<Cols,Rows,FixedMAccessor<Cols,Rows,RowMajor,Stack<Rows*Cols> > >&>(*this->my_values);
00596 }
00597
00598
00599 template<int Rstart, int Cstart, int Rsize, int Csize>
00600 inline FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >& slice(){
00601 FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >::dummy();
00602 return reinterpret_cast<FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >&>
00603 (this->my_values[Cstart*Rows+Rstart]);
00604 }
00605
00606 template<int Rstart, int Cstart, int Rsize, int Csize>
00607 inline const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >& slice()const{
00608 FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >::dummy();
00609 return reinterpret_cast<const FixedMatrix<Rsize,Csize,SkipMAccessor<Rsize,Csize,Rows,ColMajor> >&>
00610 (this->my_values[Cstart*Rows+Rstart]);
00611 }
00612
00613 inline RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) {
00614 return makeRefSkipMatrixCM(Rsize, Csize, Rows, this->my_values + Rstart + Cstart*Rows);
00615 }
00616
00617 inline const RefSkipMatrixCM slice(int Rstart, int Cstart, int Rsize, int Csize) const {
00618 return makeRefSkipMatrixCM(Rsize, Csize, Rows, this->my_values + Rstart + Cstart*Rows);
00619 }
00620
00621 };
00622
00623
00624
00625 #undef TOON_CHECK_ROW
00626 #undef TOON_CHECK_COL
00627
00628
00629 #endif