OpenWalnut  1.5.0dev
WIteratorRange.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WITERATORRANGE_H_
26 #define WITERATORRANGE_H_
27 
28 #include <utility>
29 
30 /**
31  * \class WIteratorRange
32  *
33  * \brief A range of iterators.
34  *
35  * Stores a begin and an end iterator to define a range for iteration.
36  *
37  * \tparam IteratorType The type of the iterators to store.
38  */
39 template< typename IteratorType >
41 {
42 public:
43  /**
44  * Construct a range from a begin and end iterator.
45  *
46  * \param begin The iterator to act as the begin iterator.
47  * \param end The iterator to act as the end iterator.
48  */
49  WIteratorRange( IteratorType const& begin, IteratorType const& end );
50 
51  /**
52  * Destructor.
53  */
55 
56  /**
57  * Copy constructor.
58  *
59  * \param range The range to copy from.
60  */
61  WIteratorRange( WIteratorRange const& range ); // NOLINT will be used implicitly
62 
63  /**
64  * Assignment.
65  *
66  * \param range The range to assign from.
67  * \return *this
68  */
69  WIteratorRange& operator=( WIteratorRange const& range );
70 
71  /**
72  * Returns the begin of the range.
73  *
74  * \return The begin iterator.
75  */
76  IteratorType const& begin() const;
77 
78  /**
79  * Returns the end of the range.
80  *
81  * \return The end iterator.
82  */
83  IteratorType const& end() const;
84 
85 private:
86  /**
87  * The standard constructor is not allowed.
88  */
90 
91  //! The begin of the range.
92  IteratorType m_begin;
93 
94  //! The end of the range.
95  IteratorType m_end;
96 };
97 
98 template< typename IteratorType >
99 WIteratorRange< IteratorType >::WIteratorRange( IteratorType const& begin, IteratorType const& end )
100  : m_begin( begin ),
101  m_end( end )
102 {
103 }
104 
105 template< typename IteratorType >
107 {
108 }
109 
110 template< typename IteratorType >
112  : m_begin( range.m_begin ),
113  m_end( range.m_end )
114 {
115 }
116 
117 template< typename IteratorType >
119 {
120  if( this == &range )
121  return *this;
122 
123  m_begin = range.m_begin;
124  m_end = range.m_end;
125 
126  return *this;
127 }
128 
129 template< typename IteratorType >
130 IteratorType const& WIteratorRange< IteratorType >::begin() const
131 {
132  return m_begin;
133 }
134 
135 template< typename IteratorType >
136 IteratorType const& WIteratorRange< IteratorType >::end() const
137 {
138  return m_end;
139 }
140 
141 /**
142  * \class WIteratorRangeUnpacker
143  *
144  * \brief A temporary used to unpack an iterator range into two iterators.
145  *
146  * \tparam IteratorType THe type of the iterators used.
147  */
148 template< typename IteratorType >
150 {
151 public:
152  /**
153  * Constructs the unpacker.
154  *
155  * \param begin A reference to the iterator to unpack the begin iterator into.
156  * \param end A reference to the iterator to unpack the end iterator into.
157  */
158  WIteratorRangeUnpacker( IteratorType& begin, IteratorType& end ); // NOLINT non-const intended
159 
160  /**
161  * Destructor.
162  */
164 
165  /**
166  * Unpacks the provided range into the iterators referenced by this object.
167  * The lack of a return type is intended.
168  *
169  * \param range The renge to unpack.
170  */
171  void operator=( WIteratorRange< IteratorType > const& range );
172 
173  /// @cond Supress doxygen because it produces warning here becuase it does not correctly understand the C++ code.
174  /**
175  * Copy constructor.
176  */
177  WIteratorRangeUnpacker( WIteratorRangeUnpacker const& ); // NOLINT used implicitly
178  /// @endcond
179 
180 private:
181  /**
182  * Assignment is not allowed.
183  *
184  * \return Not used.
185  */
187 
188  //! A reference to the iterator that will be assigned the beginning of the range.
189  IteratorType& m_begin;
190 
191  //! A reference to the iterator that will be assigned the end of the range.
192  IteratorType& m_end;
193 };
194 
195 template< typename IteratorType >
196 WIteratorRangeUnpacker< IteratorType >::WIteratorRangeUnpacker( IteratorType& begin, IteratorType& end ) // NOLINT non-const intended
197  : m_begin( begin ),
198  m_end( end )
199 {
200 }
201 
202 template< typename IteratorType >
204 {
205 }
206 
207 template< typename IteratorType >
209  : m_begin( other.m_begin ),
210  m_end( other.m_end )
211 {
212 }
213 
214 template< typename IteratorType >
216 {
217  m_begin = range.begin();
218  m_end = range.end();
219 }
220 
221 #endif // WITERATORRANGE_H_
A temporary used to unpack an iterator range into two iterators.
IteratorType & m_begin
A reference to the iterator that will be assigned the beginning of the range.
WIteratorRangeUnpacker(IteratorType &begin, IteratorType &end)
Constructs the unpacker.
WIteratorRangeUnpacker & operator=(WIteratorRangeUnpacker const &)
Assignment is not allowed.
void operator=(WIteratorRange< IteratorType > const &range)
Unpacks the provided range into the iterators referenced by this object.
~WIteratorRangeUnpacker()
Destructor.
IteratorType & m_end
A reference to the iterator that will be assigned the end of the range.
A range of iterators.
WIteratorRange()
The standard constructor is not allowed.
IteratorType m_end
The end of the range.
~WIteratorRange()
Destructor.
IteratorType const & end() const
Returns the end of the range.
IteratorType m_begin
The begin of the range.
WIteratorRange & operator=(WIteratorRange const &range)
Assignment.
IteratorType const & begin() const
Returns the begin of the range.