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/TvmetBase.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: TvmetBase.h,v 1.17 2007-06-23 15:58:58 opetzold Exp $ |
narshu | 1:cc2a9eb0bd55 | 22 | */ |
narshu | 1:cc2a9eb0bd55 | 23 | |
narshu | 1:cc2a9eb0bd55 | 24 | #ifndef TVMET_BASE_H |
narshu | 1:cc2a9eb0bd55 | 25 | #define TVMET_BASE_H |
narshu | 1:cc2a9eb0bd55 | 26 | |
narshu | 1:cc2a9eb0bd55 | 27 | #include <iostream>//<iosfwd> // io streams forward declaration |
narshu | 1:cc2a9eb0bd55 | 28 | #include <typeinfo> // rtti: used by Xpr.h level printing |
narshu | 1:cc2a9eb0bd55 | 29 | #include <cmath> // unary and binary math |
narshu | 1:cc2a9eb0bd55 | 30 | #include <cstdlib> // labs |
narshu | 1:cc2a9eb0bd55 | 31 | |
narshu | 1:cc2a9eb0bd55 | 32 | #if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER == 1310) |
narshu | 1:cc2a9eb0bd55 | 33 | #include <string> // operator<<(ostream) here defined |
narshu | 1:cc2a9eb0bd55 | 34 | #endif |
narshu | 1:cc2a9eb0bd55 | 35 | |
narshu | 1:cc2a9eb0bd55 | 36 | #if defined(__APPLE_CC__) |
narshu | 1:cc2a9eb0bd55 | 37 | // Mac OS X builds seems to miss these functions inside cmath |
narshu | 1:cc2a9eb0bd55 | 38 | extern "C" int isnan(double); |
narshu | 1:cc2a9eb0bd55 | 39 | extern "C" int isinf(double); |
narshu | 1:cc2a9eb0bd55 | 40 | #endif |
narshu | 1:cc2a9eb0bd55 | 41 | |
narshu | 1:cc2a9eb0bd55 | 42 | namespace tvmet { |
narshu | 1:cc2a9eb0bd55 | 43 | |
narshu | 1:cc2a9eb0bd55 | 44 | |
narshu | 1:cc2a9eb0bd55 | 45 | /** |
narshu | 1:cc2a9eb0bd55 | 46 | * \class TvmetBase TvmetBase.h "tvmet/TvmetBase.h" |
narshu | 1:cc2a9eb0bd55 | 47 | * \brief Base class |
narshu | 1:cc2a9eb0bd55 | 48 | * Used for static polymorph call of print_xpr |
narshu | 1:cc2a9eb0bd55 | 49 | */ |
narshu | 1:cc2a9eb0bd55 | 50 | template<class E> class TvmetBase { }; |
narshu | 1:cc2a9eb0bd55 | 51 | |
narshu | 1:cc2a9eb0bd55 | 52 | |
narshu | 1:cc2a9eb0bd55 | 53 | /** |
narshu | 1:cc2a9eb0bd55 | 54 | * \class IndentLevel TvmetBase.h "tvmet/TvmetBase.h" |
narshu | 1:cc2a9eb0bd55 | 55 | * \brief Prints the level indent. |
narshu | 1:cc2a9eb0bd55 | 56 | */ |
narshu | 1:cc2a9eb0bd55 | 57 | class IndentLevel : public TvmetBase< IndentLevel > |
narshu | 1:cc2a9eb0bd55 | 58 | { |
narshu | 1:cc2a9eb0bd55 | 59 | public: |
narshu | 1:cc2a9eb0bd55 | 60 | IndentLevel(std::size_t level) : m_level(level) { } |
narshu | 1:cc2a9eb0bd55 | 61 | |
narshu | 1:cc2a9eb0bd55 | 62 | std::ostream& print_xpr(std::ostream& os) const { |
narshu | 1:cc2a9eb0bd55 | 63 | for(std::size_t i = 0; i != m_level; ++i) os << " "; |
narshu | 1:cc2a9eb0bd55 | 64 | return os; |
narshu | 1:cc2a9eb0bd55 | 65 | } |
narshu | 1:cc2a9eb0bd55 | 66 | |
narshu | 1:cc2a9eb0bd55 | 67 | private: |
narshu | 1:cc2a9eb0bd55 | 68 | std::size_t m_level; |
narshu | 1:cc2a9eb0bd55 | 69 | }; |
narshu | 1:cc2a9eb0bd55 | 70 | |
narshu | 1:cc2a9eb0bd55 | 71 | |
narshu | 1:cc2a9eb0bd55 | 72 | /** |
narshu | 1:cc2a9eb0bd55 | 73 | * \fn operator<<(std::ostream& os, const TvmetBase<E>& e) |
narshu | 1:cc2a9eb0bd55 | 74 | * \brief overloaded ostream operator using static polymorphic. |
narshu | 1:cc2a9eb0bd55 | 75 | * \ingroup _binary_operator |
narshu | 1:cc2a9eb0bd55 | 76 | */ |
narshu | 1:cc2a9eb0bd55 | 77 | template<class E> |
narshu | 1:cc2a9eb0bd55 | 78 | inline |
narshu | 1:cc2a9eb0bd55 | 79 | std::ostream& operator<<(std::ostream& os, const TvmetBase<E>& e) { |
narshu | 1:cc2a9eb0bd55 | 80 | static_cast<const E&>(e).print_xpr(os); |
narshu | 1:cc2a9eb0bd55 | 81 | return os; |
narshu | 1:cc2a9eb0bd55 | 82 | } |
narshu | 1:cc2a9eb0bd55 | 83 | |
narshu | 1:cc2a9eb0bd55 | 84 | |
narshu | 1:cc2a9eb0bd55 | 85 | /** |
narshu | 1:cc2a9eb0bd55 | 86 | * \class dispatch TvmetBase.h "tvmet/TvmetBase.h" |
narshu | 1:cc2a9eb0bd55 | 87 | * \brief Class helper to distuingish between e.g. meta |
narshu | 1:cc2a9eb0bd55 | 88 | * and loop strategy used. |
narshu | 1:cc2a9eb0bd55 | 89 | */ |
narshu | 1:cc2a9eb0bd55 | 90 | template<bool> struct dispatch; |
narshu | 1:cc2a9eb0bd55 | 91 | |
narshu | 1:cc2a9eb0bd55 | 92 | /** |
narshu | 1:cc2a9eb0bd55 | 93 | * \class dispatch<true> TvmetBase.h "tvmet/TvmetBase.h" |
narshu | 1:cc2a9eb0bd55 | 94 | * \brief specialized. |
narshu | 1:cc2a9eb0bd55 | 95 | */ |
narshu | 1:cc2a9eb0bd55 | 96 | template<> struct dispatch<true> { }; |
narshu | 1:cc2a9eb0bd55 | 97 | |
narshu | 1:cc2a9eb0bd55 | 98 | /** |
narshu | 1:cc2a9eb0bd55 | 99 | * \class dispatch<false> TvmetBase.h "tvmet/TvmetBase.h" |
narshu | 1:cc2a9eb0bd55 | 100 | * \brief specialized. |
narshu | 1:cc2a9eb0bd55 | 101 | */ |
narshu | 1:cc2a9eb0bd55 | 102 | template<> struct dispatch<false> { }; |
narshu | 1:cc2a9eb0bd55 | 103 | |
narshu | 1:cc2a9eb0bd55 | 104 | |
narshu | 1:cc2a9eb0bd55 | 105 | } // namespace tvmet |
narshu | 1:cc2a9eb0bd55 | 106 | |
narshu | 1:cc2a9eb0bd55 | 107 | #endif // TVMET_BASE_H |
narshu | 1:cc2a9eb0bd55 | 108 | |
narshu | 1:cc2a9eb0bd55 | 109 | // Local Variables: |
narshu | 1:cc2a9eb0bd55 | 110 | // mode:C++ |
narshu | 1:cc2a9eb0bd55 | 111 | // tab-width:8 |
narshu | 1:cc2a9eb0bd55 | 112 | // End: |