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