All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PtrIterator.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_UTIL_PTRITERATOR_H_
23 #define _BLAZE_UTIL_PTRITERATOR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <iterator>
31 #include <blaze/util/Null.h>
32 
33 
34 namespace blaze {
35 
36 //=================================================================================================
37 //
38 // CLASS DEFINITION
39 //
40 //=================================================================================================
41 
42 //*************************************************************************************************
94 template< typename Type >
96 {
97  public:
98  //**Type definitions****************************************************************************
99  // pe naming convention
100  typedef std::random_access_iterator_tag IteratorCategory;
101  typedef Type* ValueType;
102  typedef Type* PointerType;
103  typedef ValueType const& ReferenceType;
104  typedef ValueType const* IteratorType;
105  typedef std::ptrdiff_t DifferenceType;
106 
107  // STL iterator requirements
113  //**********************************************************************************************
114 
115  //**Constructors********************************************************************************
118  inline PtrIterator();
119  explicit inline PtrIterator( const IteratorType& it );
120 
121  template< typename Other >
122  inline PtrIterator( const PtrIterator<Other>& it );
123 
124  // No explicitly declared copy constructor.
126  //**********************************************************************************************
127 
128  //**Destructor**********************************************************************************
129  // No explicitly declared destructor.
130  //**********************************************************************************************
131 
132  //**Copy assignment operator********************************************************************
133  // No explicitly declared copy assignment operator.
134  //**********************************************************************************************
135 
136  //**Operators***********************************************************************************
139  inline PtrIterator& operator++();
140  inline PtrIterator operator++( int );
141  inline PtrIterator& operator--();
142  inline PtrIterator operator--( int );
144  inline PtrIterator operator+ ( DifferenceType n ) const;
146  inline PtrIterator operator- ( DifferenceType n ) const;
147  inline DifferenceType operator- ( const PtrIterator& it ) const;
149  //**********************************************************************************************
150 
151  //**Access operators****************************************************************************
154  inline PointerType operator[]( DifferenceType n ) const;
155  inline PointerType operator*() const;
156  inline PointerType operator->() const;
158  //**********************************************************************************************
159 
160  //**Utility functions***************************************************************************
163  inline const IteratorType& base() const;
165  //**********************************************************************************************
166 
167  private:
168  //**Member variables****************************************************************************
172 
173  //**********************************************************************************************
174 };
175 //*************************************************************************************************
176 
177 
178 
179 
180 //=================================================================================================
181 //
182 // CONSTRUCTORS
183 //
184 //=================================================================================================
185 
186 //*************************************************************************************************
189 template< typename Type >
191  : it_(NULL) // Pointer to the current memory location
192 {}
193 //*************************************************************************************************
194 
195 
196 //*************************************************************************************************
201 template< typename Type >
203  : it_(it) // Pointer to the current memory location
204 {}
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
213 template< typename Type >
214 template< typename Other >
216  : it_( it.base() ) // Pointer to the current memory location
217 {}
218 //*************************************************************************************************
219 
220 
221 
222 
223 //=================================================================================================
224 //
225 // OPERATORS
226 //
227 //=================================================================================================
228 
229 //*************************************************************************************************
234 template< typename Type >
236 {
237  ++it_;
238  return *this;
239 }
240 //*************************************************************************************************
241 
242 
243 //*************************************************************************************************
248 template< typename Type >
250 {
251  PtrIterator tmp( *this );
252  ++it_;
253  return tmp;
254 }
255 //*************************************************************************************************
256 
257 
258 //*************************************************************************************************
263 template< typename Type >
265 {
266  --it_;
267  return *this;
268 }
269 //*************************************************************************************************
270 
271 
272 //*************************************************************************************************
277 template< typename Type >
279 {
280  PtrIterator tmp( *this );
281  --it_;
282  return tmp;
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
293 template< typename Type >
295 {
296  it_ += n;
297  return *this;
298 }
299 //*************************************************************************************************
300 
301 
302 //*************************************************************************************************
308 template< typename Type >
310 {
311  return PtrIterator( it_ + n );
312 }
313 //*************************************************************************************************
314 
315 
316 //*************************************************************************************************
322 template< typename Type >
324 {
325  it_ -= n;
326  return *this;
327 }
328 //*************************************************************************************************
329 
330 
331 //*************************************************************************************************
337 template< typename Type >
339 {
340  return PtrIterator( it_ - n );
341 }
342 //*************************************************************************************************
343 
344 
345 //*************************************************************************************************
351 template< typename Type >
353 {
354  return it_ - it.it_;
355 }
356 //*************************************************************************************************
357 
358 
359 
360 
361 //=================================================================================================
362 //
363 // ACCESS OPERATORS
364 //
365 //=================================================================================================
366 
367 //*************************************************************************************************
373 template< typename Type >
375 {
376  return it_[index];
377 }
378 //*************************************************************************************************
379 
380 
381 //*************************************************************************************************
386 template< typename Type >
388 {
389  return *it_;
390 }
391 //*************************************************************************************************
392 
393 
394 //*************************************************************************************************
399 template< typename Type >
401 {
402  return *it_;
403 }
404 //*************************************************************************************************
405 
406 
407 
408 
409 //=================================================================================================
410 //
411 // UTILITY FUNCTIONS
412 //
413 //=================================================================================================
414 
415 //*************************************************************************************************
420 template< typename Type >
422 {
423  return it_;
424 }
425 //*************************************************************************************************
426 
427 
428 
429 
430 //=================================================================================================
431 //
432 // GLOBAL OPERATORS
433 //
434 //=================================================================================================
435 
436 //*************************************************************************************************
439 template< typename TypeL, typename TypeR >
440 inline bool operator==( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
441 
442 template< typename TypeL, typename TypeR >
443 inline bool operator!=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
444 
445 template< typename TypeL, typename TypeR >
446 inline bool operator<( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
447 
448 template< typename TypeL, typename TypeR >
449 inline bool operator>( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
450 
451 template< typename TypeL, typename TypeR >
452 inline bool operator<=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
453 
454 template< typename TypeL, typename TypeR >
455 inline bool operator>=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
457 //*************************************************************************************************
458 
459 
460 //*************************************************************************************************
467 template< typename TypeL, typename TypeR >
468 inline bool operator==( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
469 {
470  return lhs.base() == rhs.base();
471 }
472 //*************************************************************************************************
473 
474 
475 //*************************************************************************************************
482 template< typename TypeL, typename TypeR >
483 inline bool operator!=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
484 {
485  return lhs.base() != rhs.base();
486 }
487 //*************************************************************************************************
488 
489 
490 //*************************************************************************************************
497 template< typename TypeL, typename TypeR >
498 inline bool operator<( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
499 {
500  return lhs.base() < rhs.base();
501 }
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
512 template< typename TypeL, typename TypeR >
513 inline bool operator>( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
514 {
515  return lhs.base() > rhs.base();
516 }
517 //*************************************************************************************************
518 
519 
520 //*************************************************************************************************
527 template< typename TypeL, typename TypeR >
528 inline bool operator<=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
529 {
530  return lhs.base() <= rhs.base();
531 }
532 //*************************************************************************************************
533 
534 
535 //*************************************************************************************************
542 template< typename TypeL, typename TypeR >
543 inline bool operator>=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
544 {
545  return lhs.base() >= rhs.base();
546 }
547 //*************************************************************************************************
548 
549 } // namespace blaze
550 
551 #endif