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