All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PtrIterator.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_PTRITERATOR_H_
36 #define _BLAZE_UTIL_PTRITERATOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <blaze/util/Null.h>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
107 template< typename Type >
109 {
110  public:
111  //**Type definitions****************************************************************************
112  // blaze naming convention
113  typedef std::random_access_iterator_tag IteratorCategory;
114  typedef Type* ValueType;
115  typedef Type* PointerType;
116  typedef ValueType const& ReferenceType;
117  typedef ValueType const* IteratorType;
118  typedef std::ptrdiff_t DifferenceType;
119 
120  // STL iterator requirements
126  //**********************************************************************************************
127 
128  //**Constructors********************************************************************************
131  inline PtrIterator();
132  explicit inline PtrIterator( const IteratorType& it );
133 
134  template< typename Other >
135  inline PtrIterator( const PtrIterator<Other>& it );
136 
137  // No explicitly declared copy constructor.
139  //**********************************************************************************************
140 
141  //**Destructor**********************************************************************************
142  // No explicitly declared destructor.
143  //**********************************************************************************************
144 
145  //**Copy assignment operator********************************************************************
146  // No explicitly declared copy assignment operator.
147  //**********************************************************************************************
148 
149  //**Operators***********************************************************************************
152  inline PtrIterator& operator++();
153  inline PtrIterator operator++( int );
154  inline PtrIterator& operator--();
155  inline PtrIterator operator--( int );
157  inline PtrIterator operator+ ( DifferenceType n ) const;
159  inline PtrIterator operator- ( DifferenceType n ) const;
160  inline DifferenceType operator- ( const PtrIterator& it ) const;
162  //**********************************************************************************************
163 
164  //**Access operators****************************************************************************
167  inline PointerType operator[]( DifferenceType n ) const;
168  inline PointerType operator*() const;
169  inline PointerType operator->() const;
171  //**********************************************************************************************
172 
173  //**Utility functions***************************************************************************
176  inline const IteratorType& base() const;
178  //**********************************************************************************************
179 
180  private:
181  //**Member variables****************************************************************************
185 
186  //**********************************************************************************************
187 };
188 //*************************************************************************************************
189 
190 
191 
192 
193 //=================================================================================================
194 //
195 // CONSTRUCTORS
196 //
197 //=================================================================================================
198 
199 //*************************************************************************************************
202 template< typename Type >
204  : it_(NULL) // Pointer to the current memory location
205 {}
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
214 template< typename Type >
216  : it_(it) // Pointer to the current memory location
217 {}
218 //*************************************************************************************************
219 
220 
221 //*************************************************************************************************
226 template< typename Type >
227 template< typename Other >
229  : it_( it.base() ) // Pointer to the current memory location
230 {}
231 //*************************************************************************************************
232 
233 
234 
235 
236 //=================================================================================================
237 //
238 // OPERATORS
239 //
240 //=================================================================================================
241 
242 //*************************************************************************************************
247 template< typename Type >
249 {
250  ++it_;
251  return *this;
252 }
253 //*************************************************************************************************
254 
255 
256 //*************************************************************************************************
261 template< typename Type >
263 {
264  PtrIterator tmp( *this );
265  ++it_;
266  return tmp;
267 }
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
276 template< typename Type >
278 {
279  --it_;
280  return *this;
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
290 template< typename Type >
292 {
293  PtrIterator tmp( *this );
294  --it_;
295  return tmp;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
306 template< typename Type >
308 {
309  it_ += n;
310  return *this;
311 }
312 //*************************************************************************************************
313 
314 
315 //*************************************************************************************************
321 template< typename Type >
323 {
324  return PtrIterator( it_ + n );
325 }
326 //*************************************************************************************************
327 
328 
329 //*************************************************************************************************
335 template< typename Type >
337 {
338  it_ -= n;
339  return *this;
340 }
341 //*************************************************************************************************
342 
343 
344 //*************************************************************************************************
350 template< typename Type >
352 {
353  return PtrIterator( it_ - n );
354 }
355 //*************************************************************************************************
356 
357 
358 //*************************************************************************************************
364 template< typename Type >
366 {
367  return it_ - it.it_;
368 }
369 //*************************************************************************************************
370 
371 
372 
373 
374 //=================================================================================================
375 //
376 // ACCESS OPERATORS
377 //
378 //=================================================================================================
379 
380 //*************************************************************************************************
386 template< typename Type >
388 {
389  return it_[index];
390 }
391 //*************************************************************************************************
392 
393 
394 //*************************************************************************************************
399 template< typename Type >
401 {
402  return *it_;
403 }
404 //*************************************************************************************************
405 
406 
407 //*************************************************************************************************
412 template< typename Type >
414 {
415  return *it_;
416 }
417 //*************************************************************************************************
418 
419 
420 
421 
422 //=================================================================================================
423 //
424 // UTILITY FUNCTIONS
425 //
426 //=================================================================================================
427 
428 //*************************************************************************************************
433 template< typename Type >
435 {
436  return it_;
437 }
438 //*************************************************************************************************
439 
440 
441 
442 
443 //=================================================================================================
444 //
445 // GLOBAL OPERATORS
446 //
447 //=================================================================================================
448 
449 //*************************************************************************************************
452 template< typename TypeL, typename TypeR >
453 inline bool operator==( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
454 
455 template< typename TypeL, typename TypeR >
456 inline bool operator!=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
457 
458 template< typename TypeL, typename TypeR >
459 inline bool operator<( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
460 
461 template< typename TypeL, typename TypeR >
462 inline bool operator>( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
463 
464 template< typename TypeL, typename TypeR >
465 inline bool operator<=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
466 
467 template< typename TypeL, typename TypeR >
468 inline bool operator>=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
470 //*************************************************************************************************
471 
472 
473 //*************************************************************************************************
480 template< typename TypeL, typename TypeR >
481 inline bool operator==( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
482 {
483  return lhs.base() == rhs.base();
484 }
485 //*************************************************************************************************
486 
487 
488 //*************************************************************************************************
495 template< typename TypeL, typename TypeR >
496 inline bool operator!=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
497 {
498  return lhs.base() != rhs.base();
499 }
500 //*************************************************************************************************
501 
502 
503 //*************************************************************************************************
510 template< typename TypeL, typename TypeR >
511 inline bool operator<( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
512 {
513  return lhs.base() < rhs.base();
514 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
525 template< typename TypeL, typename TypeR >
526 inline bool operator>( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
527 {
528  return lhs.base() > rhs.base();
529 }
530 //*************************************************************************************************
531 
532 
533 //*************************************************************************************************
540 template< typename TypeL, typename TypeR >
541 inline bool operator<=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
542 {
543  return lhs.base() <= rhs.base();
544 }
545 //*************************************************************************************************
546 
547 
548 //*************************************************************************************************
555 template< typename TypeL, typename TypeR >
556 inline bool operator>=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
557 {
558  return lhs.base() >= rhs.base();
559 }
560 //*************************************************************************************************
561 
562 } // namespace blaze
563 
564 #endif
PointerType pointer
Pointer return type.
Definition: PtrIterator.h:123
Type * ValueType
Type of the underlying pointers.
Definition: PtrIterator.h:114
PtrIterator & operator++()
Pre-increment operator.
Definition: PtrIterator.h:248
PtrIterator & operator-=(DifferenceType n)
Shifting the iterator by n elements to the lower elements.
Definition: PtrIterator.h:336
PtrIterator & operator--()
Pre-decrement operator.
Definition: PtrIterator.h:277
const blaze::Null NULL
Global NULL pointer.This instance of the Null class replaces the NULL macro to ensure a type-safe NUL...
Definition: Null.h:300
Header file for a safe C++ NULL pointer implementation.
ValueType const & ReferenceType
Reference return type.
Definition: PtrIterator.h:116
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
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: PtrIterator.h:113
Type * PointerType
Pointer return type.
Definition: PtrIterator.h:115
IteratorType it_
Pointer to the current memory location.
Definition: PtrIterator.h:184
PtrIterator & operator+=(DifferenceType n)
Shifting the iterator by n elements to the higher elements.
Definition: PtrIterator.h:307
PointerType operator[](DifferenceType n) const
Subscript operator for the direct element access.
Definition: PtrIterator.h:387
PtrIterator operator+(DifferenceType n) const
Shifting the iterator by n elements to the higher elements.
Definition: PtrIterator.h:322
Implementation of an iterator for pointer vectors.The PtrIterator class follows the example of the ra...
Definition: PtrIterator.h:108
std::ptrdiff_t DifferenceType
Difference between two iterators.
Definition: PtrIterator.h:118
PtrIterator operator-(DifferenceType n) const
Shifting the iterator by n elements to the lower elements.
Definition: PtrIterator.h:351
ReferenceType reference
Reference return type.
Definition: PtrIterator.h:124
ValueType const * IteratorType
Type of the internal pointer.
Definition: PtrIterator.h:117
PointerType operator*() const
Returns a handle to the element at the current iterator position.
Definition: PtrIterator.h:400
PointerType operator->() const
Direct access to the element at the current iterator position.
Definition: PtrIterator.h:413
ValueType value_type
Type of the underlying pointers.
Definition: PtrIterator.h:122
DifferenceType difference_type
Difference between two iterators.
Definition: PtrIterator.h:125
IteratorCategory iterator_category
The iterator category.
Definition: PtrIterator.h:121
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
const IteratorType & base() const
Access to the underlying member of the pointer iterator.
Definition: PtrIterator.h:434
PtrIterator()
Default constructor for PtrIterator.
Definition: PtrIterator.h:203