2014 Eurobot fork

Dependencies:   mbed-rtos mbed QEI

Committer:
rsavitski
Date:
Tue Oct 15 12:19:32 2013 +0000
Revision:
92:4a1225fbb146
Parent:
15:9c5aaeda36dc
touch: ripped out 2013-specific bits. Need to address "2014" comments. Rewrite AI layer and other deleted parts.

Who changed what in which revision?

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