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
58  , bool AF > // Alignment flag
60 {
61  public:
62  //**Type definitions****************************************************************************
63  typedef std::random_access_iterator_tag IteratorCategory;
64  typedef Type ValueType;
65  typedef Type* PointerType;
66  typedef Type& ReferenceType;
68 
69  // STL iterator requirements
70  typedef IteratorCategory iterator_category;
71  typedef ValueType value_type;
72  typedef PointerType pointer;
73  typedef ReferenceType reference;
74  typedef DifferenceType difference_type;
75 
78  //**********************************************************************************************
79 
80  //**Constructors********************************************************************************
83  explicit inline DenseIterator();
84  explicit inline DenseIterator( Type* ptr );
85 
86  template< typename Other, bool AF2 >
87  inline DenseIterator( const DenseIterator<Other,AF2>& it );
89  //**********************************************************************************************
90 
91  //**Destructor**********************************************************************************
92  // No explicitly declared destructor.
93  //**********************************************************************************************
94 
95  //**Assignment operators************************************************************************
98  // No explicitly declared copy assignment operator.
99  inline DenseIterator& operator+=( ptrdiff_t inc );
100  inline DenseIterator& operator-=( ptrdiff_t inc );
102  //**********************************************************************************************
103 
104  //**Increment/decrement operators***************************************************************
107  inline DenseIterator& operator++();
108  inline const DenseIterator operator++( int );
109  inline DenseIterator& operator--();
110  inline const DenseIterator operator--( int );
112  //**********************************************************************************************
113 
114  //**Access operators****************************************************************************
117  inline ReferenceType operator[]( size_t index ) const;
118  inline ReferenceType operator* () const;
119  inline PointerType operator->() const;
121  //**********************************************************************************************
122 
123  //**Utility functions***************************************************************************
126  inline PointerType base() const;
128  //**********************************************************************************************
129 
130  //**Expression template evaluation functions****************************************************
133  inline const IntrinsicType load () const;
134  inline const IntrinsicType loada() const;
135  inline const IntrinsicType loadu() const;
137  //**********************************************************************************************
138 
139  private:
140  //**Member variables****************************************************************************
143  PointerType ptr_;
144 
145  //**********************************************************************************************
146 };
147 //*************************************************************************************************
148 
149 
150 
151 
152 //=================================================================================================
153 //
154 // CONSTRUCTORS
155 //
156 //=================================================================================================
157 
158 //*************************************************************************************************
161 template< typename Type // Type of the elements
162  , bool AF > // Alignment flag
164  : ptr_( NULL ) // Pointer to the current element
165 {}
166 //*************************************************************************************************
167 
168 
169 //*************************************************************************************************
174 template< typename Type // Type of the elements
175  , bool AF > // Alignment flag
177  : ptr_( ptr ) // Pointer to the current element
178 {}
179 //*************************************************************************************************
180 
181 
182 //*************************************************************************************************
187 template< typename Type // Type of the elements
188  , bool AF > // Alignment flag
189 template< typename Other // Type of the foreign elements
190  , bool AF2 > // Alignment flag of the foreign iterator
192  : ptr_( it.base() ) // Pointer to the current element
193 {}
194 //*************************************************************************************************
195 
196 
197 
198 
199 //=================================================================================================
200 //
201 // ASSIGNMENT OPERATORS
202 //
203 //=================================================================================================
204 
205 //*************************************************************************************************
211 template< typename Type // Type of the elements
212  , bool AF > // Alignment flag
214 {
215  ptr_ += inc;
216  return *this;
217 }
218 //*************************************************************************************************
219 
220 
221 //*************************************************************************************************
227 template< typename Type // Type of the elements
228  , bool AF > // Alignment flag
230 {
231  ptr_ -= dec;
232  return *this;
233 }
234 //*************************************************************************************************
235 
236 
237 
238 
239 //=================================================================================================
240 //
241 // INCREMENT/DECREMENT OPERATORS
242 //
243 //=================================================================================================
244 
245 //*************************************************************************************************
250 template< typename Type // Type of the elements
251  , bool AF > // Alignment flag
253 {
254  ++ptr_;
255  return *this;
256 }
257 //*************************************************************************************************
258 
259 
260 //*************************************************************************************************
265 template< typename Type // Type of the elements
266  , bool AF > // Alignment flag
268 {
269  return DenseIterator( ptr_++ );
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
279 template< typename Type // Type of the elements
280  , bool AF > // Alignment flag
282 {
283  --ptr_;
284  return *this;
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
294 template< typename Type // Type of the elements
295  , bool AF > // Alignment flag
297 {
298  return DenseIterator( ptr_-- );
299 }
300 //*************************************************************************************************
301 
302 
303 
304 
305 //=================================================================================================
306 //
307 // OPERATORS
308 //
309 //=================================================================================================
310 
311 //*************************************************************************************************
317 template< typename Type // Type of the elements
318  , bool AF > // Alignment flag
321 {
322  return ptr_[index];
323 }
324 //*************************************************************************************************
325 
326 
327 //*************************************************************************************************
332 template< typename Type // Type of the elements
333  , bool AF > // Alignment flag
336 {
337  return *ptr_;
338 }
339 //*************************************************************************************************
340 
341 
342 //*************************************************************************************************
347 template< typename Type // Type of the elements
348  , bool AF > // Alignment flag
351 {
352  return ptr_;
353 }
354 //*************************************************************************************************
355 
356 
357 
358 
359 //=================================================================================================
360 //
361 // UTILITY FUNCTIONS
362 //
363 //=================================================================================================
364 
365 //*************************************************************************************************
370 template< typename Type // Type of the elements
371  , bool AF > // Alignment flag
373 {
374  return ptr_;
375 }
376 //*************************************************************************************************
377 
378 
379 
380 
381 //=================================================================================================
382 //
383 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
384 //
385 //=================================================================================================
386 
387 //*************************************************************************************************
397 template< typename Type // Type of the elements
398  , bool AF > // Alignment flag
400 {
401  if( AF )
402  return loada();
403  else
404  return loadu();
405 }
406 //*************************************************************************************************
407 
408 
409 //*************************************************************************************************
419 template< typename Type // Type of the elements
420  , bool AF > // Alignment flag
422 {
423  BLAZE_INTERNAL_ASSERT( checkAlignment( ptr_ ), "Invalid alignment detected" );
424 
425  return blaze::loada( ptr_ );
426 }
427 //*************************************************************************************************
428 
429 
430 //*************************************************************************************************
440 template< typename Type // Type of the elements
441  , bool AF > // Alignment flag
443 {
444  return blaze::loadu( ptr_ );
445 }
446 //*************************************************************************************************
447 
448 
449 
450 
451 //=================================================================================================
452 //
453 // GLOBAL OPERATORS
454 //
455 //=================================================================================================
456 
457 //*************************************************************************************************
460 template< typename T1, bool AF1, typename T2, bool AF2 >
461 inline bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs );
462 
463 template< typename T1, bool AF1, typename T2, bool AF2 >
464 inline bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs );
465 
466 template< typename T1, bool AF1, typename T2, bool AF2 >
467 inline bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs );
468 
469 template< typename T1, bool AF1, typename T2, bool AF2 >
470 inline bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs );
471 
472 template< typename T1, bool AF1, typename T2, bool AF2 >
473 inline bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs );
474 
475 template< typename T1, bool AF1, typename T2, bool AF2 >
476 inline bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs );
477 
478 template< typename Type, bool AF >
480 
481 template< typename Type, bool AF >
483 
484 template< typename Type, bool AF >
486 
487 template< typename Type, bool AF >
488 inline ptrdiff_t operator-( const DenseIterator<Type,AF>& lhs, const DenseIterator<Type,AF>& rhs );
490 //*************************************************************************************************
491 
492 
493 //*************************************************************************************************
500 template< typename T1 // Element type of the left-hand side iterator
501  , bool AF1 // Alignment flag of the left-hand side iterator
502  , typename T2 // Element type of the right-hand side iterator
503  , bool AF2 > // Alignment flag of the right-hand side iterator
504 inline bool operator==( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs )
505 {
506  return lhs.base() == rhs.base();
507 }
508 //*************************************************************************************************
509 
510 
511 //*************************************************************************************************
518 template< typename T1 // Element type of the left-hand side iterator
519  , bool AF1 // Alignment flag of the left-hand side iterator
520  , typename T2 // Element type of the right-hand side iterator
521  , bool AF2 > // Alignment flag of the right-hand side iterator
522 inline bool operator!=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs )
523 {
524  return lhs.base() != rhs.base();
525 }
526 //*************************************************************************************************
527 
528 
529 //*************************************************************************************************
536 template< typename T1 // Element type of the left-hand side iterator
537  , bool AF1 // Alignment flag of the left-hand side iterator
538  , typename T2 // Element type of the right-hand side iterator
539  , bool AF2 > // Alignment flag of the right-hand side iterator
540 inline bool operator<( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs )
541 {
542  return lhs.base() < rhs.base();
543 }
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
554 template< typename T1 // Element type of the left-hand side iterator
555  , bool AF1 // Alignment flag of the left-hand side iterator
556  , typename T2 // Element type of the right-hand side iterator
557  , bool AF2 > // Alignment flag of the right-hand side iterator
558 inline bool operator>( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs )
559 {
560  return lhs.base() > rhs.base();
561 }
562 //*************************************************************************************************
563 
564 
565 //*************************************************************************************************
572 template< typename T1 // Element type of the left-hand side iterator
573  , bool AF1 // Alignment flag of the left-hand side iterator
574  , typename T2 // Element type of the right-hand side iterator
575  , bool AF2 > // Alignment flag of the right-hand side iterator
576 inline bool operator<=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs )
577 {
578  return lhs.base() <= rhs.base();
579 }
580 //*************************************************************************************************
581 
582 
583 //*************************************************************************************************
590 template< typename T1 // Element type of the left-hand side iterator
591  , bool AF1 // Alignment flag of the left-hand side iterator
592  , typename T2 // Element type of the right-hand side iterator
593  , bool AF2 > // Alignment flag of the right-hand side iterator
594 inline bool operator>=( const DenseIterator<T1,AF1>& lhs, const DenseIterator<T2,AF2>& rhs )
595 {
596  return lhs.base() >= rhs.base();
597 }
598 //*************************************************************************************************
599 
600 
601 //*************************************************************************************************
608 template< typename Type // Element type of the iterator
609  , bool AF > // Alignment flag of the iterator
611 {
612  return DenseIterator<Type,AF>( it.base() + inc );
613 }
614 //*************************************************************************************************
615 
616 
617 //*************************************************************************************************
624 template< typename Type // Element type of the iterator
625  , bool AF > // Alignment flag of the iterator
627 {
628  return DenseIterator<Type,AF>( it.base() + inc );
629 }
630 //*************************************************************************************************
631 
632 
633 //*************************************************************************************************
640 template< typename Type // Element type of the iterator
641  , bool AF > // Alignment flag of the iterator
643 {
644  return DenseIterator<Type,AF>( it.base() - dec );
645 }
646 //*************************************************************************************************
647 
648 
649 //*************************************************************************************************
656 template< typename Type // Element type of the iterator
657  , bool AF > // Alignment flag of the iterator
659 {
660  return lhs.base() - rhs.base();
661 }
662 //*************************************************************************************************
663 
664 } // namespace blaze
665 
666 #endif
Pointer difference type of the Blaze library.
const IntrinsicType loada() const
Aligned load of the intrinsic element at the current iterator position.
Definition: DenseIterator.h:421
ValueType value_type
Type of the underlying elements.
Definition: DenseIterator.h:71
Header file for basic type definitions.
ReferenceType operator[](size_t index) const
Direct access to the underlying elements.
Definition: DenseIterator.h:320
PointerType operator->() const
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:350
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: DenseIterator.h:67
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
Type ValueType
Type of the underlying elements.
Definition: DenseIterator.h:64
ReferenceType operator*() const
Direct access to the element at the current iterator position.
Definition: DenseIterator.h:335
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loadu(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loadu.h:74
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Type & ReferenceType
Reference return type.
Definition: DenseIterator.h:66
const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:610
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:642
DenseIterator & operator--()
Pre-decrement operator.
Definition: DenseIterator.h:281
const IntrinsicType load() const
Aligned load of the intrinsic element at the current iterator position.
Definition: DenseIterator.h:399
ReferenceType reference
Reference return type.
Definition: DenseIterator.h:73
PointerType ptr_
Pointer to the current element.
Definition: DenseIterator.h:143
DenseIterator & operator-=(ptrdiff_t inc)
Subtraction assignment operator.
Definition: DenseIterator.h:229
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loada(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loada.h:77
IteratorCategory iterator_category
The iterator category.
Definition: DenseIterator.h:70
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:1232
Header file for run time assertion macros.
Type * PointerType
Pointer return type.
Definition: DenseIterator.h:65
IntrinsicTrait< Type >::Type IntrinsicType
Intrinsic type of the elements.
Definition: DenseIterator.h:77
DenseIterator & operator+=(ptrdiff_t inc)
Addition assignment operator.
Definition: DenseIterator.h:213
PointerType pointer
Pointer return type.
Definition: DenseIterator.h:72
DifferenceType difference_type
Difference between two iterators.
Definition: DenseIterator.h:74
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:59
Header file for all intrinsic functionality.
PointerType base() const
Low-level access to the underlying member of the iterator.
Definition: DenseIterator.h:372
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
Header file for the alignment check function.
DenseIterator()
Default constructor for the DenseIterator class.
Definition: DenseIterator.h:163
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
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: DenseIterator.h:63
const IntrinsicType loadu() const
Unaligned load of the intrinsic element at the current iterator position.
Definition: DenseIterator.h:442
#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
DenseIterator & operator++()
Pre-increment operator.
Definition: DenseIterator.h:252
Header file for a safe C++ NULL pointer implementation.