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