Row.h

00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 // Forward declaration
00024 template<class Rep> class ConstRowView;
00025 
00027 template<class Rep>
00028 class RowView : public RowViewTag
00029 {
00030 public:
00031     typedef RowView<Rep>        self_type;
00032     typedef RowViewTag          exp_tag;
00033     typedef NullTag             extra_param_type;
00034     typedef ConstRowView<Rep>   const_view_type;
00035     COMMON_VIEW_TYPEDEFS();
00036 
00037     enum {
00038         ROWS = 1,
00039         COLS = super_type::COLS,
00040         IsLinear = true,
00041         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00042         TNOP = COLS != 0 ? Rep::ENOP * COLS : -1,
00043         ENOP = Rep::ENOP,
00044         EXPLevel = Rep::EXPLevel +1
00045     };
00046 
00048     typedef Vec<DenseRowVecCon<value_type,COLS>, EmptyErrorChecker> temp_type;
00049 
00050     /************************************************/
00051     // Constructors
00052     EXMAT_INLINE2 RowView(const self_type& self)
00053         : rep(self.rep), row(self.row) {}
00054     EXMAT_INLINE2 RowView(super_type& mat, index_type r)
00055         : rep(mat), row(r) {}
00057     template<class Rep2> EXMAT_INLINE2
00058     RowView(const Rep2& self, Rep& mat)
00059         : rep(mat), row(self.row) {}
00060 
00062     EXMAT_INLINE2 self_type operator=(const_param_type s) {
00063         for(size_t i=0; i<size(); ++i)
00064             setAt(i) = s;
00065         return *this;
00066     }
00067     /************************************************/
00068     // Dimension information
00069     EXMAT_INLINE2 size_t size() const { return rep.cols(); }
00070     EXMAT_INLINE2 size_t rows() const { return 1; }
00071     EXMAT_INLINE2 size_t cols() const { return rep.cols(); }
00072     /************************************************/
00073     // Index function (for internal use, no error checking applied)
00074     EXMAT_INLINE2 reference setAt(index_type i) const
00075     {   return rep.setAt(i);    }
00076     EXMAT_INLINE2 const_reference getAt(index_type i) const
00077     {   return rep.getAt(i);    }
00078     EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00079     {   return rep.setAt(row, j);   }
00080     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00081     {   return rep.getAt(row, j);   }
00082 
00083 public:
00084     const index_type row;
00085 };
00089 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00090 Vec<ExpMat<RowView<typename Rep::rep_type> >, ErrChk>
00091 row(Mat<Rep, ErrChk>& mat, typename Mat<Rep, ErrChk>::index_type row) {
00092     return ExpMat<RowView<TTYPENAME Rep::rep_type> >(mat, row);
00093 }
00094 
00096 template<class Rep>
00097 class ConstRowView : public RowViewTag
00098 {
00099 public:
00100     typedef ConstRowView<Rep>   self_type;
00101     typedef RowViewTag          exp_tag;
00102     typedef NullTag             extra_param_type;
00103     COMMON_CONST_VIEW_TYPEDEFS();
00104 
00105     enum {
00106         ROWS = 1,
00107         COLS = super_type::COLS,
00108         IsLinear = true,
00109         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00110         TNOP = COLS != 0 ? Rep::ENOP * COLS : -1,
00111         ENOP = Rep::ENOP,
00112         EXPLevel = Rep::EXPLevel +1
00113     };
00114 
00116     typedef Vec<DenseRowVecCon<value_type,COLS>, EmptyErrorChecker> temp_type;
00117 
00118     /************************************************/
00119     // Constructors
00120     EXMAT_INLINE2 ConstRowView(const self_type& self)
00121         : rep(self.rep), row(self.row) {}
00122     EXMAT_INLINE2 ConstRowView(const super_type& mat, index_type r)
00123         : rep(mat), row(r) {}
00125     template<class Rep2> EXMAT_INLINE2
00126     ConstRowView(const Rep2& self, const Rep& mat)
00127         : rep(mat), row(self.row) {}
00128 
00129     /************************************************/
00130     // Dimension information
00131     EXMAT_INLINE2 size_t size() const { return rep.cols(); }
00132     EXMAT_INLINE2 size_t rows() const { return 1; }
00133     EXMAT_INLINE2 size_t cols() const { return rep.cols(); }
00134     /************************************************/
00135     // Index function (for internal use, no error checking applied)
00136     EXMAT_INLINE2 const_reference getAt(index_type i) const
00137     {   return rep.getAt(i);    }
00138     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00139     {   return rep.getAt(row, j);   }
00140 
00141 public:
00142     const index_type row;
00143 };
00147 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00148 const Vec<ExpMat<ConstRowView<typename Rep::rep_type> >, ErrChk>
00149 row(const Mat<Rep, ErrChk>& mat, typename Mat<Rep, ErrChk>::index_type row) {
00150     return ExpMat<ConstRowView<TTYPENAME Rep::rep_type> >(mat, row);
00151 }

Generated on Sat May 6 23:12:00 2006 for Exmat by  doxygen 1.4.6-NO