Oskar Weigl
/
Eurobot2013
We are going to win! wohoo
tvmet/Vector.h@1:6799c07fe510, 2012-11-07 (annotated)
- Committer:
- sv
- Date:
- Wed Nov 07 14:37:35 2012 +0000
- Revision:
- 1:6799c07fe510
Preliminary copy of 2012 code
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: Vector.h,v 1.48 2007-06-23 15:58:58 opetzold Exp $ |
sv | 1:6799c07fe510 | 22 | */ |
sv | 1:6799c07fe510 | 23 | |
sv | 1:6799c07fe510 | 24 | #ifndef TVMET_VECTOR_H |
sv | 1:6799c07fe510 | 25 | #define TVMET_VECTOR_H |
sv | 1:6799c07fe510 | 26 | |
sv | 1:6799c07fe510 | 27 | #include <iterator> // reverse_iterator |
sv | 1:6799c07fe510 | 28 | |
sv | 1:6799c07fe510 | 29 | #include <tvmet/tvmet.h> |
sv | 1:6799c07fe510 | 30 | #include <tvmet/TypePromotion.h> |
sv | 1:6799c07fe510 | 31 | #include <tvmet/CommaInitializer.h> |
sv | 1:6799c07fe510 | 32 | #include <tvmet/RunTimeError.h> |
sv | 1:6799c07fe510 | 33 | |
sv | 1:6799c07fe510 | 34 | #include <tvmet/xpr/Vector.h> |
sv | 1:6799c07fe510 | 35 | |
sv | 1:6799c07fe510 | 36 | namespace tvmet { |
sv | 1:6799c07fe510 | 37 | |
sv | 1:6799c07fe510 | 38 | |
sv | 1:6799c07fe510 | 39 | /* forwards */ |
sv | 1:6799c07fe510 | 40 | template<class T, std::size_t Sz> class Vector; |
sv | 1:6799c07fe510 | 41 | |
sv | 1:6799c07fe510 | 42 | |
sv | 1:6799c07fe510 | 43 | /** |
sv | 1:6799c07fe510 | 44 | * \class VectorConstReference Vector.h "tvmet/Vector.h" |
sv | 1:6799c07fe510 | 45 | * \brief Const value iterator for ET |
sv | 1:6799c07fe510 | 46 | */ |
sv | 1:6799c07fe510 | 47 | template<class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 48 | class VectorConstReference |
sv | 1:6799c07fe510 | 49 | : public TvmetBase< VectorConstReference<T, Sz> > |
sv | 1:6799c07fe510 | 50 | { |
sv | 1:6799c07fe510 | 51 | public: // types |
sv | 1:6799c07fe510 | 52 | typedef T value_type; |
sv | 1:6799c07fe510 | 53 | typedef T* pointer; |
sv | 1:6799c07fe510 | 54 | typedef const T* const_pointer; |
sv | 1:6799c07fe510 | 55 | |
sv | 1:6799c07fe510 | 56 | public: |
sv | 1:6799c07fe510 | 57 | /** Dimensions. */ |
sv | 1:6799c07fe510 | 58 | enum { |
sv | 1:6799c07fe510 | 59 | Size = Sz /**< The size of the vector. */ |
sv | 1:6799c07fe510 | 60 | }; |
sv | 1:6799c07fe510 | 61 | |
sv | 1:6799c07fe510 | 62 | public: |
sv | 1:6799c07fe510 | 63 | /** Complexity counter. */ |
sv | 1:6799c07fe510 | 64 | enum { |
sv | 1:6799c07fe510 | 65 | ops = Size |
sv | 1:6799c07fe510 | 66 | }; |
sv | 1:6799c07fe510 | 67 | |
sv | 1:6799c07fe510 | 68 | private: |
sv | 1:6799c07fe510 | 69 | VectorConstReference(); |
sv | 1:6799c07fe510 | 70 | VectorConstReference& operator=(const VectorConstReference&); |
sv | 1:6799c07fe510 | 71 | |
sv | 1:6799c07fe510 | 72 | public: |
sv | 1:6799c07fe510 | 73 | /** Constructor. */ |
sv | 1:6799c07fe510 | 74 | explicit VectorConstReference(const Vector<T, Size>& rhs) |
sv | 1:6799c07fe510 | 75 | : m_data(rhs.data()) |
sv | 1:6799c07fe510 | 76 | { } |
sv | 1:6799c07fe510 | 77 | |
sv | 1:6799c07fe510 | 78 | /** Constructor by a given memory pointer. */ |
sv | 1:6799c07fe510 | 79 | explicit VectorConstReference(const_pointer data) |
sv | 1:6799c07fe510 | 80 | : m_data(data) |
sv | 1:6799c07fe510 | 81 | { } |
sv | 1:6799c07fe510 | 82 | |
sv | 1:6799c07fe510 | 83 | public: // access operators |
sv | 1:6799c07fe510 | 84 | /** access by index. */ |
sv | 1:6799c07fe510 | 85 | value_type operator()(std::size_t i) const { |
sv | 1:6799c07fe510 | 86 | TVMET_RT_CONDITION(i < Size, "VectorConstReference Bounce Violation") |
sv | 1:6799c07fe510 | 87 | return m_data[i]; |
sv | 1:6799c07fe510 | 88 | } |
sv | 1:6799c07fe510 | 89 | |
sv | 1:6799c07fe510 | 90 | public: // debugging Xpr parse tree |
sv | 1:6799c07fe510 | 91 | void print_xpr(std::ostream& os, std::size_t l=0) const { |
sv | 1:6799c07fe510 | 92 | os << IndentLevel(l) |
sv | 1:6799c07fe510 | 93 | << "VectorConstReference[O=" << ops << "]<" |
sv | 1:6799c07fe510 | 94 | << "T=" << typeid(T).name() << ">," |
sv | 1:6799c07fe510 | 95 | << std::endl; |
sv | 1:6799c07fe510 | 96 | } |
sv | 1:6799c07fe510 | 97 | |
sv | 1:6799c07fe510 | 98 | private: |
sv | 1:6799c07fe510 | 99 | const_pointer _tvmet_restrict m_data; |
sv | 1:6799c07fe510 | 100 | }; |
sv | 1:6799c07fe510 | 101 | |
sv | 1:6799c07fe510 | 102 | |
sv | 1:6799c07fe510 | 103 | /** |
sv | 1:6799c07fe510 | 104 | * \class Vector Vector.h "tvmet/Vector.h" |
sv | 1:6799c07fe510 | 105 | * \brief Compile time fixed length vector with evaluation on compile time. |
sv | 1:6799c07fe510 | 106 | */ |
sv | 1:6799c07fe510 | 107 | template<class T, std::size_t Sz> |
sv | 1:6799c07fe510 | 108 | class Vector |
sv | 1:6799c07fe510 | 109 | { |
sv | 1:6799c07fe510 | 110 | public: |
sv | 1:6799c07fe510 | 111 | /** Data type of the tvmet::Vector. */ |
sv | 1:6799c07fe510 | 112 | typedef T value_type; |
sv | 1:6799c07fe510 | 113 | |
sv | 1:6799c07fe510 | 114 | /** Reference type of the tvmet::Vector data elements. */ |
sv | 1:6799c07fe510 | 115 | typedef T& reference; |
sv | 1:6799c07fe510 | 116 | |
sv | 1:6799c07fe510 | 117 | /** const reference type of the tvmet::Vector data elements. */ |
sv | 1:6799c07fe510 | 118 | typedef const T& const_reference; |
sv | 1:6799c07fe510 | 119 | |
sv | 1:6799c07fe510 | 120 | /** STL iterator interface. */ |
sv | 1:6799c07fe510 | 121 | typedef T* iterator; |
sv | 1:6799c07fe510 | 122 | |
sv | 1:6799c07fe510 | 123 | /** STL const_iterator interface. */ |
sv | 1:6799c07fe510 | 124 | typedef const T* const_iterator; |
sv | 1:6799c07fe510 | 125 | |
sv | 1:6799c07fe510 | 126 | /** STL reverse iterator interface. */ |
sv | 1:6799c07fe510 | 127 | typedef std::reverse_iterator<iterator> reverse_iterator; |
sv | 1:6799c07fe510 | 128 | |
sv | 1:6799c07fe510 | 129 | /** STL const reverse iterator interface. */ |
sv | 1:6799c07fe510 | 130 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
sv | 1:6799c07fe510 | 131 | |
sv | 1:6799c07fe510 | 132 | public: |
sv | 1:6799c07fe510 | 133 | /** Dimensions. */ |
sv | 1:6799c07fe510 | 134 | enum { |
sv | 1:6799c07fe510 | 135 | Size = Sz /**< The size of the vector. */ |
sv | 1:6799c07fe510 | 136 | }; |
sv | 1:6799c07fe510 | 137 | |
sv | 1:6799c07fe510 | 138 | public: |
sv | 1:6799c07fe510 | 139 | /** Complexity counter. */ |
sv | 1:6799c07fe510 | 140 | enum { |
sv | 1:6799c07fe510 | 141 | ops_assign = Size, |
sv | 1:6799c07fe510 | 142 | ops = ops_assign, |
sv | 1:6799c07fe510 | 143 | use_meta = ops < TVMET_COMPLEXITY_V_ASSIGN_TRIGGER ? true : false |
sv | 1:6799c07fe510 | 144 | }; |
sv | 1:6799c07fe510 | 145 | |
sv | 1:6799c07fe510 | 146 | public: // STL interface |
sv | 1:6799c07fe510 | 147 | /** STL iterator interface. */ |
sv | 1:6799c07fe510 | 148 | iterator begin() { return m_data; } |
sv | 1:6799c07fe510 | 149 | |
sv | 1:6799c07fe510 | 150 | /** STL iterator interface. */ |
sv | 1:6799c07fe510 | 151 | iterator end() { return m_data + Size; } |
sv | 1:6799c07fe510 | 152 | |
sv | 1:6799c07fe510 | 153 | /** STL const_iterator interface. */ |
sv | 1:6799c07fe510 | 154 | const_iterator begin() const { return m_data; } |
sv | 1:6799c07fe510 | 155 | |
sv | 1:6799c07fe510 | 156 | /** STL const_iterator interface. */ |
sv | 1:6799c07fe510 | 157 | const_iterator end() const { return m_data + Size; } |
sv | 1:6799c07fe510 | 158 | |
sv | 1:6799c07fe510 | 159 | /** STL reverse iterator interface reverse begin. */ |
sv | 1:6799c07fe510 | 160 | reverse_iterator rbegin() { return reverse_iterator( end() ); } |
sv | 1:6799c07fe510 | 161 | |
sv | 1:6799c07fe510 | 162 | /** STL const reverse iterator interface reverse begin. */ |
sv | 1:6799c07fe510 | 163 | const_reverse_iterator rbegin() const { |
sv | 1:6799c07fe510 | 164 | return const_reverse_iterator( end() ); |
sv | 1:6799c07fe510 | 165 | } |
sv | 1:6799c07fe510 | 166 | |
sv | 1:6799c07fe510 | 167 | /** STL reverse iterator interface reverse end. */ |
sv | 1:6799c07fe510 | 168 | reverse_iterator rend() { return reverse_iterator( begin() ); } |
sv | 1:6799c07fe510 | 169 | |
sv | 1:6799c07fe510 | 170 | /** STL const reverse iterator interface reverse end. */ |
sv | 1:6799c07fe510 | 171 | const_reverse_iterator rend() const { |
sv | 1:6799c07fe510 | 172 | return const_reverse_iterator( begin() ); |
sv | 1:6799c07fe510 | 173 | } |
sv | 1:6799c07fe510 | 174 | |
sv | 1:6799c07fe510 | 175 | /** STL vector front element. */ |
sv | 1:6799c07fe510 | 176 | value_type front() { return m_data[0]; } |
sv | 1:6799c07fe510 | 177 | |
sv | 1:6799c07fe510 | 178 | /** STL vector const front element. */ |
sv | 1:6799c07fe510 | 179 | const_reference front() const { return m_data[0]; } |
sv | 1:6799c07fe510 | 180 | |
sv | 1:6799c07fe510 | 181 | /** STL vector back element. */ |
sv | 1:6799c07fe510 | 182 | value_type back() { return m_data[Size-1]; } |
sv | 1:6799c07fe510 | 183 | |
sv | 1:6799c07fe510 | 184 | /** STL vector const back element. */ |
sv | 1:6799c07fe510 | 185 | const_reference back() const { return m_data[Size-1]; } |
sv | 1:6799c07fe510 | 186 | |
sv | 1:6799c07fe510 | 187 | /** STL vector empty() - returns allways false. */ |
sv | 1:6799c07fe510 | 188 | static bool empty() { return false; } |
sv | 1:6799c07fe510 | 189 | |
sv | 1:6799c07fe510 | 190 | /** The size of the vector. */ |
sv | 1:6799c07fe510 | 191 | static std::size_t size() { return Size; } |
sv | 1:6799c07fe510 | 192 | |
sv | 1:6799c07fe510 | 193 | /** STL vector max_size() - returns allways Size. */ |
sv | 1:6799c07fe510 | 194 | static std::size_t max_size() { return Size; } |
sv | 1:6799c07fe510 | 195 | |
sv | 1:6799c07fe510 | 196 | public: |
sv | 1:6799c07fe510 | 197 | /** Default Destructor */ |
sv | 1:6799c07fe510 | 198 | ~Vector() { |
sv | 1:6799c07fe510 | 199 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 200 | delete [] m_data; |
sv | 1:6799c07fe510 | 201 | #endif |
sv | 1:6799c07fe510 | 202 | } |
sv | 1:6799c07fe510 | 203 | |
sv | 1:6799c07fe510 | 204 | /** Default Constructor. The allocated memory region isn't cleared. If you want |
sv | 1:6799c07fe510 | 205 | a clean use the constructor argument zero. */ |
sv | 1:6799c07fe510 | 206 | explicit Vector() |
sv | 1:6799c07fe510 | 207 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 208 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 209 | #endif |
sv | 1:6799c07fe510 | 210 | { } |
sv | 1:6799c07fe510 | 211 | |
sv | 1:6799c07fe510 | 212 | /** Copy Constructor, not explicit! */ |
sv | 1:6799c07fe510 | 213 | Vector(const Vector& rhs) |
sv | 1:6799c07fe510 | 214 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 215 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 216 | #endif |
sv | 1:6799c07fe510 | 217 | { |
sv | 1:6799c07fe510 | 218 | *this = XprVector<ConstReference, Size>(rhs.const_ref()); |
sv | 1:6799c07fe510 | 219 | } |
sv | 1:6799c07fe510 | 220 | |
sv | 1:6799c07fe510 | 221 | /** |
sv | 1:6799c07fe510 | 222 | * Constructor with STL iterator interface. The data will be copied into the |
sv | 1:6799c07fe510 | 223 | * vector self, there isn't any stored reference to the array pointer. |
sv | 1:6799c07fe510 | 224 | */ |
sv | 1:6799c07fe510 | 225 | template<class InputIterator> |
sv | 1:6799c07fe510 | 226 | explicit Vector(InputIterator first, InputIterator last) |
sv | 1:6799c07fe510 | 227 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 228 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 229 | #endif |
sv | 1:6799c07fe510 | 230 | { |
sv | 1:6799c07fe510 | 231 | TVMET_RT_CONDITION( static_cast<std::size_t>(std::distance(first, last)) <= Size, |
sv | 1:6799c07fe510 | 232 | "InputIterator doesn't fits in size" ) |
sv | 1:6799c07fe510 | 233 | std::copy(first, last, m_data); |
sv | 1:6799c07fe510 | 234 | } |
sv | 1:6799c07fe510 | 235 | |
sv | 1:6799c07fe510 | 236 | /** |
sv | 1:6799c07fe510 | 237 | * Constructor with STL iterator interface. The data will be copied into the |
sv | 1:6799c07fe510 | 238 | * vector self, there isn't any stored reference to the array pointer. |
sv | 1:6799c07fe510 | 239 | */ |
sv | 1:6799c07fe510 | 240 | template<class InputIterator> |
sv | 1:6799c07fe510 | 241 | explicit Vector(InputIterator first, std::size_t sz) |
sv | 1:6799c07fe510 | 242 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 243 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 244 | #endif |
sv | 1:6799c07fe510 | 245 | { |
sv | 1:6799c07fe510 | 246 | TVMET_RT_CONDITION( sz <= Size, "InputIterator doesn't fits in size" ) |
sv | 1:6799c07fe510 | 247 | std::copy(first, first + sz, m_data); |
sv | 1:6799c07fe510 | 248 | } |
sv | 1:6799c07fe510 | 249 | |
sv | 1:6799c07fe510 | 250 | /** Constructor with initializer for all elements. */ |
sv | 1:6799c07fe510 | 251 | explicit Vector(value_type rhs) |
sv | 1:6799c07fe510 | 252 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 253 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 254 | #endif |
sv | 1:6799c07fe510 | 255 | { |
sv | 1:6799c07fe510 | 256 | typedef XprLiteral<value_type> expr_type; |
sv | 1:6799c07fe510 | 257 | *this = XprVector<expr_type, Size>(expr_type(rhs)); |
sv | 1:6799c07fe510 | 258 | } |
sv | 1:6799c07fe510 | 259 | |
sv | 1:6799c07fe510 | 260 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 261 | explicit Vector(value_type x0, value_type x1) |
sv | 1:6799c07fe510 | 262 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 263 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 264 | #endif |
sv | 1:6799c07fe510 | 265 | { |
sv | 1:6799c07fe510 | 266 | TVMET_CT_CONDITION(2 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 267 | m_data[0] = x0; m_data[1] = x1; |
sv | 1:6799c07fe510 | 268 | } |
sv | 1:6799c07fe510 | 269 | |
sv | 1:6799c07fe510 | 270 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 271 | explicit Vector(value_type x0, value_type x1, value_type x2) |
sv | 1:6799c07fe510 | 272 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 273 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 274 | #endif |
sv | 1:6799c07fe510 | 275 | { |
sv | 1:6799c07fe510 | 276 | TVMET_CT_CONDITION(3 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 277 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; |
sv | 1:6799c07fe510 | 278 | } |
sv | 1:6799c07fe510 | 279 | |
sv | 1:6799c07fe510 | 280 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 281 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3) |
sv | 1:6799c07fe510 | 282 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 283 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 284 | #endif |
sv | 1:6799c07fe510 | 285 | { |
sv | 1:6799c07fe510 | 286 | TVMET_CT_CONDITION(4 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 287 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; |
sv | 1:6799c07fe510 | 288 | } |
sv | 1:6799c07fe510 | 289 | |
sv | 1:6799c07fe510 | 290 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 291 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3, |
sv | 1:6799c07fe510 | 292 | value_type x4) |
sv | 1:6799c07fe510 | 293 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 294 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 295 | #endif |
sv | 1:6799c07fe510 | 296 | { |
sv | 1:6799c07fe510 | 297 | TVMET_CT_CONDITION(5 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 298 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; m_data[4] = x4; |
sv | 1:6799c07fe510 | 299 | } |
sv | 1:6799c07fe510 | 300 | |
sv | 1:6799c07fe510 | 301 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 302 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3, |
sv | 1:6799c07fe510 | 303 | value_type x4, value_type x5) |
sv | 1:6799c07fe510 | 304 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 305 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 306 | #endif |
sv | 1:6799c07fe510 | 307 | { |
sv | 1:6799c07fe510 | 308 | TVMET_CT_CONDITION(6 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 309 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; m_data[4] = x4; |
sv | 1:6799c07fe510 | 310 | m_data[5] = x5; |
sv | 1:6799c07fe510 | 311 | } |
sv | 1:6799c07fe510 | 312 | |
sv | 1:6799c07fe510 | 313 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 314 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3, |
sv | 1:6799c07fe510 | 315 | value_type x4, value_type x5, value_type x6) |
sv | 1:6799c07fe510 | 316 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 317 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 318 | #endif |
sv | 1:6799c07fe510 | 319 | { |
sv | 1:6799c07fe510 | 320 | TVMET_CT_CONDITION(7 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 321 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; m_data[4] = x4; |
sv | 1:6799c07fe510 | 322 | m_data[5] = x5; m_data[6] = x6; |
sv | 1:6799c07fe510 | 323 | } |
sv | 1:6799c07fe510 | 324 | |
sv | 1:6799c07fe510 | 325 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 326 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3, |
sv | 1:6799c07fe510 | 327 | value_type x4, value_type x5, value_type x6, value_type x7) |
sv | 1:6799c07fe510 | 328 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 329 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 330 | #endif |
sv | 1:6799c07fe510 | 331 | { |
sv | 1:6799c07fe510 | 332 | TVMET_CT_CONDITION(8 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 333 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; m_data[4] = x4; |
sv | 1:6799c07fe510 | 334 | m_data[5] = x5; m_data[6] = x6; m_data[7] = x7; |
sv | 1:6799c07fe510 | 335 | } |
sv | 1:6799c07fe510 | 336 | |
sv | 1:6799c07fe510 | 337 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 338 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3, |
sv | 1:6799c07fe510 | 339 | value_type x4, value_type x5, value_type x6, value_type x7, |
sv | 1:6799c07fe510 | 340 | value_type x8) |
sv | 1:6799c07fe510 | 341 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 342 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 343 | #endif |
sv | 1:6799c07fe510 | 344 | { |
sv | 1:6799c07fe510 | 345 | TVMET_CT_CONDITION(9 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 346 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; m_data[4] = x4; |
sv | 1:6799c07fe510 | 347 | m_data[5] = x5; m_data[6] = x6; m_data[7] = x7; m_data[8] = x8; |
sv | 1:6799c07fe510 | 348 | } |
sv | 1:6799c07fe510 | 349 | |
sv | 1:6799c07fe510 | 350 | /** Default Constructor with initializer list. */ |
sv | 1:6799c07fe510 | 351 | explicit Vector(value_type x0, value_type x1, value_type x2, value_type x3, |
sv | 1:6799c07fe510 | 352 | value_type x4, value_type x5, value_type x6, value_type x7, |
sv | 1:6799c07fe510 | 353 | value_type x8, value_type x9) |
sv | 1:6799c07fe510 | 354 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 355 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 356 | #endif |
sv | 1:6799c07fe510 | 357 | { |
sv | 1:6799c07fe510 | 358 | TVMET_CT_CONDITION(10 <= Size, ArgumentList_is_too_long) |
sv | 1:6799c07fe510 | 359 | m_data[0] = x0; m_data[1] = x1; m_data[2] = x2; m_data[3] = x3; m_data[4] = x4; |
sv | 1:6799c07fe510 | 360 | m_data[5] = x5; m_data[6] = x6; m_data[7] = x7; m_data[8] = x8; m_data[9] = x9; |
sv | 1:6799c07fe510 | 361 | } |
sv | 1:6799c07fe510 | 362 | |
sv | 1:6799c07fe510 | 363 | /** Construct a vector by expression. */ |
sv | 1:6799c07fe510 | 364 | template <class E> |
sv | 1:6799c07fe510 | 365 | explicit Vector(const XprVector<E, Size>& e) |
sv | 1:6799c07fe510 | 366 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 367 | : m_data( new value_type[Size] ) |
sv | 1:6799c07fe510 | 368 | #endif |
sv | 1:6799c07fe510 | 369 | { |
sv | 1:6799c07fe510 | 370 | *this = e; |
sv | 1:6799c07fe510 | 371 | } |
sv | 1:6799c07fe510 | 372 | |
sv | 1:6799c07fe510 | 373 | /** Assign a value_type on array, this can be used for a single value |
sv | 1:6799c07fe510 | 374 | or a comma separeted list of values. */ |
sv | 1:6799c07fe510 | 375 | CommaInitializer<Vector, Size> operator=(value_type rhs) { |
sv | 1:6799c07fe510 | 376 | return CommaInitializer<Vector, Size>(*this, rhs); |
sv | 1:6799c07fe510 | 377 | } |
sv | 1:6799c07fe510 | 378 | |
sv | 1:6799c07fe510 | 379 | public: // access operators |
sv | 1:6799c07fe510 | 380 | value_type* _tvmet_restrict data() { return m_data; } |
sv | 1:6799c07fe510 | 381 | const value_type* _tvmet_restrict data() const { return m_data; } |
sv | 1:6799c07fe510 | 382 | |
sv | 1:6799c07fe510 | 383 | public: // index access operators |
sv | 1:6799c07fe510 | 384 | value_type& _tvmet_restrict operator()(std::size_t i) { |
sv | 1:6799c07fe510 | 385 | // Note: g++-2.95.3 does have problems on typedef reference |
sv | 1:6799c07fe510 | 386 | TVMET_RT_CONDITION(i < Size, "Vector Bounce Violation") |
sv | 1:6799c07fe510 | 387 | return m_data[i]; |
sv | 1:6799c07fe510 | 388 | } |
sv | 1:6799c07fe510 | 389 | |
sv | 1:6799c07fe510 | 390 | value_type operator()(std::size_t i) const { |
sv | 1:6799c07fe510 | 391 | TVMET_RT_CONDITION(i < Size, "Vector Bounce Violation") |
sv | 1:6799c07fe510 | 392 | return m_data[i]; |
sv | 1:6799c07fe510 | 393 | } |
sv | 1:6799c07fe510 | 394 | |
sv | 1:6799c07fe510 | 395 | value_type& _tvmet_restrict operator[](std::size_t i) { |
sv | 1:6799c07fe510 | 396 | // Note: g++-2.95.3 does have problems on typedef reference |
sv | 1:6799c07fe510 | 397 | return this->operator()(i); |
sv | 1:6799c07fe510 | 398 | } |
sv | 1:6799c07fe510 | 399 | |
sv | 1:6799c07fe510 | 400 | value_type operator[](std::size_t i) const { |
sv | 1:6799c07fe510 | 401 | return this->operator()(i); |
sv | 1:6799c07fe510 | 402 | } |
sv | 1:6799c07fe510 | 403 | |
sv | 1:6799c07fe510 | 404 | public: // ET interface |
sv | 1:6799c07fe510 | 405 | typedef VectorConstReference<T, Size> ConstReference; |
sv | 1:6799c07fe510 | 406 | |
sv | 1:6799c07fe510 | 407 | /** Return a const Reference of the internal data */ |
sv | 1:6799c07fe510 | 408 | ConstReference const_ref() const { return ConstReference(*this); } |
sv | 1:6799c07fe510 | 409 | |
sv | 1:6799c07fe510 | 410 | /** Return the vector as const expression. */ |
sv | 1:6799c07fe510 | 411 | XprVector<ConstReference, Size> as_expr() const { |
sv | 1:6799c07fe510 | 412 | return XprVector<ConstReference, Size>(this->const_ref()); |
sv | 1:6799c07fe510 | 413 | } |
sv | 1:6799c07fe510 | 414 | |
sv | 1:6799c07fe510 | 415 | private: |
sv | 1:6799c07fe510 | 416 | /** Wrapper for meta assign. */ |
sv | 1:6799c07fe510 | 417 | template<class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 418 | static inline |
sv | 1:6799c07fe510 | 419 | void do_assign(dispatch<true>, Dest& dest, const Src& src, const Assign& assign_fn) { |
sv | 1:6799c07fe510 | 420 | meta::Vector<Size, 0>::assign(dest, src, assign_fn); |
sv | 1:6799c07fe510 | 421 | } |
sv | 1:6799c07fe510 | 422 | |
sv | 1:6799c07fe510 | 423 | /** Wrapper for loop assign. */ |
sv | 1:6799c07fe510 | 424 | template<class Dest, class Src, class Assign> |
sv | 1:6799c07fe510 | 425 | static inline |
sv | 1:6799c07fe510 | 426 | void do_assign(dispatch<false>, Dest& dest, const Src& src, const Assign& assign_fn) { |
sv | 1:6799c07fe510 | 427 | loop::Vector<Size>::assign(dest, src, assign_fn); |
sv | 1:6799c07fe510 | 428 | } |
sv | 1:6799c07fe510 | 429 | |
sv | 1:6799c07fe510 | 430 | public: |
sv | 1:6799c07fe510 | 431 | /** assign this to a vector expression using the functional assign_fn. */ |
sv | 1:6799c07fe510 | 432 | template<class T2, class Assign> |
sv | 1:6799c07fe510 | 433 | void assign_to(Vector<T2, Size>& dest, const Assign& assign_fn) const { |
sv | 1:6799c07fe510 | 434 | do_assign(dispatch<use_meta>(), dest, *this, assign_fn); |
sv | 1:6799c07fe510 | 435 | } |
sv | 1:6799c07fe510 | 436 | |
sv | 1:6799c07fe510 | 437 | public: // assign operations |
sv | 1:6799c07fe510 | 438 | /** assign a given Vector element wise to this vector. |
sv | 1:6799c07fe510 | 439 | The operator=(const Vector&) is compiler generated. */ |
sv | 1:6799c07fe510 | 440 | template<class T2> |
sv | 1:6799c07fe510 | 441 | Vector& operator=(const Vector<T2, Size>& rhs) { |
sv | 1:6799c07fe510 | 442 | rhs.assign_to(*this, Fcnl_assign<value_type, T2>()); |
sv | 1:6799c07fe510 | 443 | return *this; |
sv | 1:6799c07fe510 | 444 | } |
sv | 1:6799c07fe510 | 445 | |
sv | 1:6799c07fe510 | 446 | /** assign a given XprVector element wise to this vector. */ |
sv | 1:6799c07fe510 | 447 | template<class E> |
sv | 1:6799c07fe510 | 448 | Vector& operator=(const XprVector<E, Size>& rhs) { |
sv | 1:6799c07fe510 | 449 | rhs.assign_to(*this, Fcnl_assign<value_type, typename E::value_type>()); |
sv | 1:6799c07fe510 | 450 | return *this; |
sv | 1:6799c07fe510 | 451 | } |
sv | 1:6799c07fe510 | 452 | |
sv | 1:6799c07fe510 | 453 | private: |
sv | 1:6799c07fe510 | 454 | template<class Obj, std::size_t LEN> friend class CommaInitializer; |
sv | 1:6799c07fe510 | 455 | |
sv | 1:6799c07fe510 | 456 | /** This is a helper for assigning a comma separated initializer |
sv | 1:6799c07fe510 | 457 | list. It's equal to Vector& operator=(value_type) which does |
sv | 1:6799c07fe510 | 458 | replace it. */ |
sv | 1:6799c07fe510 | 459 | Vector& assign_value(value_type rhs) { |
sv | 1:6799c07fe510 | 460 | typedef XprLiteral<value_type> expr_type; |
sv | 1:6799c07fe510 | 461 | *this = XprVector<expr_type, Size>(expr_type(rhs)); |
sv | 1:6799c07fe510 | 462 | return *this; |
sv | 1:6799c07fe510 | 463 | } |
sv | 1:6799c07fe510 | 464 | |
sv | 1:6799c07fe510 | 465 | public: // math operators with scalars |
sv | 1:6799c07fe510 | 466 | // NOTE: this meaning is clear - element wise ops even if not in ns element_wise |
sv | 1:6799c07fe510 | 467 | Vector& operator+=(value_type) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 468 | Vector& operator-=(value_type) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 469 | Vector& operator*=(value_type) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 470 | Vector& operator/=(value_type) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 471 | |
sv | 1:6799c07fe510 | 472 | Vector& operator%=(std::size_t) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 473 | Vector& operator^=(std::size_t) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 474 | Vector& operator&=(std::size_t) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 475 | Vector& operator|=(std::size_t) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 476 | Vector& operator<<=(std::size_t) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 477 | Vector& operator>>=(std::size_t) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 478 | |
sv | 1:6799c07fe510 | 479 | public: // math assign operators with vectors |
sv | 1:6799c07fe510 | 480 | // NOTE: access using the operators in ns element_wise, since that's what is does |
sv | 1:6799c07fe510 | 481 | template <class T2> Vector& M_add_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 482 | template <class T2> Vector& M_sub_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 483 | template <class T2> Vector& M_mul_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 484 | template <class T2> Vector& M_div_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 485 | template <class T2> Vector& M_mod_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 486 | template <class T2> Vector& M_xor_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 487 | template <class T2> Vector& M_and_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 488 | template <class T2> Vector& M_or_eq (const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 489 | template <class T2> Vector& M_shl_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 490 | template <class T2> Vector& M_shr_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 491 | |
sv | 1:6799c07fe510 | 492 | public: // math operators with expressions |
sv | 1:6799c07fe510 | 493 | // NOTE: access using the operators in ns element_wise, since that's what is does |
sv | 1:6799c07fe510 | 494 | template <class E> Vector& M_add_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 495 | template <class E> Vector& M_sub_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 496 | template <class E> Vector& M_mul_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 497 | template <class E> Vector& M_div_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 498 | template <class E> Vector& M_mod_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 499 | template <class E> Vector& M_xor_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 500 | template <class E> Vector& M_and_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 501 | template <class E> Vector& M_or_eq (const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 502 | template <class E> Vector& M_shl_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 503 | template <class E> Vector& M_shr_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 504 | |
sv | 1:6799c07fe510 | 505 | public: // aliased math operators with expressions, used with proxy |
sv | 1:6799c07fe510 | 506 | template <class T2> Vector& alias_assign(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 507 | template <class T2> Vector& alias_add_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 508 | template <class T2> Vector& alias_sub_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 509 | template <class T2> Vector& alias_mul_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 510 | template <class T2> Vector& alias_div_eq(const Vector<T2, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 511 | |
sv | 1:6799c07fe510 | 512 | template <class E> Vector& alias_assign(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 513 | template <class E> Vector& alias_add_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 514 | template <class E> Vector& alias_sub_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 515 | template <class E> Vector& alias_mul_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 516 | template <class E> Vector& alias_div_eq(const XprVector<E, Size>&) TVMET_CXX_ALWAYS_INLINE; |
sv | 1:6799c07fe510 | 517 | |
sv | 1:6799c07fe510 | 518 | public: // io |
sv | 1:6799c07fe510 | 519 | /** Structure for info printing as Vector<T, Size>. */ |
sv | 1:6799c07fe510 | 520 | struct Info : public TvmetBase<Info> { |
sv | 1:6799c07fe510 | 521 | std::ostream& print_xpr(std::ostream& os) const { |
sv | 1:6799c07fe510 | 522 | os << "Vector<T=" << typeid(value_type).name() |
sv | 1:6799c07fe510 | 523 | << ", Sz=" << Size << ">"; |
sv | 1:6799c07fe510 | 524 | return os; |
sv | 1:6799c07fe510 | 525 | } |
sv | 1:6799c07fe510 | 526 | }; |
sv | 1:6799c07fe510 | 527 | |
sv | 1:6799c07fe510 | 528 | /** Get an info object of this vector. */ |
sv | 1:6799c07fe510 | 529 | static Info info() { return Info(); } |
sv | 1:6799c07fe510 | 530 | |
sv | 1:6799c07fe510 | 531 | /** Member function for expression level printing. */ |
sv | 1:6799c07fe510 | 532 | std::ostream& print_xpr(std::ostream& os, std::size_t l=0) const; |
sv | 1:6799c07fe510 | 533 | |
sv | 1:6799c07fe510 | 534 | /** Member function for printing internal data. */ |
sv | 1:6799c07fe510 | 535 | std::ostream& print_on(std::ostream& os) const; |
sv | 1:6799c07fe510 | 536 | |
sv | 1:6799c07fe510 | 537 | private: |
sv | 1:6799c07fe510 | 538 | /** The data of vector self. */ |
sv | 1:6799c07fe510 | 539 | |
sv | 1:6799c07fe510 | 540 | #if defined(TVMET_DYNAMIC_MEMORY) |
sv | 1:6799c07fe510 | 541 | value_type* m_data; |
sv | 1:6799c07fe510 | 542 | #else |
sv | 1:6799c07fe510 | 543 | value_type m_data[Size]; |
sv | 1:6799c07fe510 | 544 | #endif |
sv | 1:6799c07fe510 | 545 | }; |
sv | 1:6799c07fe510 | 546 | |
sv | 1:6799c07fe510 | 547 | |
sv | 1:6799c07fe510 | 548 | } // namespace tvmet |
sv | 1:6799c07fe510 | 549 | |
sv | 1:6799c07fe510 | 550 | #include <tvmet/VectorImpl.h> |
sv | 1:6799c07fe510 | 551 | #include <tvmet/VectorFunctions.h> |
sv | 1:6799c07fe510 | 552 | #include <tvmet/VectorBinaryFunctions.h> |
sv | 1:6799c07fe510 | 553 | #include <tvmet/VectorUnaryFunctions.h> |
sv | 1:6799c07fe510 | 554 | #include <tvmet/VectorOperators.h> |
sv | 1:6799c07fe510 | 555 | #include <tvmet/VectorEval.h> |
sv | 1:6799c07fe510 | 556 | #include <tvmet/AliasProxy.h> |
sv | 1:6799c07fe510 | 557 | |
sv | 1:6799c07fe510 | 558 | #endif // TVMET_VECTOR_H |
sv | 1:6799c07fe510 | 559 | |
sv | 1:6799c07fe510 | 560 | // Local Variables: |
sv | 1:6799c07fe510 | 561 | // mode:C++ |
sv | 1:6799c07fe510 | 562 | // tab-width:8 |
sv | 1:6799c07fe510 | 563 | // End: |