Reverse.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 ConstReverseVecView;
00025 
00027 template<class Rep>
00028 class ReverseVecView : public ReverseVecViewTag
00029 {
00030 public:
00031     typedef ReverseVecView<Rep>         self_type;
00032     typedef ReverseVecViewTag           exp_tag;
00033     typedef NullTag                     extra_param_type;
00034     typedef ConstReverseVecView<Rep>    const_view_type;
00035     COMMON_VIEW_TYPEDEFS();
00036 
00037     enum {
00038         ROWS = super_type::ROWS,
00039         COLS = super_type::COLS,
00040         IsLinear = false,
00041         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00042         TNOP = Rep::TNOP,
00043         ENOP = Rep::ENOP,
00044         EXPLevel = Rep::EXPLevel +1
00045     };
00046 
00048     typedef Vec<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00049 
00050     /************************************************/
00051     // Constructors
00052     EXMAT_INLINE2 ReverseVecView(const self_type& self)
00053         : rep(self.rep) {}
00054     EXMAT_INLINE2 ReverseVecView(super_type& vec)
00055         : rep(vec) {}
00057     template<class Rep2> EXMAT_INLINE2
00058     ReverseVecView(const Rep2& self, Rep& vec)
00059         : rep(vec) {}
00060 
00062     EXMAT_INLINE2 self_type operator=(const_param_type s) {
00063         rep = s;
00064         return *this;
00065     }
00066     /************************************************/
00067     // Dimension information
00068     EXMAT_INLINE2 size_t size() const { return rep.size(); }
00069     EXMAT_INLINE2 size_t rows() const { return rep.rows(); }
00070     EXMAT_INLINE2 size_t cols() const { return rep.cols(); }
00071     /************************************************/
00072     // Index function (for internal use, no error checking applied)
00073     EXMAT_INLINE2 reference setAt(index_type i)
00074     {   return rep.setAt(size()-1-i);   }
00075     EXMAT_INLINE2 const_reference getAt(index_type i) const
00076     {   return rep.getAt(size()-1-i);   }
00077     EXMAT_INLINE2 reference setAt(index_type i, index_type j)
00078     {   return rep.setAt(rows()-1-i, cols()-1-j);   }
00079     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00080     {   return rep.getAt(rows()-1-i, cols()-1-j);   }
00081 };
00085 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00086 Vec<ExpMat<ReverseVecView<typename Rep::rep_type> >, ErrChk>
00087 reverse(Vec<Rep, ErrChk>& vec) {
00088     return ExpMat<ReverseVecView<TTYPENAME Rep::rep_type> >(vec);
00089 }
00090 
00092 template<class Rep>
00093 class ConstReverseVecView : public ReverseVecViewTag
00094 {
00095 public:
00096     typedef ConstReverseVecView<Rep>    self_type;
00097     typedef ReverseVecViewTag           exp_tag;
00098     typedef NullTag                     extra_param_type;
00099     COMMON_CONST_VIEW_TYPEDEFS();
00100 
00101     enum {
00102         ROWS = super_type::ROWS,
00103         COLS = super_type::COLS,
00104         IsLinear = false,
00105         IsLinearRecursive = IsLinear && super_type::IsLinearRecursive,
00106         TNOP = Rep::TNOP,
00107         ENOP = Rep::ENOP,
00108         EXPLevel = Rep::EXPLevel +1
00109     };
00110 
00112     typedef Vec<DenseMatCon<value_type,ROWS,COLS>, EmptyErrorChecker> temp_type;
00113 
00114     /************************************************/
00115     // Constructors
00116     EXMAT_INLINE2 ConstReverseVecView(const self_type& self)
00117         : rep(self.rep) {}
00118     EXMAT_INLINE2 ConstReverseVecView(const super_type& vec_)
00119         : rep(vec_) {}
00121     template<class Rep2> EXMAT_INLINE2
00122     ConstReverseVecView(const Rep2& self, const Rep& vec)
00123         : rep(vec) {}
00124 
00125     /************************************************/
00126     // Dimension information
00127     EXMAT_INLINE2 size_t size() const { return rep.size(); }
00128     EXMAT_INLINE2 size_t rows() const { return rep.rows(); }
00129     EXMAT_INLINE2 size_t cols() const { return rep.cols(); }
00130     /************************************************/
00131     // Index function (for internal use, no error checking applied)
00132     EXMAT_INLINE2 const_reference getAt(index_type i) const
00133     {   return rep.getAt(size()-1-i);   }
00134     EXMAT_INLINE2 const_reference getAt(index_type i, index_type j) const
00135     {   return rep.getAt(rows()-1-i, cols()-1-j);   }
00136 };
00140 template<class Rep, class ErrChk> EXMAT_INLINE2 static
00141 const Vec<ExpMat<ConstReverseVecView<typename Rep::rep_type> >, ErrChk>
00142 reverse(const Vec<Rep, ErrChk>& vec) {
00143     return ExpMat<ConstReverseVecView<TTYPENAME Rep::rep_type> >(vec);
00144 }

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