Eurobot2012_Primary

Dependencies:   mbed Eurobot_2012_Primary

Committer:
narshu
Date:
Wed Oct 17 22:22:47 2012 +0000
Revision:
26:0995f61cb7b8
Parent:
25:143b19c1fb05
Eurobot 2012 Primary;

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: AliasProxy.h,v 1.8 2007-06-23 15:58:58 opetzold Exp $
narshu 25:143b19c1fb05 22 */
narshu 25:143b19c1fb05 23
narshu 25:143b19c1fb05 24 #ifndef TVMET_ALIAS_PROXY_H
narshu 25:143b19c1fb05 25 #define TVMET_ALIAS_PROXY_H
narshu 25:143b19c1fb05 26
narshu 25:143b19c1fb05 27 namespace tvmet {
narshu 25:143b19c1fb05 28
narshu 25:143b19c1fb05 29
narshu 25:143b19c1fb05 30 /** forwards */
narshu 25:143b19c1fb05 31 template<class E> class AliasProxy;
narshu 25:143b19c1fb05 32
narshu 25:143b19c1fb05 33
narshu 25:143b19c1fb05 34 /**
narshu 25:143b19c1fb05 35 * \brief Simplify syntax for alias Matrices and Vectors,
narshu 25:143b19c1fb05 36 * where aliasing left hand values appear in the
narshu 25:143b19c1fb05 37 * expression.
narshu 25:143b19c1fb05 38 * \par Example:
narshu 25:143b19c1fb05 39 * \code
narshu 25:143b19c1fb05 40 * typedef tvmet::Matrix<double, 10, 10> matrix_type;
narshu 25:143b19c1fb05 41 * matrix_type m;
narshu 25:143b19c1fb05 42 * ...
narshu 25:143b19c1fb05 43 * alias(m) += trans(m);
narshu 25:143b19c1fb05 44 * \endcode
narshu 25:143b19c1fb05 45 * \sa AliasProxy
narshu 25:143b19c1fb05 46 * \sa Some Notes \ref alias
narshu 25:143b19c1fb05 47 */
narshu 25:143b19c1fb05 48 template<class E>
narshu 25:143b19c1fb05 49 AliasProxy<E> alias(E& expr) { return AliasProxy<E>(expr); }
narshu 25:143b19c1fb05 50
narshu 25:143b19c1fb05 51
narshu 25:143b19c1fb05 52 /**
narshu 25:143b19c1fb05 53 * \class AliasProxy AliasProxy.h "tvmet/AliasProxy.h"
narshu 25:143b19c1fb05 54 * \brief Assign proxy for alias Matrices and Vectors.
narshu 25:143b19c1fb05 55 *
narshu 25:143b19c1fb05 56 * A short lived object to provide simplified alias syntax.
narshu 25:143b19c1fb05 57 * Only the friend function alias is allowed to create
narshu 25:143b19c1fb05 58 * such a object. The proxy calls the appropriate member
narshu 25:143b19c1fb05 59 * alias_xyz() which have to use temporaries to avoid
narshu 25:143b19c1fb05 60 * overlapping memory regions.
narshu 25:143b19c1fb05 61 * \sa alias
narshu 25:143b19c1fb05 62 * \sa Some Notes \ref alias
narshu 25:143b19c1fb05 63 * \note Thanks to ublas-dev group, where the principle idea
narshu 25:143b19c1fb05 64 * comes from.
narshu 25:143b19c1fb05 65 */
narshu 25:143b19c1fb05 66 template<class E>
narshu 25:143b19c1fb05 67 class AliasProxy
narshu 25:143b19c1fb05 68 {
narshu 25:143b19c1fb05 69 AliasProxy(const AliasProxy&);
narshu 25:143b19c1fb05 70 AliasProxy& operator=(const AliasProxy&);
narshu 25:143b19c1fb05 71
narshu 25:143b19c1fb05 72 friend AliasProxy<E> alias<>(E& expr);
narshu 25:143b19c1fb05 73
narshu 25:143b19c1fb05 74 public:
narshu 25:143b19c1fb05 75 AliasProxy(E& expr) : m_expr(expr) { }
narshu 25:143b19c1fb05 76
narshu 25:143b19c1fb05 77
narshu 25:143b19c1fb05 78 template<class E2>
narshu 25:143b19c1fb05 79 E& operator=(const E2& expr) {
narshu 25:143b19c1fb05 80 return m_expr.alias_assign(expr);
narshu 25:143b19c1fb05 81 }
narshu 25:143b19c1fb05 82
narshu 25:143b19c1fb05 83 template<class E2>
narshu 25:143b19c1fb05 84 E& operator+=(const E2& expr) {
narshu 25:143b19c1fb05 85 return m_expr.alias_add_eq(expr);
narshu 25:143b19c1fb05 86 }
narshu 25:143b19c1fb05 87
narshu 25:143b19c1fb05 88 template<class E2>
narshu 25:143b19c1fb05 89 E& operator-=(const E2& expr) {
narshu 25:143b19c1fb05 90 return m_expr.alias_sub_eq(expr);
narshu 25:143b19c1fb05 91 }
narshu 25:143b19c1fb05 92
narshu 25:143b19c1fb05 93 template<class E2>
narshu 25:143b19c1fb05 94 E& operator*=(const E2& expr) {
narshu 25:143b19c1fb05 95 return m_expr.alias_mul_eq(expr);
narshu 25:143b19c1fb05 96 }
narshu 25:143b19c1fb05 97
narshu 25:143b19c1fb05 98 template<class E2>
narshu 25:143b19c1fb05 99 E& operator/=(const E2& expr) {
narshu 25:143b19c1fb05 100 return m_expr.alias_div_eq(expr);
narshu 25:143b19c1fb05 101 }
narshu 25:143b19c1fb05 102
narshu 25:143b19c1fb05 103 private:
narshu 25:143b19c1fb05 104 E& m_expr;
narshu 25:143b19c1fb05 105 };
narshu 25:143b19c1fb05 106
narshu 25:143b19c1fb05 107
narshu 25:143b19c1fb05 108 #if 0
narshu 25:143b19c1fb05 109 namespace element_wise {
narshu 25:143b19c1fb05 110 // \todo to write
narshu 25:143b19c1fb05 111 template<class E, class E2>
narshu 25:143b19c1fb05 112 E& operator/=(AliasProxy<E>& proxy, const E2& rhs) {
narshu 25:143b19c1fb05 113 return proxy.div_upd(rhs);
narshu 25:143b19c1fb05 114 }
narshu 25:143b19c1fb05 115
narshu 25:143b19c1fb05 116 }
narshu 25:143b19c1fb05 117 #endif
narshu 25:143b19c1fb05 118
narshu 25:143b19c1fb05 119
narshu 25:143b19c1fb05 120 } // namespace tvmet
narshu 25:143b19c1fb05 121
narshu 25:143b19c1fb05 122
narshu 25:143b19c1fb05 123 #endif /* TVMET_ALIAS_PROXY_H */
narshu 25:143b19c1fb05 124
narshu 25:143b19c1fb05 125 // Local Variables:
narshu 25:143b19c1fb05 126 // mode:C++
narshu 25:143b19c1fb05 127 // tab-width:8
narshu 25:143b19c1fb05 128 // End: