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
Vector.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: Vector.h,v 1.24 2007-06-23 15:58:59 opetzold Exp $ 00022 */ 00023 00024 #ifndef TVMET_META_VECTOR_H 00025 #define TVMET_META_VECTOR_H 00026 00027 #include <tvmet/NumericTraits.h> 00028 #include <tvmet/xpr/Null.h> 00029 00030 namespace tvmet { 00031 00032 /* forwards */ 00033 template<class T, std::size_t Sz> class Vector; 00034 00035 00036 namespace meta { 00037 00038 00039 /** 00040 * \class Vector Vector.h "tvmet/meta/Vector.h" 00041 * \brief Meta %Vector class using expression templates 00042 */ 00043 template<std::size_t Sz, std::size_t K=0> 00044 class Vector 00045 { 00046 Vector(); 00047 Vector(const Vector&); 00048 Vector& operator=(const Vector&); 00049 00050 private: 00051 enum { 00052 doIt = (K < (Sz-1)) ? 1 : 0 /**< recursive counter */ 00053 }; 00054 00055 public: 00056 /** assign an expression expr using the functional assign_fn. */ 00057 template <class Dest, class Src, class Assign> 00058 static inline 00059 void assign(Dest& lhs, const Src& rhs, const Assign& assign_fn) { 00060 assign_fn.apply_on(lhs(K), rhs(K)); 00061 meta::Vector<Sz * doIt, (K+1) * doIt>::assign(lhs, rhs, assign_fn); 00062 } 00063 00064 /** build the sum of the vector. */ 00065 template<class E> 00066 static inline 00067 typename E::value_type 00068 sum(const E& e) { 00069 return e(K) + meta::Vector<Sz * doIt, (K+1) * doIt>::sum(e); 00070 } 00071 00072 /** build the product of the vector. */ 00073 template<class E> 00074 static inline 00075 typename NumericTraits< 00076 typename E::value_type 00077 >::sum_type 00078 product(const E& e) { 00079 return e(K) * meta::Vector<Sz * doIt, (K+1) * doIt>::product(e); 00080 } 00081 00082 /** build the dot product of the vector. */ 00083 template<class Dest, class Src> 00084 static inline 00085 typename PromoteTraits< 00086 typename Dest::value_type, 00087 typename Src::value_type 00088 >::value_type 00089 dot(const Dest& lhs, const Src& rhs) { 00090 return lhs(K) * rhs(K) 00091 + meta::Vector<Sz * doIt, (K+1) * doIt>::dot(lhs, rhs); 00092 } 00093 00094 /** check for all elements */ 00095 template<class E> 00096 static inline 00097 bool 00098 all_elements(const E& e) { 00099 if(!e(K)) return false; 00100 return meta::Vector<Sz * doIt, (K+1) * doIt>::all_elements(e); 00101 } 00102 00103 /** check for any elements */ 00104 template<class E> 00105 static inline 00106 bool 00107 any_elements(const E& e) { 00108 if(e(K)) return true; 00109 return meta::Vector<Sz * doIt, (K+1) * doIt>::any_elements(e); 00110 } 00111 }; 00112 00113 00114 /** 00115 * \class Vector<0,0> Vector.h "tvmet/meta/Vector.h" 00116 * \brief Meta %Vector Specialized for recursion 00117 */ 00118 template<> 00119 class Vector<0,0> 00120 { 00121 Vector(); 00122 Vector(const Vector&); 00123 Vector& operator=(const Vector&); 00124 00125 public: 00126 template <class Dest, class Src, class Assign> 00127 static inline void assign(Dest&, const Src&, const Assign&) { } 00128 00129 template<class E> 00130 static inline XprNull sum(const E&) { return XprNull(); } 00131 00132 template<class E> 00133 static inline XprNull product(const E&) { return XprNull(); } 00134 00135 template<class Dest, class Src> 00136 static inline XprNull dot(const Dest&, const Src&) { return XprNull(); } 00137 00138 template<class E> 00139 static inline bool all_elements(const E&) { return true; } 00140 00141 template<class E> 00142 static inline bool any_elements(const E&) { return false; } 00143 }; 00144 00145 00146 } // namespace meta 00147 00148 } // namespace tvmet 00149 00150 #endif /* TVMET_META_VECTOR_H */ 00151 00152 // Local Variables: 00153 // mode:C++ 00154 // tab-width:8 00155 // End:
Generated on Tue Jul 12 2022 21:02:14 by
1.7.2
