Col.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 ConstColView;
00025 
00027 template<class Rep>
00028 class ColView : public ColViewTag
00029 {
00030 public:
00031     typedef ColView<Rep>        self_type;
00032     typedef ColViewTag          exp_tag;
00033     typedef NullTag             extra_param_type;
00034     typedef ConstColView<Rep>   const_view_type;
00035     COMMON_VIEW_TYPEDEFS();
00036 
00037     enum {
00038         ROWS = super_type::ROWS,
00039         COLS = 1,
00040         IsLinear = true,
00041         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00042         TNOP = ROWS != 0 ? Rep::ENOP * ROWS : -1,
00043         ENOP = Rep::ENOP,
00044         EXPLevel = Rep::EXPLevel +1
00045     };
00046 
00048     typedef Vec<DenseColVecCon<value_type,ROWS>, EmptyErrorChecker> temp_type;
00049 
00050     /************************************************/
00051     // Constructors
00052     EXMAT_INLINE2 ColView(const self_type& self)
00053         : rep(self.rep), col(self.col) {}
00054     EXMAT_INLINE2 ColView(super_type& mat, index_type c)
00055         : rep(mat), col(c) {}
00057     template<class Rep2> EXMAT_INLINE2
00058     ColView(const Rep2& self, Rep& mat)
00059         : rep(mat), col(self.col) {}
00060 
00062     EXMAT_INLINE2 self_type operator=(const_param_type s) {
00063         for(int 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.rows(); }
00070     EXMAT_INLINE2 size_t rows() const { return rep.rows(); }
00071     EXMAT_INLINE2 size_t cols() const { return 1; }
00072     /************************************************/
00073     // Index function (for internal use, no error checking applied)
00074     EXMAT_INLINE2 reference setAt(index_type i)
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(i, col);   }
00080     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00081     {   return rep.getAt(i, col);   }
00082 
00083 private:
00084     const index_type col;
00085 };
00089 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00090 Vec<ExpMat<ColView<typename Rep::rep_type> >, ErrChk>
00091 col(Mat<Rep, ErrChk>& mat, typename Mat<Rep, ErrChk>::index_type col) {
00092     return ExpMat<ColView<TTYPENAME Rep::rep_type> >(mat, col);
00093 }
00094 
00096 template<class Rep>
00097 class ConstColView : public ColViewTag
00098 {
00099 public:
00100     typedef ConstColView<Rep>   self_type;
00101     typedef ColViewTag          exp_tag;
00102     typedef NullTag             extra_param_type;
00103     COMMON_CONST_VIEW_TYPEDEFS();
00104 
00105     enum {
00106         ROWS = super_type::ROWS,
00107         COLS = 1,
00108         IsLinear = true,
00109         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00110         TNOP = ROWS != 0 ? Rep::ENOP * ROWS : -1,
00111         ENOP = Rep::ENOP,
00112         EXPLevel = Rep::EXPLevel +1
00113     };
00114 
00116     typedef Vec<DenseColVecCon<value_type,ROWS>, EmptyErrorChecker> temp_type;
00117 
00118     /************************************************/
00119     // Constructors
00120     EXMAT_INLINE2 ConstColView(const self_type& self)
00121         : rep(self.rep), col(self.col) {}
00122     EXMAT_INLINE2 ConstColView(const super_type& mat, index_type c)
00123         : rep(mat), col(c) {}
00125     template<class Rep2> EXMAT_INLINE2
00126     ConstColView(const Rep2& self, const Rep& mat)
00127         : rep(mat), col(self.col) {}
00128 
00129     /************************************************/
00130     // Dimension information
00131     EXMAT_INLINE2 size_t size() const { return rep.rows(); }
00132     EXMAT_INLINE2 size_t rows() const { return rep.rows(); }
00133     EXMAT_INLINE2 size_t cols() const { return 1; }
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(i, col);   }
00140 
00141 private:
00142     const index_type col;
00143 };
00147 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00148 const Vec<ExpMat<ConstColView<typename Rep::rep_type> >, ErrChk>
00149 col(const Mat<Rep, ErrChk>& mat, typename Mat<Rep, ErrChk>::index_type col) {
00150     return ExpMat<ConstColView<TTYPENAME Rep::rep_type> >(mat, col);
00151 }

Generated on Sat May 6 23:11:55 2006 for Exmat by  doxygen 1.4.6-NO