This is some awesome robot code
Dependencies: mbed-rtos mbed QEI
Fork of ICRSEurobot13 by
tvmet/meta/Vector.h@90:e4164bb8c60e, 2013-04-17 (annotated)
- Committer:
- madcowswe
- Date:
- Wed Apr 17 23:16:25 2013 +0000
- Revision:
- 90:e4164bb8c60e
- Parent:
- 15:9c5aaeda36dc
final state at end of competition. Includes avoid wooden team hack
Who changed what in which revision?
User | Revision | Line number | New 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.24 2007-06-23 15:58:59 opetzold Exp $ |
madcowswe | 15:9c5aaeda36dc | 22 | */ |
madcowswe | 15:9c5aaeda36dc | 23 | |
madcowswe | 15:9c5aaeda36dc | 24 | #ifndef TVMET_META_VECTOR_H |
madcowswe | 15:9c5aaeda36dc | 25 | #define TVMET_META_VECTOR_H |
madcowswe | 15:9c5aaeda36dc | 26 | |
madcowswe | 15:9c5aaeda36dc | 27 | #include <tvmet/NumericTraits.h> |
madcowswe | 15:9c5aaeda36dc | 28 | #include <tvmet/xpr/Null.h> |
madcowswe | 15:9c5aaeda36dc | 29 | |
madcowswe | 15:9c5aaeda36dc | 30 | namespace tvmet { |
madcowswe | 15:9c5aaeda36dc | 31 | |
madcowswe | 15:9c5aaeda36dc | 32 | /* forwards */ |
madcowswe | 15:9c5aaeda36dc | 33 | template<class T, std::size_t Sz> class Vector; |
madcowswe | 15:9c5aaeda36dc | 34 | |
madcowswe | 15:9c5aaeda36dc | 35 | |
madcowswe | 15:9c5aaeda36dc | 36 | namespace meta { |
madcowswe | 15:9c5aaeda36dc | 37 | |
madcowswe | 15:9c5aaeda36dc | 38 | |
madcowswe | 15:9c5aaeda36dc | 39 | /** |
madcowswe | 15:9c5aaeda36dc | 40 | * \class Vector Vector.h "tvmet/meta/Vector.h" |
madcowswe | 15:9c5aaeda36dc | 41 | * \brief Meta %Vector class using expression templates |
madcowswe | 15:9c5aaeda36dc | 42 | */ |
madcowswe | 15:9c5aaeda36dc | 43 | template<std::size_t Sz, std::size_t K=0> |
madcowswe | 15:9c5aaeda36dc | 44 | class Vector |
madcowswe | 15:9c5aaeda36dc | 45 | { |
madcowswe | 15:9c5aaeda36dc | 46 | Vector(); |
madcowswe | 15:9c5aaeda36dc | 47 | Vector(const Vector&); |
madcowswe | 15:9c5aaeda36dc | 48 | Vector& operator=(const Vector&); |
madcowswe | 15:9c5aaeda36dc | 49 | |
madcowswe | 15:9c5aaeda36dc | 50 | private: |
madcowswe | 15:9c5aaeda36dc | 51 | enum { |
madcowswe | 15:9c5aaeda36dc | 52 | doIt = (K < (Sz-1)) ? 1 : 0 /**< recursive counter */ |
madcowswe | 15:9c5aaeda36dc | 53 | }; |
madcowswe | 15:9c5aaeda36dc | 54 | |
madcowswe | 15:9c5aaeda36dc | 55 | public: |
madcowswe | 15:9c5aaeda36dc | 56 | /** assign an expression expr using the functional assign_fn. */ |
madcowswe | 15:9c5aaeda36dc | 57 | template <class Dest, class Src, class Assign> |
madcowswe | 15:9c5aaeda36dc | 58 | static inline |
madcowswe | 15:9c5aaeda36dc | 59 | void assign(Dest& lhs, const Src& rhs, const Assign& assign_fn) { |
madcowswe | 15:9c5aaeda36dc | 60 | assign_fn.apply_on(lhs(K), rhs(K)); |
madcowswe | 15:9c5aaeda36dc | 61 | meta::Vector<Sz * doIt, (K+1) * doIt>::assign(lhs, rhs, assign_fn); |
madcowswe | 15:9c5aaeda36dc | 62 | } |
madcowswe | 15:9c5aaeda36dc | 63 | |
madcowswe | 15:9c5aaeda36dc | 64 | /** build the sum of the vector. */ |
madcowswe | 15:9c5aaeda36dc | 65 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 66 | static inline |
madcowswe | 15:9c5aaeda36dc | 67 | typename E::value_type |
madcowswe | 15:9c5aaeda36dc | 68 | sum(const E& e) { |
madcowswe | 15:9c5aaeda36dc | 69 | return e(K) + meta::Vector<Sz * doIt, (K+1) * doIt>::sum(e); |
madcowswe | 15:9c5aaeda36dc | 70 | } |
madcowswe | 15:9c5aaeda36dc | 71 | |
madcowswe | 15:9c5aaeda36dc | 72 | /** build the product of the vector. */ |
madcowswe | 15:9c5aaeda36dc | 73 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 74 | static inline |
madcowswe | 15:9c5aaeda36dc | 75 | typename NumericTraits< |
madcowswe | 15:9c5aaeda36dc | 76 | typename E::value_type |
madcowswe | 15:9c5aaeda36dc | 77 | >::sum_type |
madcowswe | 15:9c5aaeda36dc | 78 | product(const E& e) { |
madcowswe | 15:9c5aaeda36dc | 79 | return e(K) * meta::Vector<Sz * doIt, (K+1) * doIt>::product(e); |
madcowswe | 15:9c5aaeda36dc | 80 | } |
madcowswe | 15:9c5aaeda36dc | 81 | |
madcowswe | 15:9c5aaeda36dc | 82 | /** build the dot product of the vector. */ |
madcowswe | 15:9c5aaeda36dc | 83 | template<class Dest, class Src> |
madcowswe | 15:9c5aaeda36dc | 84 | static inline |
madcowswe | 15:9c5aaeda36dc | 85 | typename PromoteTraits< |
madcowswe | 15:9c5aaeda36dc | 86 | typename Dest::value_type, |
madcowswe | 15:9c5aaeda36dc | 87 | typename Src::value_type |
madcowswe | 15:9c5aaeda36dc | 88 | >::value_type |
madcowswe | 15:9c5aaeda36dc | 89 | dot(const Dest& lhs, const Src& rhs) { |
madcowswe | 15:9c5aaeda36dc | 90 | return lhs(K) * rhs(K) |
madcowswe | 15:9c5aaeda36dc | 91 | + meta::Vector<Sz * doIt, (K+1) * doIt>::dot(lhs, rhs); |
madcowswe | 15:9c5aaeda36dc | 92 | } |
madcowswe | 15:9c5aaeda36dc | 93 | |
madcowswe | 15:9c5aaeda36dc | 94 | /** check for all elements */ |
madcowswe | 15:9c5aaeda36dc | 95 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 96 | static inline |
madcowswe | 15:9c5aaeda36dc | 97 | bool |
madcowswe | 15:9c5aaeda36dc | 98 | all_elements(const E& e) { |
madcowswe | 15:9c5aaeda36dc | 99 | if(!e(K)) return false; |
madcowswe | 15:9c5aaeda36dc | 100 | return meta::Vector<Sz * doIt, (K+1) * doIt>::all_elements(e); |
madcowswe | 15:9c5aaeda36dc | 101 | } |
madcowswe | 15:9c5aaeda36dc | 102 | |
madcowswe | 15:9c5aaeda36dc | 103 | /** check for any elements */ |
madcowswe | 15:9c5aaeda36dc | 104 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 105 | static inline |
madcowswe | 15:9c5aaeda36dc | 106 | bool |
madcowswe | 15:9c5aaeda36dc | 107 | any_elements(const E& e) { |
madcowswe | 15:9c5aaeda36dc | 108 | if(e(K)) return true; |
madcowswe | 15:9c5aaeda36dc | 109 | return meta::Vector<Sz * doIt, (K+1) * doIt>::any_elements(e); |
madcowswe | 15:9c5aaeda36dc | 110 | } |
madcowswe | 15:9c5aaeda36dc | 111 | }; |
madcowswe | 15:9c5aaeda36dc | 112 | |
madcowswe | 15:9c5aaeda36dc | 113 | |
madcowswe | 15:9c5aaeda36dc | 114 | /** |
madcowswe | 15:9c5aaeda36dc | 115 | * \class Vector<0,0> Vector.h "tvmet/meta/Vector.h" |
madcowswe | 15:9c5aaeda36dc | 116 | * \brief Meta %Vector Specialized for recursion |
madcowswe | 15:9c5aaeda36dc | 117 | */ |
madcowswe | 15:9c5aaeda36dc | 118 | template<> |
madcowswe | 15:9c5aaeda36dc | 119 | class Vector<0,0> |
madcowswe | 15:9c5aaeda36dc | 120 | { |
madcowswe | 15:9c5aaeda36dc | 121 | Vector(); |
madcowswe | 15:9c5aaeda36dc | 122 | Vector(const Vector&); |
madcowswe | 15:9c5aaeda36dc | 123 | Vector& operator=(const Vector&); |
madcowswe | 15:9c5aaeda36dc | 124 | |
madcowswe | 15:9c5aaeda36dc | 125 | public: |
madcowswe | 15:9c5aaeda36dc | 126 | template <class Dest, class Src, class Assign> |
madcowswe | 15:9c5aaeda36dc | 127 | static inline void assign(Dest&, const Src&, const Assign&) { } |
madcowswe | 15:9c5aaeda36dc | 128 | |
madcowswe | 15:9c5aaeda36dc | 129 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 130 | static inline XprNull sum(const E&) { return XprNull(); } |
madcowswe | 15:9c5aaeda36dc | 131 | |
madcowswe | 15:9c5aaeda36dc | 132 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 133 | static inline XprNull product(const E&) { return XprNull(); } |
madcowswe | 15:9c5aaeda36dc | 134 | |
madcowswe | 15:9c5aaeda36dc | 135 | template<class Dest, class Src> |
madcowswe | 15:9c5aaeda36dc | 136 | static inline XprNull dot(const Dest&, const Src&) { return XprNull(); } |
madcowswe | 15:9c5aaeda36dc | 137 | |
madcowswe | 15:9c5aaeda36dc | 138 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 139 | static inline bool all_elements(const E&) { return true; } |
madcowswe | 15:9c5aaeda36dc | 140 | |
madcowswe | 15:9c5aaeda36dc | 141 | template<class E> |
madcowswe | 15:9c5aaeda36dc | 142 | static inline bool any_elements(const E&) { return false; } |
madcowswe | 15:9c5aaeda36dc | 143 | }; |
madcowswe | 15:9c5aaeda36dc | 144 | |
madcowswe | 15:9c5aaeda36dc | 145 | |
madcowswe | 15:9c5aaeda36dc | 146 | } // namespace meta |
madcowswe | 15:9c5aaeda36dc | 147 | |
madcowswe | 15:9c5aaeda36dc | 148 | } // namespace tvmet |
madcowswe | 15:9c5aaeda36dc | 149 | |
madcowswe | 15:9c5aaeda36dc | 150 | #endif /* TVMET_META_VECTOR_H */ |
madcowswe | 15:9c5aaeda36dc | 151 | |
madcowswe | 15:9c5aaeda36dc | 152 | // Local Variables: |
madcowswe | 15:9c5aaeda36dc | 153 | // mode:C++ |
madcowswe | 15:9c5aaeda36dc | 154 | // tab-width:8 |
madcowswe | 15:9c5aaeda36dc | 155 | // End: |