This is some awesome robot code

Dependencies:   mbed-rtos mbed QEI

Fork of ICRSEurobot13 by Thomas Branch

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?

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: VectorImpl.h,v 1.31 2007-06-23 15:58:58 opetzold Exp $
madcowswe 15:9c5aaeda36dc 22 */
madcowswe 15:9c5aaeda36dc 23
madcowswe 15:9c5aaeda36dc 24 #ifndef TVMET_VECTOR_IMPL_H
madcowswe 15:9c5aaeda36dc 25 #define TVMET_VECTOR_IMPL_H
madcowswe 15:9c5aaeda36dc 26
madcowswe 15:9c5aaeda36dc 27 #include <iomanip> // setw
madcowswe 15:9c5aaeda36dc 28
madcowswe 15:9c5aaeda36dc 29 #include <tvmet/Functional.h>
madcowswe 15:9c5aaeda36dc 30 #include <tvmet/Io.h>
madcowswe 15:9c5aaeda36dc 31
madcowswe 15:9c5aaeda36dc 32
madcowswe 15:9c5aaeda36dc 33 namespace tvmet {
madcowswe 15:9c5aaeda36dc 34
madcowswe 15:9c5aaeda36dc 35
madcowswe 15:9c5aaeda36dc 36 /*
madcowswe 15:9c5aaeda36dc 37 * member operators for i/o
madcowswe 15:9c5aaeda36dc 38 */
madcowswe 15:9c5aaeda36dc 39 template<class T, std::size_t Sz>
madcowswe 15:9c5aaeda36dc 40 std::ostream& Vector<T, Sz>::print_xpr(std::ostream& os, std::size_t l) const
madcowswe 15:9c5aaeda36dc 41 {
madcowswe 15:9c5aaeda36dc 42 os << IndentLevel(l++) << "Vector[" << ops << "]<"
madcowswe 15:9c5aaeda36dc 43 << typeid(T).name() << ", " << Size << ">,"
madcowswe 15:9c5aaeda36dc 44 << IndentLevel(--l)
madcowswe 15:9c5aaeda36dc 45 << std::endl;
madcowswe 15:9c5aaeda36dc 46
madcowswe 15:9c5aaeda36dc 47 return os;
madcowswe 15:9c5aaeda36dc 48 }
madcowswe 15:9c5aaeda36dc 49
madcowswe 15:9c5aaeda36dc 50
madcowswe 15:9c5aaeda36dc 51 template<class T, std::size_t Sz>
madcowswe 15:9c5aaeda36dc 52 std::ostream& Vector<T, Sz>::print_on(std::ostream& os) const
madcowswe 15:9c5aaeda36dc 53 {
madcowswe 15:9c5aaeda36dc 54 enum {
madcowswe 15:9c5aaeda36dc 55 complex_type = NumericTraits<value_type>::is_complex
madcowswe 15:9c5aaeda36dc 56 };
madcowswe 15:9c5aaeda36dc 57
madcowswe 15:9c5aaeda36dc 58 std::streamsize w = IoPrintHelper<Vector>::width(dispatch<complex_type>(), *this);
madcowswe 15:9c5aaeda36dc 59
madcowswe 15:9c5aaeda36dc 60 os << std::setw(0) << "[\n ";
madcowswe 15:9c5aaeda36dc 61 for(std::size_t i = 0; i < (Size - 1); ++i) {
madcowswe 15:9c5aaeda36dc 62 os << std::setw(w) << m_data[i] << ", ";
madcowswe 15:9c5aaeda36dc 63 }
madcowswe 15:9c5aaeda36dc 64 os << std::setw(w) << m_data[Size - 1] << "\n]";
madcowswe 15:9c5aaeda36dc 65
madcowswe 15:9c5aaeda36dc 66 return os;
madcowswe 15:9c5aaeda36dc 67 }
madcowswe 15:9c5aaeda36dc 68
madcowswe 15:9c5aaeda36dc 69
madcowswe 15:9c5aaeda36dc 70 /*
madcowswe 15:9c5aaeda36dc 71 * member operators with scalars, per se element wise
madcowswe 15:9c5aaeda36dc 72 */
madcowswe 15:9c5aaeda36dc 73 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
madcowswe 15:9c5aaeda36dc 74 template<class T, std::size_t Sz> \
madcowswe 15:9c5aaeda36dc 75 inline \
madcowswe 15:9c5aaeda36dc 76 Vector<T, Sz>& Vector<T, Sz>::operator OP (value_type rhs) { \
madcowswe 15:9c5aaeda36dc 77 typedef XprLiteral<value_type> expr_type; \
madcowswe 15:9c5aaeda36dc 78 this->M_##NAME(XprVector<expr_type, Size>(expr_type(rhs))); \
madcowswe 15:9c5aaeda36dc 79 return *this; \
madcowswe 15:9c5aaeda36dc 80 }
madcowswe 15:9c5aaeda36dc 81
madcowswe 15:9c5aaeda36dc 82 TVMET_IMPLEMENT_MACRO(add_eq, +=)
madcowswe 15:9c5aaeda36dc 83 TVMET_IMPLEMENT_MACRO(sub_eq, -=)
madcowswe 15:9c5aaeda36dc 84 TVMET_IMPLEMENT_MACRO(mul_eq, *=)
madcowswe 15:9c5aaeda36dc 85 TVMET_IMPLEMENT_MACRO(div_eq, /=)
madcowswe 15:9c5aaeda36dc 86 #undef TVMET_IMPLEMENT_MACRO
madcowswe 15:9c5aaeda36dc 87
madcowswe 15:9c5aaeda36dc 88
madcowswe 15:9c5aaeda36dc 89 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
madcowswe 15:9c5aaeda36dc 90 template<class T, std::size_t Sz> \
madcowswe 15:9c5aaeda36dc 91 inline \
madcowswe 15:9c5aaeda36dc 92 Vector<T, Sz>& Vector<T, Sz>::operator OP (std::size_t rhs) { \
madcowswe 15:9c5aaeda36dc 93 typedef XprLiteral<value_type> expr_type; \
madcowswe 15:9c5aaeda36dc 94 this->M_##NAME(XprVector<expr_type, Size>(expr_type(rhs))); \
madcowswe 15:9c5aaeda36dc 95 return *this; \
madcowswe 15:9c5aaeda36dc 96 }
madcowswe 15:9c5aaeda36dc 97
madcowswe 15:9c5aaeda36dc 98 TVMET_IMPLEMENT_MACRO(mod_eq, %=)
madcowswe 15:9c5aaeda36dc 99 TVMET_IMPLEMENT_MACRO(xor_eq,^=)
madcowswe 15:9c5aaeda36dc 100 TVMET_IMPLEMENT_MACRO(and_eq, &=)
madcowswe 15:9c5aaeda36dc 101 TVMET_IMPLEMENT_MACRO(or_eq, |=)
madcowswe 15:9c5aaeda36dc 102 TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
madcowswe 15:9c5aaeda36dc 103 TVMET_IMPLEMENT_MACRO(shr_eq, >>=)
madcowswe 15:9c5aaeda36dc 104 #undef TVMET_IMPLEMENT_MACRO
madcowswe 15:9c5aaeda36dc 105
madcowswe 15:9c5aaeda36dc 106
madcowswe 15:9c5aaeda36dc 107 /*
madcowswe 15:9c5aaeda36dc 108 * member functions (operators) with vectors, for use with +=,-= ... <<=
madcowswe 15:9c5aaeda36dc 109 */
madcowswe 15:9c5aaeda36dc 110 #define TVMET_IMPLEMENT_MACRO(NAME) \
madcowswe 15:9c5aaeda36dc 111 template<class T1, std::size_t Sz> \
madcowswe 15:9c5aaeda36dc 112 template <class T2> \
madcowswe 15:9c5aaeda36dc 113 inline Vector<T1, Sz>& \
madcowswe 15:9c5aaeda36dc 114 Vector<T1, Sz>::M_##NAME (const Vector<T2, Size>& rhs) { \
madcowswe 15:9c5aaeda36dc 115 this->M_##NAME( XprVector<typename Vector<T2, Size>::ConstReference, Size>(rhs.const_ref()) ); \
madcowswe 15:9c5aaeda36dc 116 return *this; \
madcowswe 15:9c5aaeda36dc 117 }
madcowswe 15:9c5aaeda36dc 118
madcowswe 15:9c5aaeda36dc 119 TVMET_IMPLEMENT_MACRO(add_eq)
madcowswe 15:9c5aaeda36dc 120 TVMET_IMPLEMENT_MACRO(sub_eq)
madcowswe 15:9c5aaeda36dc 121 TVMET_IMPLEMENT_MACRO(mul_eq)
madcowswe 15:9c5aaeda36dc 122 TVMET_IMPLEMENT_MACRO(div_eq)
madcowswe 15:9c5aaeda36dc 123 TVMET_IMPLEMENT_MACRO(mod_eq)
madcowswe 15:9c5aaeda36dc 124 TVMET_IMPLEMENT_MACRO(xor_eq)
madcowswe 15:9c5aaeda36dc 125 TVMET_IMPLEMENT_MACRO(and_eq)
madcowswe 15:9c5aaeda36dc 126 TVMET_IMPLEMENT_MACRO(or_eq)
madcowswe 15:9c5aaeda36dc 127 TVMET_IMPLEMENT_MACRO(shl_eq)
madcowswe 15:9c5aaeda36dc 128 TVMET_IMPLEMENT_MACRO(shr_eq)
madcowswe 15:9c5aaeda36dc 129 #undef TVMET_IMPLEMENT_MACRO
madcowswe 15:9c5aaeda36dc 130
madcowswe 15:9c5aaeda36dc 131
madcowswe 15:9c5aaeda36dc 132 /*
madcowswe 15:9c5aaeda36dc 133 * member functions (operators) with expressions, for use width +=,-= ... <<=
madcowswe 15:9c5aaeda36dc 134 */
madcowswe 15:9c5aaeda36dc 135 #define TVMET_IMPLEMENT_MACRO(NAME) \
madcowswe 15:9c5aaeda36dc 136 template<class T, std::size_t Sz> \
madcowswe 15:9c5aaeda36dc 137 template <class E> \
madcowswe 15:9c5aaeda36dc 138 inline \
madcowswe 15:9c5aaeda36dc 139 Vector<T, Sz>& \
madcowswe 15:9c5aaeda36dc 140 Vector<T, Sz>::M_##NAME (const XprVector<E, Size>& rhs) { \
madcowswe 15:9c5aaeda36dc 141 rhs.assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
madcowswe 15:9c5aaeda36dc 142 return *this; \
madcowswe 15:9c5aaeda36dc 143 }
madcowswe 15:9c5aaeda36dc 144
madcowswe 15:9c5aaeda36dc 145 TVMET_IMPLEMENT_MACRO(add_eq)
madcowswe 15:9c5aaeda36dc 146 TVMET_IMPLEMENT_MACRO(sub_eq)
madcowswe 15:9c5aaeda36dc 147 TVMET_IMPLEMENT_MACRO(mul_eq)
madcowswe 15:9c5aaeda36dc 148 TVMET_IMPLEMENT_MACRO(div_eq)
madcowswe 15:9c5aaeda36dc 149 TVMET_IMPLEMENT_MACRO(mod_eq)
madcowswe 15:9c5aaeda36dc 150 TVMET_IMPLEMENT_MACRO(xor_eq)
madcowswe 15:9c5aaeda36dc 151 TVMET_IMPLEMENT_MACRO(and_eq)
madcowswe 15:9c5aaeda36dc 152 TVMET_IMPLEMENT_MACRO(or_eq)
madcowswe 15:9c5aaeda36dc 153 TVMET_IMPLEMENT_MACRO(shl_eq)
madcowswe 15:9c5aaeda36dc 154 TVMET_IMPLEMENT_MACRO(shr_eq)
madcowswe 15:9c5aaeda36dc 155 #undef TVMET_IMPLEMENT_MACRO
madcowswe 15:9c5aaeda36dc 156
madcowswe 15:9c5aaeda36dc 157
madcowswe 15:9c5aaeda36dc 158 /*
madcowswe 15:9c5aaeda36dc 159 * aliased member functions (operators) with vectors,
madcowswe 15:9c5aaeda36dc 160 * for use with +=,-= ... <<=
madcowswe 15:9c5aaeda36dc 161 */
madcowswe 15:9c5aaeda36dc 162 #define TVMET_IMPLEMENT_MACRO(NAME) \
madcowswe 15:9c5aaeda36dc 163 template<class T1, std::size_t Sz> \
madcowswe 15:9c5aaeda36dc 164 template <class T2> \
madcowswe 15:9c5aaeda36dc 165 inline \
madcowswe 15:9c5aaeda36dc 166 Vector<T1, Sz>& \
madcowswe 15:9c5aaeda36dc 167 Vector<T1, Sz>::alias_##NAME (const Vector<T2, Size>& rhs) { \
madcowswe 15:9c5aaeda36dc 168 this->alias_##NAME( XprVector<typename Vector<T2, Size>::ConstReference, Size>(rhs.const_ref()) ); \
madcowswe 15:9c5aaeda36dc 169 return *this; \
madcowswe 15:9c5aaeda36dc 170 }
madcowswe 15:9c5aaeda36dc 171
madcowswe 15:9c5aaeda36dc 172 TVMET_IMPLEMENT_MACRO(assign)
madcowswe 15:9c5aaeda36dc 173 TVMET_IMPLEMENT_MACRO(add_eq)
madcowswe 15:9c5aaeda36dc 174 TVMET_IMPLEMENT_MACRO(sub_eq)
madcowswe 15:9c5aaeda36dc 175 TVMET_IMPLEMENT_MACRO(mul_eq)
madcowswe 15:9c5aaeda36dc 176 TVMET_IMPLEMENT_MACRO(div_eq)
madcowswe 15:9c5aaeda36dc 177 #undef TVMET_IMPLEMENT_MACRO
madcowswe 15:9c5aaeda36dc 178
madcowswe 15:9c5aaeda36dc 179
madcowswe 15:9c5aaeda36dc 180 /*
madcowswe 15:9c5aaeda36dc 181 * aliased member functions (operators) with expressions,
madcowswe 15:9c5aaeda36dc 182 * for use width +=,-= ... <<=
madcowswe 15:9c5aaeda36dc 183 */
madcowswe 15:9c5aaeda36dc 184 #define TVMET_IMPLEMENT_MACRO(NAME) \
madcowswe 15:9c5aaeda36dc 185 template<class T, std::size_t Sz> \
madcowswe 15:9c5aaeda36dc 186 template <class E> \
madcowswe 15:9c5aaeda36dc 187 inline \
madcowswe 15:9c5aaeda36dc 188 Vector<T, Sz>& \
madcowswe 15:9c5aaeda36dc 189 Vector<T, Sz>::alias_##NAME (const XprVector<E, Size>& rhs) { \
madcowswe 15:9c5aaeda36dc 190 typedef Vector<T, Sz> temp_type; \
madcowswe 15:9c5aaeda36dc 191 temp_type(rhs).assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \
madcowswe 15:9c5aaeda36dc 192 return *this; \
madcowswe 15:9c5aaeda36dc 193 }
madcowswe 15:9c5aaeda36dc 194
madcowswe 15:9c5aaeda36dc 195 TVMET_IMPLEMENT_MACRO(assign)
madcowswe 15:9c5aaeda36dc 196 TVMET_IMPLEMENT_MACRO(add_eq)
madcowswe 15:9c5aaeda36dc 197 TVMET_IMPLEMENT_MACRO(sub_eq)
madcowswe 15:9c5aaeda36dc 198 TVMET_IMPLEMENT_MACRO(mul_eq)
madcowswe 15:9c5aaeda36dc 199 TVMET_IMPLEMENT_MACRO(div_eq)
madcowswe 15:9c5aaeda36dc 200 #undef TVMET_IMPLEMENT_MACRO
madcowswe 15:9c5aaeda36dc 201
madcowswe 15:9c5aaeda36dc 202
madcowswe 15:9c5aaeda36dc 203 } // namespace tvmet
madcowswe 15:9c5aaeda36dc 204
madcowswe 15:9c5aaeda36dc 205 #endif // TVMET_VECTOR_IMPL_H
madcowswe 15:9c5aaeda36dc 206
madcowswe 15:9c5aaeda36dc 207 // Local Variables:
madcowswe 15:9c5aaeda36dc 208 // mode:C++
madcowswe 15:9c5aaeda36dc 209 // tab-width:8
madcowswe 15:9c5aaeda36dc 210 // End: