Cooper Liu
/
Eurobot2013_Co-Processor
working version with calibration done
Fork of Eurobot2013 by
tvmet/xpr/Eval.h@11:5ba926692210, 2013-04-09 (annotated)
- Committer:
- xiaxia686
- Date:
- Tue Apr 09 15:32:47 2013 +0000
- Revision:
- 11:5ba926692210
- Parent:
- 1:6799c07fe510
woking version (calibrated)
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: Eval.h,v 1.13 2007-06-23 15:58:59 opetzold Exp $ |
sv | 1:6799c07fe510 | 22 | */ |
sv | 1:6799c07fe510 | 23 | |
sv | 1:6799c07fe510 | 24 | #ifndef TVMET_XPR_EVAL_H |
sv | 1:6799c07fe510 | 25 | #define TVMET_XPR_EVAL_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 XprEval Eval.h "tvmet/xpr/Eval.h" |
sv | 1:6799c07fe510 | 32 | * \brief evaluate the expression |
sv | 1:6799c07fe510 | 33 | * |
sv | 1:6799c07fe510 | 34 | * Since we can't overwrite the ? operator we have to write a wrapper |
sv | 1:6799c07fe510 | 35 | * for expression like return v1>v2 ? true : false |
sv | 1:6799c07fe510 | 36 | */ |
sv | 1:6799c07fe510 | 37 | template<class E1, class E2, class E3> |
sv | 1:6799c07fe510 | 38 | class XprEval |
sv | 1:6799c07fe510 | 39 | : public TvmetBase< XprEval<E1, E2, E3> > |
sv | 1:6799c07fe510 | 40 | { |
sv | 1:6799c07fe510 | 41 | public: |
sv | 1:6799c07fe510 | 42 | typedef E1 expr1_type; |
sv | 1:6799c07fe510 | 43 | typedef E2 expr2_type; |
sv | 1:6799c07fe510 | 44 | typedef E3 expr3_type; |
sv | 1:6799c07fe510 | 45 | |
sv | 1:6799c07fe510 | 46 | typedef typename expr2_type::value_type value2_type; |
sv | 1:6799c07fe510 | 47 | typedef typename expr3_type::value_type value3_type; |
sv | 1:6799c07fe510 | 48 | |
sv | 1:6799c07fe510 | 49 | typedef typename |
sv | 1:6799c07fe510 | 50 | PromoteTraits<value2_type, value3_type>::value_type value_type; |
sv | 1:6799c07fe510 | 51 | |
sv | 1:6799c07fe510 | 52 | public: |
sv | 1:6799c07fe510 | 53 | /** Complexity Counter */ |
sv | 1:6799c07fe510 | 54 | enum { |
sv | 1:6799c07fe510 | 55 | ops_expr1 = E1::ops, |
sv | 1:6799c07fe510 | 56 | ops_expr2 = E2::ops, |
sv | 1:6799c07fe510 | 57 | ops_expr3 = E3::ops, |
sv | 1:6799c07fe510 | 58 | ops = ops_expr1 // only (e1 op e2) are evaluated |
sv | 1:6799c07fe510 | 59 | }; |
sv | 1:6799c07fe510 | 60 | |
sv | 1:6799c07fe510 | 61 | private: |
sv | 1:6799c07fe510 | 62 | XprEval(); |
sv | 1:6799c07fe510 | 63 | XprEval& operator=(const XprEval<expr1_type, expr2_type, expr3_type>&); |
sv | 1:6799c07fe510 | 64 | |
sv | 1:6799c07fe510 | 65 | public: |
sv | 1:6799c07fe510 | 66 | /** Constructor */ |
sv | 1:6799c07fe510 | 67 | explicit XprEval(const expr1_type& e1, const expr2_type& e2, const expr3_type& e3) |
sv | 1:6799c07fe510 | 68 | : m_expr1(e1), m_expr2(e2), m_expr3(e3) |
sv | 1:6799c07fe510 | 69 | { } |
sv | 1:6799c07fe510 | 70 | |
sv | 1:6799c07fe510 | 71 | /** Copy Constructor. Not explicit! */ |
sv | 1:6799c07fe510 | 72 | #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR) |
sv | 1:6799c07fe510 | 73 | XprEval(const XprEval& rhs) |
sv | 1:6799c07fe510 | 74 | : m_expr1(rhs.m_expr1), m_expr2(rhs.m_expr2), m_expr3(rhs.m_expr3) |
sv | 1:6799c07fe510 | 75 | { } |
sv | 1:6799c07fe510 | 76 | #endif |
sv | 1:6799c07fe510 | 77 | |
sv | 1:6799c07fe510 | 78 | public: //access |
sv | 1:6799c07fe510 | 79 | /** index operator for vectors. */ |
sv | 1:6799c07fe510 | 80 | value_type operator()(std::size_t i) const { |
sv | 1:6799c07fe510 | 81 | return m_expr1(i) ? m_expr2(i) : m_expr3(i); |
sv | 1:6799c07fe510 | 82 | } |
sv | 1:6799c07fe510 | 83 | |
sv | 1:6799c07fe510 | 84 | /** index operator for matrizes. */ |
sv | 1:6799c07fe510 | 85 | value_type operator()(std::size_t i, std::size_t j) const { |
sv | 1:6799c07fe510 | 86 | return m_expr1(i, j) ? m_expr2(i, j) : m_expr3(i, j); |
sv | 1:6799c07fe510 | 87 | } |
sv | 1:6799c07fe510 | 88 | |
sv | 1:6799c07fe510 | 89 | public: // debugging Xpr parse tree |
sv | 1:6799c07fe510 | 90 | void print_xpr(std::ostream& os, std::size_t l=0) const { |
sv | 1:6799c07fe510 | 91 | os << IndentLevel(l++) |
sv | 1:6799c07fe510 | 92 | << "XprEval[" << ops << ", (" |
sv | 1:6799c07fe510 | 93 | << ops_expr1 << ", " << ops_expr2 << ", " << ops_expr3 << ")]<" |
sv | 1:6799c07fe510 | 94 | << std::endl; |
sv | 1:6799c07fe510 | 95 | m_expr1.print_xpr(os, l); |
sv | 1:6799c07fe510 | 96 | m_expr2.print_xpr(os, l); |
sv | 1:6799c07fe510 | 97 | m_expr3.print_xpr(os, l); |
sv | 1:6799c07fe510 | 98 | os << IndentLevel(--l) |
sv | 1:6799c07fe510 | 99 | << ">," << std::endl; |
sv | 1:6799c07fe510 | 100 | } |
sv | 1:6799c07fe510 | 101 | |
sv | 1:6799c07fe510 | 102 | private: |
sv | 1:6799c07fe510 | 103 | const expr1_type m_expr1; |
sv | 1:6799c07fe510 | 104 | const expr2_type m_expr2; |
sv | 1:6799c07fe510 | 105 | const expr3_type m_expr3; |
sv | 1:6799c07fe510 | 106 | }; |
sv | 1:6799c07fe510 | 107 | |
sv | 1:6799c07fe510 | 108 | |
sv | 1:6799c07fe510 | 109 | } // namespace tvmet |
sv | 1:6799c07fe510 | 110 | |
sv | 1:6799c07fe510 | 111 | #endif // TVMET_XPR_EVAL_H |
sv | 1:6799c07fe510 | 112 | |
sv | 1:6799c07fe510 | 113 | // Local Variables: |
sv | 1:6799c07fe510 | 114 | // mode:C++ |
sv | 1:6799c07fe510 | 115 | // tab-width:8 |
sv | 1:6799c07fe510 | 116 | // End: |