Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Eurobot_2012_Secondary by
VectorImpl.h
00001 /* 00002 * Tiny Vector Matrix Library 00003 * Dense Vector Matrix Libary of Tiny size using Expression Templates 00004 * 00005 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * $Id: VectorImpl.h,v 1.31 2007-06-23 15:58:58 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_VECTOR_IMPL_H 00025 #define TVMET_VECTOR_IMPL_H 00026 00027 #include <iomanip> // setw 00028 00029 #include <tvmet/Functional.h> 00030 #include <tvmet/Io.h> 00031 00032 00033 namespace tvmet { 00034 00035 00036 /* 00037 * member operators for i/o 00038 */ 00039 template<class T, std::size_t Sz> 00040 std::ostream& Vector<T, Sz>::print_xpr(std::ostream& os, std::size_t l) const 00041 { 00042 os << IndentLevel(l++) << "Vector[" << ops << "]<" 00043 << typeid(T).name() << ", " << Size << ">," 00044 << IndentLevel(--l) 00045 << std::endl; 00046 00047 return os; 00048 } 00049 00050 00051 template<class T, std::size_t Sz> 00052 std::ostream& Vector<T, Sz>::print_on(std::ostream& os) const 00053 { 00054 enum { 00055 complex_type = NumericTraits<value_type>::is_complex 00056 }; 00057 00058 std::streamsize w = IoPrintHelper<Vector>::width(dispatch<complex_type>(), *this); 00059 00060 os << std::setw(0) << "[\n "; 00061 for(std::size_t i = 0; i < (Size - 1); ++i) { 00062 os << std::setw(w) << m_data[i] << ", "; 00063 } 00064 os << std::setw(w) << m_data[Size - 1] << "\n]"; 00065 00066 return os; 00067 } 00068 00069 00070 /* 00071 * member operators with scalars, per se element wise 00072 */ 00073 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ 00074 template<class T, std::size_t Sz> \ 00075 inline \ 00076 Vector<T, Sz>& Vector<T, Sz>::operator OP (value_type rhs) { \ 00077 typedef XprLiteral<value_type> expr_type; \ 00078 this->M_##NAME(XprVector<expr_type, Size>(expr_type(rhs))); \ 00079 return *this; \ 00080 } 00081 00082 TVMET_IMPLEMENT_MACRO(add_eq, +=) 00083 TVMET_IMPLEMENT_MACRO(sub_eq, -=) 00084 TVMET_IMPLEMENT_MACRO(mul_eq, *=) 00085 TVMET_IMPLEMENT_MACRO(div_eq, /=) 00086 #undef TVMET_IMPLEMENT_MACRO 00087 00088 00089 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ 00090 template<class T, std::size_t Sz> \ 00091 inline \ 00092 Vector<T, Sz>& Vector<T, Sz>::operator OP (std::size_t rhs) { \ 00093 typedef XprLiteral<value_type> expr_type; \ 00094 this->M_##NAME(XprVector<expr_type, Size>(expr_type(rhs))); \ 00095 return *this; \ 00096 } 00097 00098 TVMET_IMPLEMENT_MACRO(mod_eq, %=) 00099 TVMET_IMPLEMENT_MACRO(xor_eq,^=) 00100 TVMET_IMPLEMENT_MACRO(and_eq, &=) 00101 TVMET_IMPLEMENT_MACRO(or_eq, |=) 00102 TVMET_IMPLEMENT_MACRO(shl_eq, <<=) 00103 TVMET_IMPLEMENT_MACRO(shr_eq, >>=) 00104 #undef TVMET_IMPLEMENT_MACRO 00105 00106 00107 /* 00108 * member functions (operators) with vectors, for use with +=,-= ... <<= 00109 */ 00110 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00111 template<class T1, std::size_t Sz> \ 00112 template <class T2> \ 00113 inline Vector<T1, Sz>& \ 00114 Vector<T1, Sz>::M_##NAME (const Vector<T2, Size>& rhs) { \ 00115 this->M_##NAME( XprVector<typename Vector<T2, Size>::ConstReference, Size>(rhs.const_ref()) ); \ 00116 return *this; \ 00117 } 00118 00119 TVMET_IMPLEMENT_MACRO(add_eq) 00120 TVMET_IMPLEMENT_MACRO(sub_eq) 00121 TVMET_IMPLEMENT_MACRO(mul_eq) 00122 TVMET_IMPLEMENT_MACRO(div_eq) 00123 TVMET_IMPLEMENT_MACRO(mod_eq) 00124 TVMET_IMPLEMENT_MACRO(xor_eq) 00125 TVMET_IMPLEMENT_MACRO(and_eq) 00126 TVMET_IMPLEMENT_MACRO(or_eq) 00127 TVMET_IMPLEMENT_MACRO(shl_eq) 00128 TVMET_IMPLEMENT_MACRO(shr_eq) 00129 #undef TVMET_IMPLEMENT_MACRO 00130 00131 00132 /* 00133 * member functions (operators) with expressions, for use width +=,-= ... <<= 00134 */ 00135 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00136 template<class T, std::size_t Sz> \ 00137 template <class E> \ 00138 inline \ 00139 Vector<T, Sz>& \ 00140 Vector<T, Sz>::M_##NAME (const XprVector<E, Size>& rhs) { \ 00141 rhs.assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \ 00142 return *this; \ 00143 } 00144 00145 TVMET_IMPLEMENT_MACRO(add_eq) 00146 TVMET_IMPLEMENT_MACRO(sub_eq) 00147 TVMET_IMPLEMENT_MACRO(mul_eq) 00148 TVMET_IMPLEMENT_MACRO(div_eq) 00149 TVMET_IMPLEMENT_MACRO(mod_eq) 00150 TVMET_IMPLEMENT_MACRO(xor_eq) 00151 TVMET_IMPLEMENT_MACRO(and_eq) 00152 TVMET_IMPLEMENT_MACRO(or_eq) 00153 TVMET_IMPLEMENT_MACRO(shl_eq) 00154 TVMET_IMPLEMENT_MACRO(shr_eq) 00155 #undef TVMET_IMPLEMENT_MACRO 00156 00157 00158 /* 00159 * aliased member functions (operators) with vectors, 00160 * for use with +=,-= ... <<= 00161 */ 00162 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00163 template<class T1, std::size_t Sz> \ 00164 template <class T2> \ 00165 inline \ 00166 Vector<T1, Sz>& \ 00167 Vector<T1, Sz>::alias_##NAME (const Vector<T2, Size>& rhs) { \ 00168 this->alias_##NAME( XprVector<typename Vector<T2, Size>::ConstReference, Size>(rhs.const_ref()) ); \ 00169 return *this; \ 00170 } 00171 00172 TVMET_IMPLEMENT_MACRO(assign) 00173 TVMET_IMPLEMENT_MACRO(add_eq) 00174 TVMET_IMPLEMENT_MACRO(sub_eq) 00175 TVMET_IMPLEMENT_MACRO(mul_eq) 00176 TVMET_IMPLEMENT_MACRO(div_eq) 00177 #undef TVMET_IMPLEMENT_MACRO 00178 00179 00180 /* 00181 * aliased member functions (operators) with expressions, 00182 * for use width +=,-= ... <<= 00183 */ 00184 #define TVMET_IMPLEMENT_MACRO(NAME) \ 00185 template<class T, std::size_t Sz> \ 00186 template <class E> \ 00187 inline \ 00188 Vector<T, Sz>& \ 00189 Vector<T, Sz>::alias_##NAME (const XprVector<E, Size>& rhs) { \ 00190 typedef Vector<T, Sz> temp_type; \ 00191 temp_type(rhs).assign_to(*this, Fcnl_##NAME<value_type, typename E::value_type>()); \ 00192 return *this; \ 00193 } 00194 00195 TVMET_IMPLEMENT_MACRO(assign) 00196 TVMET_IMPLEMENT_MACRO(add_eq) 00197 TVMET_IMPLEMENT_MACRO(sub_eq) 00198 TVMET_IMPLEMENT_MACRO(mul_eq) 00199 TVMET_IMPLEMENT_MACRO(div_eq) 00200 #undef TVMET_IMPLEMENT_MACRO 00201 00202 00203 } // namespace tvmet 00204 00205 #endif // TVMET_VECTOR_IMPL_H 00206 00207 // Local Variables: 00208 // mode:C++ 00209 // tab-width:8 00210 // End:
Generated on Tue Jul 12 2022 21:02:14 by
