SourceForge Logo Tiny Vector Matrix library using Expression Templates Sourceforge Project Page

include/tvmet/xpr/Vector.h

Go to the documentation of this file.
00001 /*
00002  * Tiny Vector Matrix Library
00003  * Dense Vector Matrix Libary of Tiny size using Expression Templates
00004  *
00005  * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * $Id: Vector.h,v 1.28 2007-06-23 15:59:00 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_XPR_VECTOR_H
00025 #define TVMET_XPR_VECTOR_H
00026 
00027 #include <tvmet/meta/Vector.h>
00028 #include <tvmet/loop/Vector.h>
00029 
00030 namespace tvmet {
00031 
00032 
00033 /* forwards */
00034 template <class T, std::size_t Sz> class Vector;
00035 
00049 template<class E, std::size_t Sz>
00050 class XprVector : public TvmetBase< XprVector<E, Sz> >
00051 {
00052   XprVector();
00053   XprVector& operator=(const XprVector&);
00054 
00055 public:
00056   typedef typename E::value_type      value_type;
00057 
00058 public:
00060   enum {
00061     Size = Sz     
00062   };
00063 
00064 public:
00066   enum {
00067     ops_assign = Size,
00068     ops        = E::ops,
00069     use_meta   = ops_assign < TVMET_COMPLEXITY_V_ASSIGN_TRIGGER ? true : false
00070   };
00071 
00072 public:
00074   explicit XprVector(const E& e)
00075     : m_expr(e)
00076   { }
00077 
00079 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
00080   XprVector(const XprVector& e)
00081     : m_expr(e.m_expr)
00082   { }
00083 #endif
00084 
00086   value_type operator()(std::size_t i) const {
00087     TVMET_RT_CONDITION(i < Size, "XprVector Bounce Violation")
00088     return m_expr(i);
00089   }
00090 
00092   value_type operator[](std::size_t i) const {
00093     return this->operator()(i);
00094   }
00095 
00096 private:
00098   template<class Dest, class Src, class Assign>
00099   static inline
00100   void do_assign(dispatch<true>, Dest& dest, const Src& src, const Assign& assign_fn) {
00101     meta::Vector<Size, 0>::assign(dest, src, assign_fn);
00102   }
00103 
00105   template<class Dest, class Src, class Assign>
00106   static inline
00107   void do_assign(dispatch<false>, Dest& dest, const Src& src, const Assign& assign_fn) {
00108     loop::Vector<Size>::assign(dest, src, assign_fn);
00109   }
00110 
00111 public:
00113   template<class Dest, class Assign>
00114   void assign_to(Dest& dest, const Assign& assign_fn) const {
00115     /* here is a way for caching, since each complex 'Node'
00116        is of type XprVector. */
00117     do_assign(dispatch<use_meta>(), dest, *this, assign_fn);
00118   }
00119 
00120 public: // debugging Xpr parse tree
00121   void print_xpr(std::ostream& os, std::size_t l=0) const {
00122     os << IndentLevel(l++)
00123        << "XprVector["
00124        << (use_meta ? "M" :  "L") << ", O=" << ops << "]<"
00125        << std::endl;
00126     m_expr.print_xpr(os, l);
00127     os << IndentLevel(l)
00128        << "Sz=" << Size << std::endl;
00129     os << IndentLevel(--l) << ">"
00130        << ((l != 0) ? "," : "") << std::endl;
00131   }
00132 
00133 private:
00134   const E           m_expr;
00135 };
00136 
00137 
00138 } // namespace tvmet
00139 
00140 #include <tvmet/Functional.h>
00141 
00142 #include <tvmet/xpr/BinOperator.h>
00143 #include <tvmet/xpr/UnOperator.h>
00144 #include <tvmet/xpr/Literal.h>
00145 
00146 #include <tvmet/xpr/VectorFunctions.h>
00147 #include <tvmet/xpr/VectorBinaryFunctions.h>
00148 #include <tvmet/xpr/VectorUnaryFunctions.h>
00149 #include <tvmet/xpr/VectorOperators.h>
00150 #include <tvmet/xpr/Eval.h>
00151 
00152 #endif // TVMET_XPR_VECTOR_H
00153 
00154 // Local Variables:
00155 // mode:C++
00156 // tab-width:8
00157 // End:

Author: