Eurobot2012_Secondary

Fork of Eurobot_2012_Secondary by Shuto Naruse

Committer:
narshu
Date:
Wed Oct 17 22:25:31 2012 +0000
Revision:
1:cc2a9eb0bd55
Commit before publishing

Who changed what in which revision?

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