Eurobot2012_Secondary

Fork of Eurobot_2012_Secondary by Shuto Naruse

Committer:
narshu
Date:
Wed Oct 17 22:25:31 2012 +0000
Revision:
1:cc2a9eb0bd55
Commit before publishing

Who changed what in which revision?

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