00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 template<class Rep, class ExtraTParam> class StaticConstSubMatView;
00025 template<class Rep> class DynConstSubMatView;
00026
00028 template<class Rep, class ExtraTParam>
00029 class StaticSubMatView : public StaticSubMatViewTag
00030 {
00031 public:
00032 typedef StaticSubMatView<Rep, ExtraTParam> self_type;
00033 typedef StaticSubMatViewTag exp_tag;
00034 typedef ExtraTParam extra_param_type;
00035 typedef StaticConstSubMatView<Rep, ExtraTParam> const_view_type;
00036 COMMON_VIEW_TYPEDEFS();
00037
00038 enum {
00039 TOP = ExtraTParam::INT1,
00040 LEFT = ExtraTParam::INT2,
00041 RS = ExtraTParam::INT3,
00042 CS = ExtraTParam::INT4,
00043 ROWS = RS,
00044 COLS = CS,
00045 IsLinear = true,
00046 IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00047 TNOP = 0,
00048 ENOP = 0,
00049 EXPLevel = Rep::EXPLevel + 1
00050 };
00051
00053 typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00054
00055
00056
00057 EXMAT_INLINE2 StaticSubMatView(const self_type& self)
00058 : rep(self.rep) {}
00059 EXMAT_INLINE2 StaticSubMatView(Rep& mat)
00060 : rep(mat) { ComErrCheck(); }
00062 template<class Rep2> EXMAT_INLINE2
00063 StaticSubMatView(const Rep2& self, Rep& mat)
00064 : rep(mat) {
00065 THROWMSG(ROWS==Rep2::ROWS && COLS==Rep2::COLS, InternalErrMsg, __FILE__);
00066 ComErrCheck();
00067 }
00068
00069
00070
00071 EXMAT_INLINE2 size_t size() const { return ROWS*COLS; }
00072 EXMAT_INLINE2 size_t rows() const { return ROWS; }
00073 EXMAT_INLINE2 size_t cols() const { return COLS; }
00074
00075
00076 EXMAT_INLINE2 reference setAt(index_type i)
00077 { return this->setAt(i/COLS, i%COLS); }
00078 EXMAT_INLINE2 const_reference getAt(index_type i) const
00079 { return this->getAt(i/COLS, i%COLS); }
00080 EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00081 { return rep.setAt(i+TOP, j+LEFT); }
00082 EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00083 { return rep.getAt(i+TOP, j+LEFT); }
00084
00085 private:
00086
00087 EXMAT_INLINE2 void ComErrCheck() {
00088 #if EXMAT_STATIC_CHECK
00089 StaticAssert1(TOP >= 0, RowOutOfRange);
00090 StaticAssert1(LEFT >= 0, ColOutOfRange);
00091 StaticAssert1(TOP+RS <= super_type::ROWS, RowOutOfRange);
00092 StaticAssert1(LEFT+CS <= super_type::COLS, ColOutOfRange);
00093 #else
00094 DefaultErrorChecker::AssertCompat(
00095 TOP >= 0 && LEFT >= 0 &&
00096 (TOP+RS <= super_type::ROWS) && (LEFT+CS <= super_type::COLS)
00097 );
00098 #endif // EXMAT_STATIC_CHECK
00099 }
00100 };
00101 #if !EXMAT_VC6
00102
00105 template<class Rep, class ErrChk, int TOP, int LEFT, int RS, int CS> EXMAT_INLINE2 static
00106 Mat<ExpMat<StaticSubMatView<Rep,TParamINT4<TOP,LEFT,RS,CS> > >, ErrChk>
00107 subMat(Mat<Rep, ErrChk>& mat, Int2Type<TOP>, Int2Type<LEFT>, Int2Type<RS>, Int2Type<CS>) {
00108 return Mat<ExpMat<StaticSubMatView<Rep,TParamINT4<TOP,LEFT,RS,CS> > >, ErrChk>(
00109 ExpMat<StaticSubMatView<Rep,TParamINT4<TOP,LEFT,RS,CS> > >(mat)
00110 );
00111 }
00112 #endif // !EXMAT_VC6
00113
00114
00116 template<class Rep, class ExtraTParam>
00117 class StaticConstSubMatView : public StaticSubMatViewTag
00118 {
00119 public:
00120 typedef StaticConstSubMatView<Rep, ExtraTParam> self_type;
00121 typedef StaticSubMatViewTag exp_tag;
00122 typedef ExtraTParam extra_param_type;
00123 COMMON_CONST_VIEW_TYPEDEFS();
00124
00125 enum {
00126 TOP = ExtraTParam::INT1,
00127 LEFT = ExtraTParam::INT2,
00128 RS = ExtraTParam::INT3,
00129 CS = ExtraTParam::INT4,
00130 ROWS = RS,
00131 COLS = CS,
00132 IsLinear = true,
00133 IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00134 TNOP = 0,
00135 ENOP = 0,
00136 EXPLevel = Rep::EXPLevel + 1
00137 };
00138
00140 typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00141
00142
00143
00144 EXMAT_INLINE2 StaticConstSubMatView(const self_type& self)
00145 : rep(self.rep) {}
00146 EXMAT_INLINE2 StaticConstSubMatView(const Rep& mat)
00147 : rep(mat) { ComErrCheck(); }
00149 template<class Rep2> EXMAT_INLINE2
00150 StaticConstSubMatView(const Rep2& self, const Rep& mat)
00151 : rep(mat) {
00152 THROWMSG(ROWS==Rep2::ROWS && COLS==Rep2::COLS, InternalErrMsg, __FILE__);
00153 ComErrCheck();
00154 }
00155
00156
00157
00158 EXMAT_INLINE2 size_t size() const { return ROWS*COLS; }
00159 EXMAT_INLINE2 size_t rows() const { return ROWS; }
00160 EXMAT_INLINE2 size_t cols() const { return COLS; }
00161
00162
00163 EXMAT_INLINE2 const_reference getAt(index_type i) const
00164 { return this->getAt(i/COLS, i%COLS); }
00165 EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00166 { return rep.getAt(i+TOP, j+LEFT); }
00167
00168 private:
00169
00170 EXMAT_INLINE2 void ComErrCheck() {
00171 #if EXMAT_STATIC_CHECK
00172 StaticAssert1(TOP >= 0, RowOutOfRange);
00173 StaticAssert1(LEFT >= 0, ColOutOfRange);
00174 StaticAssert1(TOP+RS <= super_type::ROWS, RowOutOfRange);
00175 StaticAssert1(LEFT+CS <= super_type::COLS, ColOutOfRange);
00176 #else
00177 DefaultErrorChecker::AssertCompat(
00178 TOP >= 0 && LEFT >= 0 &&
00179 (TOP+RS <= super_type::ROWS) && (LEFT+CS <= super_type::COLS)
00180 );
00181 #endif // EXMAT_STATIC_CHECK
00182 }
00183 };
00184 #if !EXMAT_VC6
00185
00188 template<class Rep, class ErrChk, int TOP, int LEFT, int RS, int CS> EXMAT_INLINE2 static
00189 const Mat<ExpMat<StaticConstSubMatView<Rep,TParamINT4<TOP,LEFT,RS,CS> > >, ErrChk>
00190 subMat(const Mat<Rep, ErrChk>& mat, Int2Type<TOP>, Int2Type<LEFT>, Int2Type<RS>, Int2Type<CS>) {
00191 return Mat<ExpMat<StaticConstSubMatView<Rep,TParamINT4<TOP,LEFT,RS,CS> > >, ErrChk>(
00192 ExpMat<StaticConstSubMatView<Rep,TParamINT4<TOP,LEFT,RS,CS> > >(mat)
00193 );
00194 }
00195 #endif // !EXMAT_VC6
00196
00197
00199 template<class Rep>
00200 class DynSubMatView : public DynSubMatViewTag
00201 {
00202 public:
00203 typedef DynSubMatView<Rep> self_type;
00204 typedef DynSubMatViewTag exp_tag;
00205 typedef NullTag extra_param_type;
00206 typedef DynConstSubMatView<Rep> const_view_type;
00207 COMMON_VIEW_TYPEDEFS();
00208
00209 enum {
00210 ROWS = 0,
00211 COLS = 0,
00212 IsLinear = true,
00213 IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00214 TNOP = 0,
00215 ENOP = 0,
00216 EXPLevel = Rep::EXPLevel + 1
00217 };
00218
00220 typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00221
00222
00223
00224 EXMAT_INLINE2 DynSubMatView(const self_type& self)
00225 : rep(self.rep), top(self.top), left(self.left), rs(self.rs), cs(self.cs) {}
00226 EXMAT_INLINE2 DynSubMatView(Rep& mat, size_t t, size_t l, size_t r, size_t c)
00227 : rep(mat), top(t), left(l), rs(r), cs(c) { ComErrCheck(); }
00229 template<class Rep2> EXMAT_INLINE2
00230 DynSubMatView(const Rep2& self, Rep& mat)
00231 : rep(mat), top(self.top), left(self.left), rs(self.rs), cs(self.cs) { ComErrCheck(); }
00232
00233
00234
00235 EXMAT_INLINE2 size_t size() const { return rs*cs; }
00236 EXMAT_INLINE2 size_t rows() const { return rs; }
00237 EXMAT_INLINE2 size_t cols() const { return cs; }
00238
00239
00240 EXMAT_INLINE2 reference setAt(index_type i)
00241 { return this->setAt(i/cols(), i%cols()); }
00242 EXMAT_INLINE2 const_reference getAt(index_type i) const
00243 { return this->getAt(i/cols(), i%cols()); }
00244 EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00245 { return rep.setAt(i+top, j+left); }
00246 EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00247 { return rep.getAt(i+top, j+left); }
00248
00249 public:
00250 const size_t top, left, rs, cs;
00251
00252 private:
00253
00254 EXMAT_INLINE2 void ComErrCheck() {
00255 DefaultErrorChecker::AssertCompat(
00256 (top+rs <= ((super_type*)(this))->rows()) &&
00257 (left+cs <= ((super_type*)(this))->cols())
00258 );
00259 }
00260 };
00264 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00265 Mat<ExpMat<DynSubMatView<Rep> >, ErrChk>
00266 subMat(Mat<Rep, ErrChk>& mat, size_t top, size_t left, size_t rs, size_t cs) {
00267 return Mat<ExpMat<DynSubMatView<Rep> >, ErrChk>(ExpMat<DynSubMatView<Rep> >(mat, top, left, rs, cs));
00268 }
00269
00270
00272 template<class Rep>
00273 class DynConstSubMatView : public DynSubMatViewTag
00274 {
00275 public:
00276 typedef DynConstSubMatView<Rep> self_type;
00277 typedef DynSubMatViewTag exp_tag;
00278 typedef NullTag extra_param_type;
00279 COMMON_CONST_VIEW_TYPEDEFS();
00280
00281 enum {
00282 ROWS = 0,
00283 COLS = 0,
00284 IsLinear = true,
00285 IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00286 TNOP = 0,
00287 ENOP = 0,
00288 EXPLevel = Rep::EXPLevel + 1
00289 };
00290
00292 typedef Mat<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00293
00294
00295
00296 EXMAT_INLINE2 DynConstSubMatView(const self_type& self)
00297 : rep(self.rep), top(self.top), left(self.left), rs(self.rs), cs(self.cs) {}
00298 EXMAT_INLINE2 DynConstSubMatView(const Rep& mat, size_t t, size_t l, size_t r, size_t c)
00299 : rep(mat), top(t), left(l), rs(r), cs(c) { ComErrCheck(); }
00301 template<class Rep2> EXMAT_INLINE2
00302 DynConstSubMatView(const Rep2& self, const Rep& mat)
00303 : rep(mat), top(self.top), left(self.left), rs(self.rs), cs(self.cs) { ComErrCheck(); }
00304
00305
00306
00307 EXMAT_INLINE2 size_t size() const { return rs*cs; }
00308 EXMAT_INLINE2 size_t rows() const { return rs; }
00309 EXMAT_INLINE2 size_t cols() const { return cs; }
00310
00311
00312 EXMAT_INLINE2 const_reference getAt(index_type i) const
00313 { return this->getAt(i/cols(), i%cols()); }
00314 EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00315 { return rep.getAt(i+top, j+left); }
00316
00317 public:
00318 const size_t top, left, rs, cs;
00319
00320 private:
00321
00322 EXMAT_INLINE2 void ComErrCheck() {
00323 DefaultErrorChecker::AssertCompat(
00324 (top+rs <= ((super_type*)(this))->rows()) &&
00325 (left+cs <= ((super_type*)(this))->cols())
00326 );
00327 }
00328 };
00332 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00333 const Mat<ExpMat<DynConstSubMatView<Rep> >, ErrChk>
00334 subMat(const Mat<Rep, ErrChk>& mat, size_t top, size_t left, size_t rs, size_t cs) {
00335 return Mat<ExpMat<DynConstSubMatView<Rep> >, ErrChk>(ExpMat<DynConstSubMatView<Rep> >(mat, top, left, rs, cs));
00336 }