Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:28 2012 +0000
Revision:
25:143b19c1fb05
Commit before publishing;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 25:143b19c1fb05 1 /*
narshu 25:143b19c1fb05 2 * Tiny Vector Matrix Library
narshu 25:143b19c1fb05 3 * Dense Vector Matrix Libary of Tiny size using Expression Templates
narshu 25:143b19c1fb05 4 *
narshu 25:143b19c1fb05 5 * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
narshu 25:143b19c1fb05 6 *
narshu 25:143b19c1fb05 7 * This library is free software; you can redistribute it and/or
narshu 25:143b19c1fb05 8 * modify it under the terms of the GNU Lesser General Public
narshu 25:143b19c1fb05 9 * License as published by the Free Software Foundation; either
narshu 25:143b19c1fb05 10 * version 2.1 of the License, or (at your option) any later version.
narshu 25:143b19c1fb05 11 *
narshu 25:143b19c1fb05 12 * This library is distributed in the hope that it will be useful,
narshu 25:143b19c1fb05 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
narshu 25:143b19c1fb05 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
narshu 25:143b19c1fb05 15 * Lesser General Public License for more details.
narshu 25:143b19c1fb05 16 *
narshu 25:143b19c1fb05 17 * You should have received a copy of the GNU Lesser General Public
narshu 25:143b19c1fb05 18 * License along with this library; if not, write to the Free Software
narshu 25:143b19c1fb05 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
narshu 25:143b19c1fb05 20 *
narshu 25:143b19c1fb05 21 * $Id: Eval.h,v 1.13 2007-06-23 15:58:59 opetzold Exp $
narshu 25:143b19c1fb05 22 */
narshu 25:143b19c1fb05 23
narshu 25:143b19c1fb05 24 #ifndef TVMET_XPR_EVAL_H
narshu 25:143b19c1fb05 25 #define TVMET_XPR_EVAL_H
narshu 25:143b19c1fb05 26
narshu 25:143b19c1fb05 27 namespace tvmet {
narshu 25:143b19c1fb05 28
narshu 25:143b19c1fb05 29
narshu 25:143b19c1fb05 30 /**
narshu 25:143b19c1fb05 31 * \class XprEval Eval.h "tvmet/xpr/Eval.h"
narshu 25:143b19c1fb05 32 * \brief evaluate the expression
narshu 25:143b19c1fb05 33 *
narshu 25:143b19c1fb05 34 * Since we can't overwrite the ? operator we have to write a wrapper
narshu 25:143b19c1fb05 35 * for expression like return v1>v2 ? true : false
narshu 25:143b19c1fb05 36 */
narshu 25:143b19c1fb05 37 template<class E1, class E2, class E3>
narshu 25:143b19c1fb05 38 class XprEval
narshu 25:143b19c1fb05 39 : public TvmetBase< XprEval<E1, E2, E3> >
narshu 25:143b19c1fb05 40 {
narshu 25:143b19c1fb05 41 public:
narshu 25:143b19c1fb05 42 typedef E1 expr1_type;
narshu 25:143b19c1fb05 43 typedef E2 expr2_type;
narshu 25:143b19c1fb05 44 typedef E3 expr3_type;
narshu 25:143b19c1fb05 45
narshu 25:143b19c1fb05 46 typedef typename expr2_type::value_type value2_type;
narshu 25:143b19c1fb05 47 typedef typename expr3_type::value_type value3_type;
narshu 25:143b19c1fb05 48
narshu 25:143b19c1fb05 49 typedef typename
narshu 25:143b19c1fb05 50 PromoteTraits<value2_type, value3_type>::value_type value_type;
narshu 25:143b19c1fb05 51
narshu 25:143b19c1fb05 52 public:
narshu 25:143b19c1fb05 53 /** Complexity Counter */
narshu 25:143b19c1fb05 54 enum {
narshu 25:143b19c1fb05 55 ops_expr1 = E1::ops,
narshu 25:143b19c1fb05 56 ops_expr2 = E2::ops,
narshu 25:143b19c1fb05 57 ops_expr3 = E3::ops,
narshu 25:143b19c1fb05 58 ops = ops_expr1 // only (e1 op e2) are evaluated
narshu 25:143b19c1fb05 59 };
narshu 25:143b19c1fb05 60
narshu 25:143b19c1fb05 61 private:
narshu 25:143b19c1fb05 62 XprEval();
narshu 25:143b19c1fb05 63 XprEval& operator=(const XprEval<expr1_type, expr2_type, expr3_type>&);
narshu 25:143b19c1fb05 64
narshu 25:143b19c1fb05 65 public:
narshu 25:143b19c1fb05 66 /** Constructor */
narshu 25:143b19c1fb05 67 explicit XprEval(const expr1_type& e1, const expr2_type& e2, const expr3_type& e3)
narshu 25:143b19c1fb05 68 : m_expr1(e1), m_expr2(e2), m_expr3(e3)
narshu 25:143b19c1fb05 69 { }
narshu 25:143b19c1fb05 70
narshu 25:143b19c1fb05 71 /** Copy Constructor. Not explicit! */
narshu 25:143b19c1fb05 72 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
narshu 25:143b19c1fb05 73 XprEval(const XprEval& rhs)
narshu 25:143b19c1fb05 74 : m_expr1(rhs.m_expr1), m_expr2(rhs.m_expr2), m_expr3(rhs.m_expr3)
narshu 25:143b19c1fb05 75 { }
narshu 25:143b19c1fb05 76 #endif
narshu 25:143b19c1fb05 77
narshu 25:143b19c1fb05 78 public: //access
narshu 25:143b19c1fb05 79 /** index operator for vectors. */
narshu 25:143b19c1fb05 80 value_type operator()(std::size_t i) const {
narshu 25:143b19c1fb05 81 return m_expr1(i) ? m_expr2(i) : m_expr3(i);
narshu 25:143b19c1fb05 82 }
narshu 25:143b19c1fb05 83
narshu 25:143b19c1fb05 84 /** index operator for matrizes. */
narshu 25:143b19c1fb05 85 value_type operator()(std::size_t i, std::size_t j) const {
narshu 25:143b19c1fb05 86 return m_expr1(i, j) ? m_expr2(i, j) : m_expr3(i, j);
narshu 25:143b19c1fb05 87 }
narshu 25:143b19c1fb05 88
narshu 25:143b19c1fb05 89 public: // debugging Xpr parse tree
narshu 25:143b19c1fb05 90 void print_xpr(std::ostream& os, std::size_t l=0) const {
narshu 25:143b19c1fb05 91 os << IndentLevel(l++)
narshu 25:143b19c1fb05 92 << "XprEval[" << ops << ", ("
narshu 25:143b19c1fb05 93 << ops_expr1 << ", " << ops_expr2 << ", " << ops_expr3 << ")]<"
narshu 25:143b19c1fb05 94 << std::endl;
narshu 25:143b19c1fb05 95 m_expr1.print_xpr(os, l);
narshu 25:143b19c1fb05 96 m_expr2.print_xpr(os, l);
narshu 25:143b19c1fb05 97 m_expr3.print_xpr(os, l);
narshu 25:143b19c1fb05 98 os << IndentLevel(--l)
narshu 25:143b19c1fb05 99 << ">," << std::endl;
narshu 25:143b19c1fb05 100 }
narshu 25:143b19c1fb05 101
narshu 25:143b19c1fb05 102 private:
narshu 25:143b19c1fb05 103 const expr1_type m_expr1;
narshu 25:143b19c1fb05 104 const expr2_type m_expr2;
narshu 25:143b19c1fb05 105 const expr3_type m_expr3;
narshu 25:143b19c1fb05 106 };
narshu 25:143b19c1fb05 107
narshu 25:143b19c1fb05 108
narshu 25:143b19c1fb05 109 } // namespace tvmet
narshu 25:143b19c1fb05 110
narshu 25:143b19c1fb05 111 #endif // TVMET_XPR_EVAL_H
narshu 25:143b19c1fb05 112
narshu 25:143b19c1fb05 113 // Local Variables:
narshu 25:143b19c1fb05 114 // mode:C++
narshu 25:143b19c1fb05 115 // tab-width:8
narshu 25:143b19c1fb05 116 // End: