All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseIterator.h
Go to the documentation of this file.
1 //=================================================================================================
24 //=================================================================================================
25 
26 #ifndef _BLAZE_MATH_DENSE_DENSEITERATOR_H_
27 #define _BLAZE_MATH_DENSE_DENSEITERATOR_H_
28 
29 
30 //*************************************************************************************************
31 // Includes
32 //*************************************************************************************************
33 
34 #include <iterator>
35 #include <blaze/math/Intrinsics.h>
37 #include <blaze/util/Assert.h>
38 #include <blaze/util/Null.h>
39 #include <blaze/util/Types.h>
40 
41 
42 namespace blaze {
43 
44 //=================================================================================================
45 //
46 // CLASS DEFINITION
47 //
48 //=================================================================================================
49 
50 //*************************************************************************************************
57 template< typename Type > // Type of the elements
59 {
60  public:
61  //**Type definitions****************************************************************************
62  typedef std::random_access_iterator_tag IteratorCategory;
63  typedef Type ValueType;
64  typedef Type* PointerType;
65  typedef Type& ReferenceType;
67 
68  // STL iterator requirements
71  typedef PointerType pointer;
74 
77  //**********************************************************************************************
78 
79  //**Constructors********************************************************************************
82  explicit inline DenseIterator();
83  explicit inline DenseIterator( Type* ptr );
84 
85  template< typename Other >
86  inline DenseIterator( const DenseIterator<Other>& it );
88  //**********************************************************************************************
89 
90  //**Destructor**********************************************************************************
91  // No explicitly declared destructor.
92  //**********************************************************************************************
93 
94  //**Assignment operators************************************************************************
97  // No explicitly declared copy assignment operator.
98  inline DenseIterator& operator+=( ptrdiff_t inc );
99  inline DenseIterator& operator-=( ptrdiff_t inc );
101  //**********************************************************************************************
102 
103  //**Increment/decrement operators***************************************************************
106  inline DenseIterator& operator++();
107  inline const DenseIterator operator++( int );
108  inline DenseIterator& operator--();
109  inline const DenseIterator operator--( int );
111  //**********************************************************************************************
112 
113  //**Access operators****************************************************************************
116  inline ReferenceType operator[]( size_t index ) const;
117  inline ReferenceType operator* () const;
118  inline PointerType operator->() const;
120  //**********************************************************************************************
121 
122  //**Utility functions***************************************************************************
125  inline PointerType base() const;
127  //**********************************************************************************************
128 
129  //**Expression template evaluation functions****************************************************
132  inline const IntrinsicType load () const;
133  inline const IntrinsicType loadu() const;
135  //**********************************************************************************************
136 
137  private:
138  //**Member variables****************************************************************************
142 
143  //**********************************************************************************************
144 };
145 //*************************************************************************************************
146 
147 
148 
149 
150 //=================================================================================================
151 //
152 // CONSTRUCTORS
153 //
154 //=================================================================================================
155 
156 //*************************************************************************************************
159 template< typename Type > // Type of the elements
161  : ptr_( NULL ) // Pointer to the current element
162 {}
163 //*************************************************************************************************
164 
165 
166 //*************************************************************************************************
171 template< typename Type > // Type of the elements
173  : ptr_( ptr ) // Pointer to the current element
174 {}
175 //*************************************************************************************************
176 
177 
178 //*************************************************************************************************
183 template< typename Type > // Type of the elements
184 template< typename Other > // Type of the foreign elements
186  : ptr_( it.base() ) // Pointer to the current element
187 {}
188 //*************************************************************************************************
189 
190 
191 
192 
193 //=================================================================================================
194 //
195 // ASSIGNMENT OPERATORS
196 //
197 //=================================================================================================
198 
199 //*************************************************************************************************
205 template< typename Type > // Type of the elements
207 {
208  ptr_ += inc;
209  return *this;
210 }
211 //*************************************************************************************************
212 
213 
214 //*************************************************************************************************
220 template< typename Type > // Type of the elements
222 {
223  ptr_ -= dec;
224  return *this;
225 }
226 //*************************************************************************************************
227 
228 
229 
230 
231 //=================================================================================================
232 //
233 // INCREMENT/DECREMENT OPERATORS
234 //
235 //=================================================================================================
236 
237 //*************************************************************************************************
242 template< typename Type > // Type of the elements
244 {
245  ++ptr_;
246  return *this;
247 }
248 //*************************************************************************************************
249 
250 
251 //*************************************************************************************************
256 template< typename Type > // Type of the elements
258 {
259  return DenseIterator( ptr_++ );
260 }
261 //*************************************************************************************************
262 
263 
264 //*************************************************************************************************
269 template< typename Type > // Type of the elements
271 {
272  --ptr_;
273  return *this;
274 }
275 //*************************************************************************************************
276 
277 
278 //*************************************************************************************************
283 template< typename Type > // Type of the elements
285 {
286  return DenseIterator( ptr_-- );
287 }
288 //*************************************************************************************************
289 
290 
291 
292 
293 //=================================================================================================
294 //
295 // OPERATORS
296 //
297 //=================================================================================================
298 
299 //*************************************************************************************************
305 template< typename Type > // Type of the elements
307  DenseIterator<Type>::operator[]( size_t index ) const
308 {
309  return ptr_[index];
310 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
319 template< typename Type > // Type of the elements
322 {
323  return *ptr_;
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
333 template< typename Type > // Type of the elements
334 inline typename DenseIterator<Type>::PointerType
336 {
337  return ptr_;
338 }
339 //*************************************************************************************************
340 
341 
342 
343 
344 //=================================================================================================
345 //
346 // UTILITY FUNCTIONS
347 //
348 //=================================================================================================
349 
350 //*************************************************************************************************
355 template< typename Type > // Type of the elements
357 {
358  return ptr_;
359 }
360 //*************************************************************************************************
361 
362 
363 
364 
365 //=================================================================================================
366 //
367 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
368 //
369 //=================================================================================================
370 
371 //*************************************************************************************************
381 template< typename Type > // Type of the elements
383 {
384  BLAZE_INTERNAL_ASSERT( checkAlignment( ptr_ ), "Invalid alignment detected" );
385  return blaze::load( ptr_ );
386 }
387 //*************************************************************************************************
388 
389 
390 //*************************************************************************************************
400 template< typename Type > // Type of the elements
402 {
403  return blaze::loadu( ptr_ );
404 }
405 //*************************************************************************************************
406 
407 
408 
409 
410 //=================================================================================================
411 //
412 // GLOBAL OPERATORS
413 //
414 //=================================================================================================
415 
416 //*************************************************************************************************
419 template< typename T1, typename T2 >
420 inline bool operator==( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs );
421 
422 template< typename T1, typename T2 >
423 inline bool operator!=( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs );
424 
425 template< typename T1, typename T2 >
426 inline bool operator<( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs );
427 
428 template< typename T1, typename T2 >
429 inline bool operator>( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs );
430 
431 template< typename T1, typename T2 >
432 inline bool operator<=( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs );
433 
434 template< typename T1, typename T2 >
435 inline bool operator>=( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs );
436 
437 template< typename Type >
438 inline const DenseIterator<Type> operator+( const DenseIterator<Type>& it, ptrdiff_t inc );
439 
440 template< typename Type >
441 inline const DenseIterator<Type> operator+( ptrdiff_t inc, const DenseIterator<Type>& it );
442 
443 template< typename Type >
444 inline const DenseIterator<Type> operator-( const DenseIterator<Type>& it, ptrdiff_t inc );
445 
446 template< typename Type >
447 inline ptrdiff_t operator-( const DenseIterator<Type>& lhs, const DenseIterator<Type>& rhs );
449 //*************************************************************************************************
450 
451 
452 //*************************************************************************************************
459 template< typename T1 // Element type of the left-hand side iterator
460  , typename T2 > // Element type of the right-hand side iterator
461 inline bool operator==( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs )
462 {
463  return lhs.base() == rhs.base();
464 }
465 //*************************************************************************************************
466 
467 
468 //*************************************************************************************************
475 template< typename T1 // Element type of the left-hand side iterator
476  , typename T2 > // Element type of the right-hand side iterator
477 inline bool operator!=( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs )
478 {
479  return lhs.base() != rhs.base();
480 }
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
491 template< typename T1 // Element type of the left-hand side iterator
492  , typename T2 > // Element type of the right-hand side iterator
493 inline bool operator<( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs )
494 {
495  return lhs.base() < rhs.base();
496 }
497 //*************************************************************************************************
498 
499 
500 //*************************************************************************************************
507 template< typename T1 // Element type of the left-hand side iterator
508  , typename T2 > // Element type of the right-hand side iterator
509 inline bool operator>( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs )
510 {
511  return lhs.base() > rhs.base();
512 }
513 //*************************************************************************************************
514 
515 
516 //*************************************************************************************************
523 template< typename T1 // Element type of the left-hand side iterator
524  , typename T2 > // Element type of the right-hand side iterator
525 inline bool operator<=( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs )
526 {
527  return lhs.base() <= rhs.base();
528 }
529 //*************************************************************************************************
530 
531 
532 //*************************************************************************************************
539 template< typename T1 // Element type of the left-hand side iterator
540  , typename T2 > // Element type of the right-hand side iterator
541 inline bool operator>=( const DenseIterator<T1>& lhs, const DenseIterator<T2>& rhs )
542 {
543  return lhs.base() >= rhs.base();
544 }
545 //*************************************************************************************************
546 
547 
548 //*************************************************************************************************
555 template< typename Type > // Element type of the iterator
557  return DenseIterator<Type>( it.base() + inc );
558 }
559 //*************************************************************************************************
560 
561 
562 //*************************************************************************************************
569 template< typename Type > // Element type of the iterator
571 {
572  return DenseIterator<Type>( it.base() + inc );
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
584 template< typename Type > // Element type of the iterator
586 {
587  return DenseIterator<Type>( it.base() - dec );
588 }
589 //*************************************************************************************************
590 
591 
592 //*************************************************************************************************
599 template< typename Type > // Element type of the iterator
601 {
602  return lhs.base() - rhs.base();
603 }
604 //*************************************************************************************************
605 
606 } // namespace blaze
607 
608 #endif
Pointer difference type of the Blaze library.
DenseIterator & operator++()
Pre-increment operator.
Definition: DenseIterator.h:243
PointerType operator->() const
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:335
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DenseIterator.h:66
PointerType ptr_
Pointer to the current element.
Definition: DenseIterator.h:141
Type ValueType
Type of the underlying elements.
Definition: DenseIterator.h:63
DenseIterator()
Default constructor for the DenseIterator class.
Definition: DenseIterator.h:160
const IntrinsicType load() const
Aligned load of the intrinsic element at the current iterator position.
Definition: DenseIterator.h:382
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:224
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
ReferenceType operator[](size_t index) const
Direct access to the underlying elements.
Definition: DenseIterator.h:307
PointerType pointer
Pointer return type.
Definition: DenseIterator.h:71
ValueType value_type
Type of the underlying elements.
Definition: DenseIterator.h:70
const IntrinsicType loadu() const
Unaligned load of the intrinsic element at the current iterator position.
Definition: DenseIterator.h:401
IntrinsicTrait< Type >::Type IntrinsicType
Intrinsic type of the elements.
Definition: DenseIterator.h:76
const DenseIterator< Type > operator+(const DenseIterator< Type > &it, ptrdiff_t inc)
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:556
DenseIterator & operator-=(ptrdiff_t inc)
Subtraction assignment operator.
Definition: DenseIterator.h:221
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Loadu< T, sizeof(T)> >::Type::Type loadu(const T *address)
Loads a vector of integral values.
Definition: Loadu.h:221
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DenseIterator.h:62
DenseIterator & operator+=(ptrdiff_t inc)
Addition assignment operator.
Definition: DenseIterator.h:206
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
Header file for run time assertion macros.
Type & ReferenceType
Reference return type.
Definition: DenseIterator.h:65
const DenseIterator< Type > operator-(const DenseIterator< Type > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:585
ReferenceType operator*() const
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:321
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
Header file for all intrinsic functionality.
Type * PointerType
Pointer return type.
Definition: DenseIterator.h:64
IteratorCategory iterator_category
The iterator category.
Definition: DenseIterator.h:69
bool checkAlignment(const T *address)
Checks the alignment of the given.
Definition: AlignmentCheck.h:68
Header file for the alignment check function.
PointerType base() const
Low-level access to the underlying member of the iterator.
Definition: DenseIterator.h:356
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
DifferenceType difference_type
Difference between two iterators.
Definition: DenseIterator.h:73
DenseIterator & operator--()
Pre-decrement operator.
Definition: DenseIterator.h:270
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
ReferenceType reference
Reference return type.
Definition: DenseIterator.h:72
Header file for a safe C++ NULL pointer implementation.