We are going to win! wohoo

Dependencies:   mbed mbed-rtos

Committer:
madcowswe
Date:
Wed Nov 14 17:15:53 2012 +0000
Revision:
9:08552997b544
Parent:
1:6799c07fe510
Added an important comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sv 1:6799c07fe510 1 /*
sv 1:6799c07fe510 2 * Tiny Vector Matrix Library
sv 1:6799c07fe510 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
sv 1:6799c07fe510 4 *
sv 1:6799c07fe510 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
sv 1:6799c07fe510 6 *
sv 1:6799c07fe510 7 * This library is free software; you can redistribute it and/or
sv 1:6799c07fe510 8 * modify it under the terms of the GNU lesser General Public
sv 1:6799c07fe510 9 * License as published by the Free Software Foundation; either
sv 1:6799c07fe510 10 * version 2.1 of the License, or (at your option) any later version.
sv 1:6799c07fe510 11 *
sv 1:6799c07fe510 12 * This library is distributed in the hope that it will be useful,
sv 1:6799c07fe510 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sv 1:6799c07fe510 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sv 1:6799c07fe510 15 * lesser General Public License for more details.
sv 1:6799c07fe510 16 *
sv 1:6799c07fe510 17 * You should have received a copy of the GNU lesser General Public
sv 1:6799c07fe510 18 * License along with this library; if not, write to the Free Software
sv 1:6799c07fe510 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sv 1:6799c07fe510 20 *
sv 1:6799c07fe510 21 * $Id: Vector.h,v 1.28 2007-06-23 15:59:00 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_XPR_VECTOR_H
sv 1:6799c07fe510 25 #define TVMET_XPR_VECTOR_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 #include <tvmet/meta/Vector.h>
sv 1:6799c07fe510 28 #include <tvmet/loop/Vector.h>
sv 1:6799c07fe510 29
sv 1:6799c07fe510 30 namespace tvmet {
sv 1:6799c07fe510 31
sv 1:6799c07fe510 32
sv 1:6799c07fe510 33 /* forwards */
sv 1:6799c07fe510 34 template <class T, std::size_t Sz> class Vector;
sv 1:6799c07fe510 35
sv 1:6799c07fe510 36 /**
sv 1:6799c07fe510 37 * \class XprVector Vector.h "tvmet/xpr/Vector.h"
sv 1:6799c07fe510 38 * \brief Represents the expression for vectors at any node in the parse tree.
sv 1:6799c07fe510 39 *
sv 1:6799c07fe510 40 * Specifically, XprVector is the class that wraps the expression, and the
sv 1:6799c07fe510 41 * expression itself is represented by the template parameter E. The
sv 1:6799c07fe510 42 * class XprVector is known as an anonymizing expression wrapper because
sv 1:6799c07fe510 43 * it can hold any subexpression of arbitrary complexity, allowing
sv 1:6799c07fe510 44 * clients to work with any expression by holding on to it via the
sv 1:6799c07fe510 45 * wrapper, without having to know the name of the type object that
sv 1:6799c07fe510 46 * actually implements the expression.
sv 1:6799c07fe510 47 * \note leave the Ctors non-explicit to allow implicit type conversation.
sv 1:6799c07fe510 48 */
sv 1:6799c07fe510 49 template<class E, std::size_t Sz>
sv 1:6799c07fe510 50 class XprVector : public TvmetBase< XprVector<E, Sz> >
sv 1:6799c07fe510 51 {
sv 1:6799c07fe510 52 XprVector();
sv 1:6799c07fe510 53 XprVector& operator=(const XprVector&);
sv 1:6799c07fe510 54
sv 1:6799c07fe510 55 public:
sv 1:6799c07fe510 56 typedef typename E::value_type value_type;
sv 1:6799c07fe510 57
sv 1:6799c07fe510 58 public:
sv 1:6799c07fe510 59 /** Dimensions. */
sv 1:6799c07fe510 60 enum {
sv 1:6799c07fe510 61 Size = Sz /**< The size of the vector. */
sv 1:6799c07fe510 62 };
sv 1:6799c07fe510 63
sv 1:6799c07fe510 64 public:
sv 1:6799c07fe510 65 /** Complexity counter */
sv 1:6799c07fe510 66 enum {
sv 1:6799c07fe510 67 ops_assign = Size,
sv 1:6799c07fe510 68 ops = E::ops,
sv 1:6799c07fe510 69 use_meta = ops_assign < TVMET_COMPLEXITY_V_ASSIGN_TRIGGER ? true : false
sv 1:6799c07fe510 70 };
sv 1:6799c07fe510 71
sv 1:6799c07fe510 72 public:
sv 1:6799c07fe510 73 /** Constructor. */
sv 1:6799c07fe510 74 explicit XprVector(const E& e)
sv 1:6799c07fe510 75 : m_expr(e)
sv 1:6799c07fe510 76 { }
sv 1:6799c07fe510 77
sv 1:6799c07fe510 78 /** Copy Constructor. Not explicit! */
sv 1:6799c07fe510 79 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
sv 1:6799c07fe510 80 XprVector(const XprVector& e)
sv 1:6799c07fe510 81 : m_expr(e.m_expr)
sv 1:6799c07fe510 82 { }
sv 1:6799c07fe510 83 #endif
sv 1:6799c07fe510 84
sv 1:6799c07fe510 85 /** const index operator for vectors. */
sv 1:6799c07fe510 86 value_type operator()(std::size_t i) const {
sv 1:6799c07fe510 87 TVMET_RT_CONDITION(i < Size, "XprVector Bounce Violation")
sv 1:6799c07fe510 88 return m_expr(i);
sv 1:6799c07fe510 89 }
sv 1:6799c07fe510 90
sv 1:6799c07fe510 91 /** const index operator for vectors. */
sv 1:6799c07fe510 92 value_type operator[](std::size_t i) const {
sv 1:6799c07fe510 93 return this->operator()(i);
sv 1:6799c07fe510 94 }
sv 1:6799c07fe510 95
sv 1:6799c07fe510 96 private:
sv 1:6799c07fe510 97 /** Wrapper for meta assign. */
sv 1:6799c07fe510 98 template<class Dest, class Src, class Assign>
sv 1:6799c07fe510 99 static inline
sv 1:6799c07fe510 100 void do_assign(dispatch<true>, Dest& dest, const Src& src, const Assign& assign_fn) {
sv 1:6799c07fe510 101 meta::Vector<Size, 0>::assign(dest, src, assign_fn);
sv 1:6799c07fe510 102 }
sv 1:6799c07fe510 103
sv 1:6799c07fe510 104 /** Wrapper for loop assign. */
sv 1:6799c07fe510 105 template<class Dest, class Src, class Assign>
sv 1:6799c07fe510 106 static inline
sv 1:6799c07fe510 107 void do_assign(dispatch<false>, Dest& dest, const Src& src, const Assign& assign_fn) {
sv 1:6799c07fe510 108 loop::Vector<Size>::assign(dest, src, assign_fn);
sv 1:6799c07fe510 109 }
sv 1:6799c07fe510 110
sv 1:6799c07fe510 111 public:
sv 1:6799c07fe510 112 /** assign this expression to Vector dest. */
sv 1:6799c07fe510 113 template<class Dest, class Assign>
sv 1:6799c07fe510 114 void assign_to(Dest& dest, const Assign& assign_fn) const {
sv 1:6799c07fe510 115 /* here is a way for caching, since each complex 'Node'
sv 1:6799c07fe510 116 is of type XprVector. */
sv 1:6799c07fe510 117 do_assign(dispatch<use_meta>(), dest, *this, assign_fn);
sv 1:6799c07fe510 118 }
sv 1:6799c07fe510 119
sv 1:6799c07fe510 120 public: // debugging Xpr parse tree
sv 1:6799c07fe510 121 void print_xpr(std::ostream& os, std::size_t l=0) const {
sv 1:6799c07fe510 122 os << IndentLevel(l++)
sv 1:6799c07fe510 123 << "XprVector["
sv 1:6799c07fe510 124 << (use_meta ? "M" : "L") << ", O=" << ops << "]<"
sv 1:6799c07fe510 125 << std::endl;
sv 1:6799c07fe510 126 m_expr.print_xpr(os, l);
sv 1:6799c07fe510 127 os << IndentLevel(l)
sv 1:6799c07fe510 128 << "Sz=" << Size << std::endl;
sv 1:6799c07fe510 129 os << IndentLevel(--l) << ">"
sv 1:6799c07fe510 130 << ((l != 0) ? "," : "") << std::endl;
sv 1:6799c07fe510 131 }
sv 1:6799c07fe510 132
sv 1:6799c07fe510 133 private:
sv 1:6799c07fe510 134 const E m_expr;
sv 1:6799c07fe510 135 };
sv 1:6799c07fe510 136
sv 1:6799c07fe510 137
sv 1:6799c07fe510 138 } // namespace tvmet
sv 1:6799c07fe510 139
sv 1:6799c07fe510 140 #include <tvmet/Functional.h>
sv 1:6799c07fe510 141
sv 1:6799c07fe510 142 #include <tvmet/xpr/BinOperator.h>
sv 1:6799c07fe510 143 #include <tvmet/xpr/UnOperator.h>
sv 1:6799c07fe510 144 #include <tvmet/xpr/Literal.h>
sv 1:6799c07fe510 145
sv 1:6799c07fe510 146 #include <tvmet/xpr/VectorFunctions.h>
sv 1:6799c07fe510 147 #include <tvmet/xpr/VectorBinaryFunctions.h>
sv 1:6799c07fe510 148 #include <tvmet/xpr/VectorUnaryFunctions.h>
sv 1:6799c07fe510 149 #include <tvmet/xpr/VectorOperators.h>
sv 1:6799c07fe510 150 #include <tvmet/xpr/Eval.h>
sv 1:6799c07fe510 151
sv 1:6799c07fe510 152 #endif // TVMET_XPR_VECTOR_H
sv 1:6799c07fe510 153
sv 1:6799c07fe510 154 // Local Variables:
sv 1:6799c07fe510 155 // mode:C++
sv 1:6799c07fe510 156 // tab-width:8
sv 1:6799c07fe510 157 // End: