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