ModErn Text Analysis
META Enumerates Textual Applications
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
include
util
range.h
Go to the documentation of this file.
1
10
#ifndef META_UTIL_RANGE_H_
11
#define META_UTIL_RANGE_H_
12
13
#include <cmath>
14
#include <iterator>
15
16
namespace
meta
17
{
18
namespace
util
19
{
20
26
template
<
class
T>
27
class
basic_range
28
{
29
public
:
33
template
<
class
Plus>
34
class
iterator_t
35
{
36
public
:
38
using
self_type
=
iterator_t
;
40
using
value_type
= T;
42
using
reference
=
const
T&;
44
using
pointer
=
const
T*;
46
using
iterator_category
= std::forward_iterator_tag;
48
using
difference_type
= std::ptrdiff_t;
49
50
friend
class
basic_range
<T>;
51
56
self_type
&
operator++
()
57
{
58
_curr
=
_plus
(
_curr
,
_range
->_step);
59
++
_idx
;
60
return
*
this
;
61
}
62
67
self_type
operator++
(
int
)
68
{
69
self_type
temp = *
this
;
70
++(*this);
71
return
temp;
72
}
73
78
reference
operator*
()
79
{
80
return
_curr
;
81
}
82
87
pointer
operator->
()
88
{
89
return
&
_curr
;
90
}
91
98
friend
bool
operator==
(
const
iterator_t
& lhs,
const
iterator_t
& rhs)
99
{
100
return
lhs.
_range
== rhs.
_range
&& lhs.
_idx
== rhs.
_idx
;
101
}
102
110
friend
bool
operator!=
(
const
iterator_t
& lhs,
const
iterator_t
& rhs)
111
{
112
return
!(lhs == rhs);
113
}
114
115
private
:
123
iterator_t
(
const
basic_range<T>
*
range
,
const
T& start,
size_t
idx)
124
:
_curr
(start),
_idx
(idx),
_range
(range)
125
{
126
// nothing
127
}
128
130
T
_curr
;
132
size_t
_idx
;
134
Plus
_plus
;
136
const
basic_range<T>
*
_range
;
137
};
138
140
using
iterator
=
iterator_t<std::plus<T>
>;
142
using
const_iterator
=
iterator
;
143
145
using
reverse_iterator
=
iterator_t<std::minus<T>
>;
147
using
const_reverse_iterator
=
reverse_iterator
;
148
149
friend
iterator
;
150
friend
reverse_iterator
;
151
155
iterator
begin
()
const
156
{
157
return
iterator
(
this
,
_begin
, 0);
158
}
159
163
iterator
end
()
const
164
{
165
return
iterator
(
this
,
_end
,
_num
);
166
}
167
171
reverse_iterator
rbegin
()
const
172
{
173
return
reverse_iterator
(
this
,
_end
, 0);
174
}
175
179
reverse_iterator
rend
()
const
180
{
181
return
reverse_iterator
(
this
,
_begin
,
_num
);
182
}
183
191
basic_range
(
const
T&
begin
,
const
T&
end
,
const
T& step)
192
:
_begin
(begin),
_end
(end),
_num
((end - begin) / step + 1),
_step
(step)
193
{
194
// nothing
195
}
196
197
basic_range
(
const
basic_range
&) =
default
;
198
basic_range
(
basic_range
&&) =
default
;
199
basic_range
& operator=(
const
basic_range
&) =
default
;
200
basic_range
& operator=(
basic_range
&&) =
default
;
201
205
~basic_range
() =
default
;
206
207
private
:
209
T
_begin
;
211
T
_end
;
213
size_t
_num
;
215
T
_step
;
216
};
217
224
template
<
class
T>
225
basic_range<T>
range
(
const
T& begin,
const
T& end)
226
{
227
return
basic_range<T>
(begin, end, T{1});
228
}
229
239
template
<
class
T>
240
basic_range<T>
range
(
const
T& begin,
const
T& end,
const
T& step)
241
{
242
return
basic_range<T>
(begin, end, step);
243
}
244
}
245
}
246
247
#endif
meta::util::basic_range::iterator_t::operator++
self_type operator++(int)
Postfix increment.
Definition:
range.h:67
meta::util::basic_range::_begin
T _begin
the beginning value for the range
Definition:
range.h:209
meta::util::basic_range::rend
reverse_iterator rend() const
Definition:
range.h:179
meta::util::basic_range::iterator_t::_curr
T _curr
the current value
Definition:
range.h:130
meta::util::basic_range::iterator_t::_plus
Plus _plus
the functor to be used for incrementing the current value
Definition:
range.h:134
meta::util::basic_range::begin
iterator begin() const
Definition:
range.h:155
meta::util::basic_range::_num
size_t _num
the number of values contained in the range
Definition:
range.h:213
meta::util::basic_range::basic_range
basic_range(const T &begin, const T &end, const T &step)
Constructs a range.
Definition:
range.h:191
meta::util::basic_range::iterator_t::_range
const basic_range< T > * _range
a back-pointer to the range this iterator is operating over
Definition:
range.h:136
meta::util::basic_range::iterator
iterator_t< std::plus< T >> iterator
the iterator for the range class
Definition:
range.h:140
meta::util::basic_range::iterator_t::operator->
pointer operator->()
Member access operator.
Definition:
range.h:87
meta::util::basic_range::iterator_t::operator*
reference operator*()
Dereference operator.
Definition:
range.h:78
meta::util::range
basic_range< T > range(const T &begin, const T &end)
Constructs a range based on a beginning and ending value.
Definition:
range.h:225
meta::util::basic_range::iterator_t::difference_type
std::ptrdiff_t difference_type
the difference type for this iterator
Definition:
range.h:48
meta::util::basic_range::~basic_range
~basic_range()=default
Defaulted destructor.
meta::util::basic_range::iterator_t::operator!=
friend bool operator!=(const iterator_t &lhs, const iterator_t &rhs)
Inequality operator.
Definition:
range.h:110
meta::util::basic_range::iterator_t::iterator_t
iterator_t(const basic_range< T > *range, const T &start, size_t idx)
Constructs a new iterator.
Definition:
range.h:123
meta
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition:
analyzer.h:24
meta::util::basic_range::iterator_t::reference
const T & reference
a reference to the contained type
Definition:
range.h:42
meta::util::basic_range::iterator_t::operator==
friend bool operator==(const iterator_t &lhs, const iterator_t &rhs)
Equality operator.
Definition:
range.h:98
meta::util::basic_range
Implements a range that spans a loop's extension and termination conditions, most useful for iteratin...
Definition:
range.h:27
meta::util::basic_range::rbegin
reverse_iterator rbegin() const
Definition:
range.h:171
meta::util::basic_range::iterator_t::_idx
size_t _idx
the current index into the ragne
Definition:
range.h:132
meta::util::basic_range::end
iterator end() const
Definition:
range.h:163
meta::util::basic_range::_step
T _step
the step size of the range
Definition:
range.h:215
meta::util::basic_range::_end
T _end
the ending value for the range
Definition:
range.h:211
meta::util::basic_range::iterator_t::iterator_category
std::forward_iterator_tag iterator_category
the category for this iterator
Definition:
range.h:46
meta::util::basic_range::iterator_t::operator++
self_type & operator++()
Prefix increment.
Definition:
range.h:56
meta::util::basic_range::iterator_t::value_type
T value_type
convenience typedef for the contained value of the range
Definition:
range.h:40
meta::util::basic_range::iterator_t::pointer
const T * pointer
a pointer to the contained type
Definition:
range.h:44
meta::util::basic_range::reverse_iterator
iterator_t< std::minus< T >> reverse_iterator
the reverse_iterator for the range class
Definition:
range.h:145
meta::util::basic_range::iterator_t
Iterator to traverse the generic range.
Definition:
range.h:34
Generated on Tue Mar 3 2015 23:20:16 for ModErn Text Analysis by
1.8.9.1