We are going to win! wohoo

Dependencies:   mbed mbed-rtos

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?

UserRevisionLine numberNew 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: BinaryFunctionals.h,v 1.24 2007-06-23 15:58:58 opetzold Exp $
sv 1:6799c07fe510 22 */
sv 1:6799c07fe510 23
sv 1:6799c07fe510 24 #ifndef TVMET_BINARY_FUNCTIONAL_H
sv 1:6799c07fe510 25 #define TVMET_BINARY_FUNCTIONAL_H
sv 1:6799c07fe510 26
sv 1:6799c07fe510 27 namespace tvmet {
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29
sv 1:6799c07fe510 30 /**
sv 1:6799c07fe510 31 * \class Fcnl_assign BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
sv 1:6799c07fe510 32 * \brief Binary operator for assign operations.
sv 1:6799c07fe510 33 *
sv 1:6799c07fe510 34 * Unfortunally we have sometimes to cast on assign operations e.g.,
sv 1:6799c07fe510 35 * on assign on different POD. So we avoid warnings.
sv 1:6799c07fe510 36 */
sv 1:6799c07fe510 37 template <class T1, class T2>
sv 1:6799c07fe510 38 struct Fcnl_assign : public BinaryFunctional {
sv 1:6799c07fe510 39 static inline
sv 1:6799c07fe510 40 void apply_on(T1& _tvmet_restrict lhs, T2 rhs) {
sv 1:6799c07fe510 41 lhs = static_cast<T1>(rhs);
sv 1:6799c07fe510 42 }
sv 1:6799c07fe510 43
sv 1:6799c07fe510 44 static
sv 1:6799c07fe510 45 void print_xpr(std::ostream& os, std::size_t l=0) {
sv 1:6799c07fe510 46 os << IndentLevel(l) << "fcnl_assign<T1="
sv 1:6799c07fe510 47 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"
sv 1:6799c07fe510 48 << std::endl;
sv 1:6799c07fe510 49 }
sv 1:6799c07fe510 50 };
sv 1:6799c07fe510 51
sv 1:6799c07fe510 52
sv 1:6799c07fe510 53 /** \class Fcnl_add_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 54 /** \class Fcnl_sub_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 55 /** \class Fcnl_mul_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 56 /** \class Fcnl_div_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 57 /** \class Fcnl_mod_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 58 /** \class Fcnl_xor_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 59 /** \class Fcnl_and_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 60 /** \class Fcnl_or_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 61 /** \class Fcnl_shl_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 62 /** \class Fcnl_shr_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 63 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 64 template <class T1, class T2> \
sv 1:6799c07fe510 65 struct Fcnl_##NAME : public BinaryFunctional { \
sv 1:6799c07fe510 66 typedef void value_type; \
sv 1:6799c07fe510 67 \
sv 1:6799c07fe510 68 static inline \
sv 1:6799c07fe510 69 void apply_on(T1& _tvmet_restrict lhs, T2 rhs) { \
sv 1:6799c07fe510 70 lhs OP rhs; \
sv 1:6799c07fe510 71 } \
sv 1:6799c07fe510 72 \
sv 1:6799c07fe510 73 static \
sv 1:6799c07fe510 74 void print_xpr(std::ostream& os, std::size_t l=0) { \
sv 1:6799c07fe510 75 os << IndentLevel(l) \
sv 1:6799c07fe510 76 << "Fcnl_" << #NAME << "<T1=" \
sv 1:6799c07fe510 77 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
sv 1:6799c07fe510 78 << std::endl; \
sv 1:6799c07fe510 79 } \
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 TVMET_IMPLEMENT_MACRO(mod_eq, %=)
sv 1:6799c07fe510 87 TVMET_IMPLEMENT_MACRO(xor_eq, ^=)
sv 1:6799c07fe510 88 TVMET_IMPLEMENT_MACRO(and_eq, &=)
sv 1:6799c07fe510 89 TVMET_IMPLEMENT_MACRO(or_eq, |=)
sv 1:6799c07fe510 90 TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
sv 1:6799c07fe510 91 TVMET_IMPLEMENT_MACRO(shr_eq, >>=)
sv 1:6799c07fe510 92
sv 1:6799c07fe510 93 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 94
sv 1:6799c07fe510 95
sv 1:6799c07fe510 96 /** \class Fcnl_add BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 97 /** \class Fcnl_sub BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 98 /** \class Fcnl_mul BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 99 /** \class Fcnl_div BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 100 /** \class Fcnl_mod BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 101 /** \class Fcnl_bitxor BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 102 /** \class Fcnl_bitand BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 103 /** \class Fcnl_bitor BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 104 /** \class Fcnl_shl BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 105 /** \class Fcnl_shr BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 106 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 107 template <class T1, class T2> \
sv 1:6799c07fe510 108 struct Fcnl_##NAME : public BinaryFunctional { \
sv 1:6799c07fe510 109 typedef typename PromoteTraits<T1, T2>::value_type value_type; \
sv 1:6799c07fe510 110 \
sv 1:6799c07fe510 111 static inline \
sv 1:6799c07fe510 112 value_type apply_on(T1 lhs, T2 rhs) { \
sv 1:6799c07fe510 113 return lhs OP rhs; \
sv 1:6799c07fe510 114 } \
sv 1:6799c07fe510 115 \
sv 1:6799c07fe510 116 static \
sv 1:6799c07fe510 117 void print_xpr(std::ostream& os, std::size_t l=0) { \
sv 1:6799c07fe510 118 os << IndentLevel(l) \
sv 1:6799c07fe510 119 << "Fcnl_" << #NAME << "<T1=" \
sv 1:6799c07fe510 120 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
sv 1:6799c07fe510 121 << std::endl; \
sv 1:6799c07fe510 122 } \
sv 1:6799c07fe510 123 };
sv 1:6799c07fe510 124
sv 1:6799c07fe510 125 TVMET_IMPLEMENT_MACRO(add, +)
sv 1:6799c07fe510 126 TVMET_IMPLEMENT_MACRO(sub, -)
sv 1:6799c07fe510 127 TVMET_IMPLEMENT_MACRO(mul, *)
sv 1:6799c07fe510 128 TVMET_IMPLEMENT_MACRO(div, /)
sv 1:6799c07fe510 129 TVMET_IMPLEMENT_MACRO(mod, %)
sv 1:6799c07fe510 130 TVMET_IMPLEMENT_MACRO(bitxor, ^)
sv 1:6799c07fe510 131 TVMET_IMPLEMENT_MACRO(bitand, &)
sv 1:6799c07fe510 132 TVMET_IMPLEMENT_MACRO(bitor, |)
sv 1:6799c07fe510 133 TVMET_IMPLEMENT_MACRO(shl, <<)
sv 1:6799c07fe510 134 TVMET_IMPLEMENT_MACRO(shr, >>)
sv 1:6799c07fe510 135
sv 1:6799c07fe510 136 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 137
sv 1:6799c07fe510 138
sv 1:6799c07fe510 139 /** \class Fcnl_greater BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 140 /** \class Fcnl_greater_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 141 /** \class Fcnl_less BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 142 /** \class Fcnl_less_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 143 /** \class Fcnl_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 144 /** \class Fcnl_not_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 145 /** \class Fcnl_and BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 146 /** \class Fcnl_or BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 147 #define TVMET_IMPLEMENT_MACRO(NAME, OP) \
sv 1:6799c07fe510 148 template <class T1, class T2> \
sv 1:6799c07fe510 149 struct Fcnl_##NAME : public BinaryFunctional { \
sv 1:6799c07fe510 150 typedef bool value_type; \
sv 1:6799c07fe510 151 \
sv 1:6799c07fe510 152 static inline \
sv 1:6799c07fe510 153 bool apply_on(T1 lhs, T2 rhs) { \
sv 1:6799c07fe510 154 return lhs OP rhs; \
sv 1:6799c07fe510 155 } \
sv 1:6799c07fe510 156 \
sv 1:6799c07fe510 157 static \
sv 1:6799c07fe510 158 void print_xpr(std::ostream& os, std::size_t l=0) { \
sv 1:6799c07fe510 159 os << IndentLevel(l) \
sv 1:6799c07fe510 160 << "Fcnl_" << #NAME << "<T1=" \
sv 1:6799c07fe510 161 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
sv 1:6799c07fe510 162 << std::endl; \
sv 1:6799c07fe510 163 } \
sv 1:6799c07fe510 164 };
sv 1:6799c07fe510 165
sv 1:6799c07fe510 166 TVMET_IMPLEMENT_MACRO(greater, >)
sv 1:6799c07fe510 167 TVMET_IMPLEMENT_MACRO(less, <)
sv 1:6799c07fe510 168 TVMET_IMPLEMENT_MACRO(greater_eq, >=)
sv 1:6799c07fe510 169 TVMET_IMPLEMENT_MACRO(less_eq, <=)
sv 1:6799c07fe510 170 TVMET_IMPLEMENT_MACRO(eq, ==)
sv 1:6799c07fe510 171 TVMET_IMPLEMENT_MACRO(not_eq, !=)
sv 1:6799c07fe510 172 TVMET_IMPLEMENT_MACRO(and, &&)
sv 1:6799c07fe510 173 TVMET_IMPLEMENT_MACRO(or, ||)
sv 1:6799c07fe510 174
sv 1:6799c07fe510 175 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 176
sv 1:6799c07fe510 177
sv 1:6799c07fe510 178 /** \class Fcnl_atan2 BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 179 /** \class Fcnl_fmod BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 180 /** \class Fcnl_pow BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 181 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 182 template <class T1, class T2> \
sv 1:6799c07fe510 183 struct Fcnl_##NAME : public BinaryFunctional { \
sv 1:6799c07fe510 184 typedef typename PromoteTraits<T1, T2>::value_type value_type; \
sv 1:6799c07fe510 185 \
sv 1:6799c07fe510 186 static inline \
sv 1:6799c07fe510 187 value_type apply_on(T1 lhs, T2 rhs) { \
sv 1:6799c07fe510 188 return TVMET_STD_SCOPE(NAME)(lhs, rhs); \
sv 1:6799c07fe510 189 } \
sv 1:6799c07fe510 190 \
sv 1:6799c07fe510 191 static \
sv 1:6799c07fe510 192 void print_xpr(std::ostream& os, std::size_t l=0) { \
sv 1:6799c07fe510 193 os << IndentLevel(l) \
sv 1:6799c07fe510 194 << "Fcnl_" << #NAME << "<T1=" \
sv 1:6799c07fe510 195 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
sv 1:6799c07fe510 196 << std::endl; \
sv 1:6799c07fe510 197 } \
sv 1:6799c07fe510 198 };
sv 1:6799c07fe510 199
sv 1:6799c07fe510 200 TVMET_IMPLEMENT_MACRO(atan2)
sv 1:6799c07fe510 201 TVMET_IMPLEMENT_MACRO(fmod)
sv 1:6799c07fe510 202 TVMET_IMPLEMENT_MACRO(pow)
sv 1:6799c07fe510 203
sv 1:6799c07fe510 204 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 205
sv 1:6799c07fe510 206
sv 1:6799c07fe510 207 /** \class Fcnl_drem BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 208 /** \class Fcnl_hypot BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 209 /** \class Fcnl_jn BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 210 /** \class Fcnl_yn BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
sv 1:6799c07fe510 211 #define TVMET_IMPLEMENT_MACRO(NAME) \
sv 1:6799c07fe510 212 template <class T1, class T2> \
sv 1:6799c07fe510 213 struct Fcnl_##NAME : public BinaryFunctional { \
sv 1:6799c07fe510 214 typedef typename PromoteTraits<T1, T2>::value_type value_type; \
sv 1:6799c07fe510 215 \
sv 1:6799c07fe510 216 static inline \
sv 1:6799c07fe510 217 value_type apply_on(T1 lhs, T2 rhs) { \
sv 1:6799c07fe510 218 return TVMET_GLOBAL_SCOPE(NAME)(lhs, rhs); \
sv 1:6799c07fe510 219 } \
sv 1:6799c07fe510 220 \
sv 1:6799c07fe510 221 static \
sv 1:6799c07fe510 222 void print_xpr(std::ostream& os, std::size_t l=0) { \
sv 1:6799c07fe510 223 os << IndentLevel(l) \
sv 1:6799c07fe510 224 << "Fcnl_" << #NAME << "<T1=" \
sv 1:6799c07fe510 225 << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \
sv 1:6799c07fe510 226 << std::endl; \
sv 1:6799c07fe510 227 } \
sv 1:6799c07fe510 228 };
sv 1:6799c07fe510 229
sv 1:6799c07fe510 230 TVMET_IMPLEMENT_MACRO(drem)
sv 1:6799c07fe510 231 TVMET_IMPLEMENT_MACRO(hypot)
sv 1:6799c07fe510 232 TVMET_IMPLEMENT_MACRO(jn)
sv 1:6799c07fe510 233 TVMET_IMPLEMENT_MACRO(yn)
sv 1:6799c07fe510 234
sv 1:6799c07fe510 235 #undef TVMET_IMPLEMENT_MACRO
sv 1:6799c07fe510 236
sv 1:6799c07fe510 237
sv 1:6799c07fe510 238 #if defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 239 /**
sv 1:6799c07fe510 240 * \class Fcnl_polar BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
sv 1:6799c07fe510 241 * \brief %Functional for polar.
sv 1:6799c07fe510 242 */
sv 1:6799c07fe510 243 template <class T1, class T2> struct Fcnl_polar : public BinaryFunctional { };
sv 1:6799c07fe510 244
sv 1:6799c07fe510 245
sv 1:6799c07fe510 246 /**
sv 1:6799c07fe510 247 * \class Fcnl_polar<T,T> BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
sv 1:6799c07fe510 248 * \brief %Functional for polar.
sv 1:6799c07fe510 249 * \note This functional is partialy specialized due to the declaration
sv 1:6799c07fe510 250 * of %polar in namespace std <tt>complex<T> polar(T, T)</tt>.
sv 1:6799c07fe510 251 * This means especially that type promotion isn't avaible here.
sv 1:6799c07fe510 252 */
sv 1:6799c07fe510 253 template <class T>
sv 1:6799c07fe510 254 struct Fcnl_polar<T,T> : public BinaryFunctional {
sv 1:6799c07fe510 255 typedef std::complex<T> value_type;
sv 1:6799c07fe510 256
sv 1:6799c07fe510 257 static inline
sv 1:6799c07fe510 258 value_type apply_on(T lhs, T rhs) {
sv 1:6799c07fe510 259 return std::polar(lhs, rhs);
sv 1:6799c07fe510 260 }
sv 1:6799c07fe510 261
sv 1:6799c07fe510 262 static
sv 1:6799c07fe510 263 void print_xpr(std::ostream& os, std::size_t l=0) {
sv 1:6799c07fe510 264 os << IndentLevel(l) << "Fcnl_polar<T1="
sv 1:6799c07fe510 265 << typeid(T).name() << ", T2=" << typeid(T).name() << ">,"
sv 1:6799c07fe510 266 << std::endl;
sv 1:6799c07fe510 267 }
sv 1:6799c07fe510 268 };
sv 1:6799c07fe510 269 #endif // defined(TVMET_HAVE_COMPLEX)
sv 1:6799c07fe510 270
sv 1:6799c07fe510 271
sv 1:6799c07fe510 272 /**
sv 1:6799c07fe510 273 * \class Fcnl_swap BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
sv 1:6799c07fe510 274 * \brief Binary operator for swapping values using temporaries.
sv 1:6799c07fe510 275 */
sv 1:6799c07fe510 276 template <class T1, class T2>
sv 1:6799c07fe510 277 struct Fcnl_swap : public BinaryFunctional {
sv 1:6799c07fe510 278 static inline
sv 1:6799c07fe510 279 void apply_on(T1& _tvmet_restrict lhs, T2& _tvmet_restrict rhs) {
sv 1:6799c07fe510 280 typedef typename PromoteTraits<T1, T2>::value_type temp_type;
sv 1:6799c07fe510 281
sv 1:6799c07fe510 282 temp_type temp(lhs);
sv 1:6799c07fe510 283 lhs = static_cast<T1>(rhs);
sv 1:6799c07fe510 284 rhs = static_cast<T2>(temp);
sv 1:6799c07fe510 285 }
sv 1:6799c07fe510 286
sv 1:6799c07fe510 287 static
sv 1:6799c07fe510 288 void print_xpr(std::ostream& os, std::size_t l=0) {
sv 1:6799c07fe510 289 os << IndentLevel(l) << "Fcnl_swap<T1="
sv 1:6799c07fe510 290 << typeid(T1).name() << ", T2" << typeid(T2).name() << ">,"
sv 1:6799c07fe510 291 << std::endl;
sv 1:6799c07fe510 292 }
sv 1:6799c07fe510 293 };
sv 1:6799c07fe510 294
sv 1:6799c07fe510 295
sv 1:6799c07fe510 296 } // namespace tvmet
sv 1:6799c07fe510 297
sv 1:6799c07fe510 298 #endif // TVMET_BINARY_FUNCTIONAL_H
sv 1:6799c07fe510 299
sv 1:6799c07fe510 300 // Local Variables:
sv 1:6799c07fe510 301 // mode:C++
sv 1:6799c07fe510 302 // tab-width:8
sv 1:6799c07fe510 303 // End: