Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JForwardIterator.hh
Go to the documentation of this file.
1#ifndef __JLANG__JFORWARDITERATOR__
2#define __JLANG__JFORWARDITERATOR__
3
4#include <cstddef>
5
6/**
7 * \author mdejong
8 */
9
10namespace JLANG {}
11namespace JPP { using namespace JLANG; }
12
13namespace JLANG {
14
15 /**
16 * Template interface for method bool increment().
17 * This interface implements the pre-fix and post-fix operators <tt>++</tt>.
18 */
19 template<class T>
21 public:
22 /**
23 * Virtual destructor.
24 */
26 {}
27
28
29 /**
30 * Increment iterator.
31 *
32 * \return this iterator
33 */
35 {
36 this->increment();
37
38 return static_cast<T&>(*this);
39 }
40
41
42 /**
43 * Increment iterator.
44 *
45 * \return previous iterator
46 */
48 {
49 const T tmp(static_cast<const T&>(*this));
50
51 this->increment();
52
53 return tmp;
54 }
55
56
57 /**
58 * Advance iterator.
59 *
60 * \param offset offset
61 * \return iterator
62 */
63 T& operator+=(const size_t offset)
64 {
65 this->increment(offset);
66
67 return static_cast<T&>(*this);
68 }
69
70
71 /**
72 * Advance operator.
73 *
74 * \param object iterator
75 * \param offset offset
76 * \return iterator
77 */
78 friend inline T operator+(const T& object, const size_t offset)
79 {
80 T tmp(object);
81
82 tmp.increment(offset);
83
84 return tmp;
85 }
86
87
88 /**
89 * Increment iterator.
90 *
91 * \return true if incremented; else false
92 */
93 virtual bool increment() = 0;
94
95
96 /**
97 * Increment iterator.
98 *
99 * \param offset offset
100 * \return true if incremented; else false
101 */
102 virtual bool increment(const size_t offset)
103 {
104 size_t i = 0;
105
106 while (i != offset && this->increment()) {
107 ++i;
108 }
109
110 return i == offset;
111 }
112 };
113}
114
115#endif
116
Template interface for method bool increment().
virtual bool increment(const size_t offset)
Increment iterator.
virtual ~JForwardIterator()
Virtual destructor.
T & operator+=(const size_t offset)
Advance iterator.
virtual bool increment()=0
Increment iterator.
friend T operator+(const T &object, const size_t offset)
Advance operator.
T operator++(int)
Increment iterator.
T & operator++()
Increment iterator.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).