This is some awesome robot code

Dependencies:   mbed-rtos mbed QEI

Fork of ICRSEurobot13 by Thomas Branch

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MatrixDiag.h Source File

MatrixDiag.h

00001 /*
00002  * Tiny Vector Matrix Library
00003  * Dense Vector Matrix Libary of Tiny size using Expression Templates
00004  *
00005  * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * $Id: MatrixDiag.h,v 1.17 2007-06-23 15:59:00 opetzold Exp $
00022  */
00023 
00024 #ifndef TVMET_XPR_MATRIX_DIAG_H
00025 #define TVMET_XPR_MATRIX_DIAG_H
00026 
00027 namespace tvmet {
00028 
00029 
00030 /**
00031  * \class XprMatrixDiag MatrixDiag.h "tvmet/xpr/MatrixDiag.h"
00032  * \brief Expression on matrix used for access on the diagonal vector.
00033  */
00034 template<class E, std::size_t Sz>
00035 class XprMatrixDiag
00036   : public TvmetBase< XprMatrixDiag<E, Sz> >
00037 {
00038   XprMatrixDiag();
00039   XprMatrixDiag& operator=(const XprMatrixDiag<E, Sz>&);
00040 
00041 public:
00042   typedef typename E::value_type            value_type;
00043 
00044 public:
00045   /** Complexity counter. */
00046   enum {
00047     ops_expr  = E::ops,
00048     ops       = ops_expr/Sz
00049   };
00050 
00051 public:
00052   /** Constructor. */
00053   explicit XprMatrixDiag(const E& e)
00054     : m_expr(e)
00055   { }
00056 
00057   /** Copy Constructor. Not explicit! */
00058 #if defined(TVMET_OPTIMIZE_XPR_MANUAL_CCTOR)
00059   XprMatrixDiag(const XprMatrixDiag& e)
00060     : m_expr(e.m_expr)
00061   { }
00062 #endif
00063 
00064   /** index operator for arrays/matrizes */
00065   value_type operator()(std::size_t i) const {
00066     TVMET_RT_CONDITION(i < Sz, "XprMatrixDiag Bounce Violation")
00067     return m_expr(i, i);
00068   }
00069 
00070 public: // debugging Xpr parse tree
00071   void print_xpr(std::ostream& os, std::size_t l=0) const {
00072     os << IndentLevel(l++)
00073        << "XprMatrixDiag[O=" << ops << ", (O=" << ops_expr << ")]<"
00074        << std::endl;
00075     m_expr.print_xpr(os, l);
00076     os << IndentLevel(l)
00077        << "Sz=" << Sz << std::endl
00078        << IndentLevel(--l) << ">"
00079        << ((l != 0) ? "," : "") << std::endl;
00080   }
00081 
00082 private:
00083   const E                        m_expr;
00084 };
00085 
00086 
00087 } // namespace tvmet
00088 
00089 #endif // TVMET_XPR_MATRIX_DIAG_H
00090 
00091 // Local Variables:
00092 // mode:C++
00093 // tab-width:8
00094 // End: