main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
gecode
iter
ranges-map.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2008
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
namespace
Gecode
{
namespace
Iter {
namespace
Ranges {
35
44
template
<
class
I,
class
M,
bool
strict=true>
45
class
Map
{
46
public
:
48
49
Map
(
void
);
52
Map
(I&
i
);
54
Map
(I&
i
,
const
M& m);
56
void
init
(I&
i
);
58
void
init
(I&
i
,
const
M& m);
60
62
63
bool
operator ()
(
void
)
const
;
66
void
operator ++
(
void
);
68
70
71
int
min
(
void
)
const
;
74
int
max
(
void
)
const
;
76
unsigned
int
width
(
void
)
const
;
78
};
79
81
template
<
class
I,
class
M>
82
class
Map
<I,M,false> :
public
MinMax
{
83
protected
:
85
I
i
;
87
M
m
;
89
void
next(
void
);
90
public
:
92
93
Map
(
void
);
96
Map
(I&
i
);
98
Map
(I&
i
,
const
M& m);
100
void
init
(I&
i
);
102
void
init
(I&
i
,
const
M& m);
104
106
107
void
operator ++
(
void
);
110
};
111
113
template
<
class
I,
class
M>
114
class
Map
<I,M,true> {
115
protected
:
117
I
i
;
119
M
m
;
120
public
:
122
123
Map
(
void
);
126
Map
(I&
i
);
128
Map
(I&
i
,
const
M& m);
130
void
init
(I&
i
);
132
void
init
(I&
i
,
const
M& m);
134
136
137
bool
operator ()
(
void
)
const
;
140
void
operator ++
(
void
);
142
144
145
int
min
(
void
)
const
;
148
int
max
(
void
)
const
;
150
unsigned
int
width
(
void
)
const
;
152
};
153
154
155
template
<
class
I,
class
M>
156
forceinline
157
Map<I,M,false>::Map
(
void
) {}
158
159
template
<
class
I,
class
M>
160
forceinline
void
161
Map<I,M,false>::next
(
void
) {
162
if
(
i
()) {
163
mi = m.
min
(
i
.min());
164
ma = m.max(
i
.max());
165
++
i
;
166
while
(
i
() && (ma+1 >= m.min(
i
.min()))) {
167
ma = m.max(
i
.max()); ++
i
;
168
}
169
}
else
{
170
finish();
171
}
172
}
173
174
template
<
class
I,
class
M>
175
forceinline
void
176
Map<I,M,false>::init
(I& i0) {
177
i
=i0; next();
178
}
179
template
<
class
I,
class
M>
180
forceinline
void
181
Map<I,M,false>::init
(I& i0,
const
M& m0) {
182
i
=i0; m=m0; next();
183
}
184
185
template
<
class
I,
class
M>
186
forceinline
187
Map<I,M,false>::Map
(I& i0) :
i
(i0) {
188
next();
189
}
190
template
<
class
I,
class
M>
191
forceinline
192
Map<I,M,false>::Map
(I& i0,
const
M& m0) :
i
(i0), m(m0) {
193
next();
194
}
195
196
template
<
class
I,
class
M>
197
forceinline
void
198
Map<I,M,false>::operator ++
(
void
) {
199
next();
200
}
201
202
203
204
template
<
class
I,
class
M>
205
forceinline
206
Map<I,M,true>::Map
(
void
) {}
207
208
template
<
class
I,
class
M>
209
forceinline
void
210
Map<I,M,true>::init
(I& i0) {
211
i
=i0;
212
}
213
template
<
class
I,
class
M>
214
forceinline
void
215
Map<I,M,true>::init
(I& i0,
const
M& m0) {
216
i
=i0; m=m0;
217
}
218
219
template
<
class
I,
class
M>
220
forceinline
221
Map<I,M,true>::Map
(I& i0) :
i
(i0) {}
222
template
<
class
I,
class
M>
223
forceinline
224
Map<I,M,true>::Map
(I& i0,
const
M& m0) :
i
(i0), m(m0) {}
225
226
template
<
class
I,
class
M>
227
forceinline
bool
228
Map<I,M,true>::operator ()
(
void
)
const
{
229
return
i
();
230
}
231
template
<
class
I,
class
M>
232
forceinline
void
233
Map<I,M,true>::operator ++
(
void
) {
234
++
i
;
235
}
236
237
template
<
class
I,
class
M>
238
forceinline
int
239
Map<I,M,true>::min
(
void
)
const
{
240
return
m.min(
i
.min());
241
}
242
template
<
class
I,
class
M>
243
forceinline
int
244
Map<I,M,true>::max
(
void
)
const
{
245
return
m.max(
i
.max());
246
}
247
template
<
class
I,
class
M>
248
forceinline
unsigned
int
249
Map<I,M,true>::width
(
void
)
const
{
250
return
static_cast<unsigned int>(
max
()-
min
())+1;
251
}
252
253
}}}
254
255
// STATISTICS: iter-any
256
Gecode::Iter::Ranges::Map::width
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Gecode::Iter::Ranges::Map< I, M, false >::i
I i
Input range.
Definition:
ranges-map.hpp:85
Gecode::Iter::Ranges::Map< I, M, false >::m
M m
Map for ranges.
Definition:
ranges-map.hpp:87
Gecode::Iter::Ranges::Map::operator++
void operator++(void)
Move iterator to next range (if possible)
Gecode::Iter::Ranges::Map::min
int min(void) const
Return smallest value of range.
Gecode
Gecode toplevel namespace
Gecode::Iter::Ranges::MinMax
Base for range iterators with explicit min and max.
Definition:
ranges-minmax.hpp:47
Gecode::Iter::Ranges::Map
Range iterator for mapping ranges.
Definition:
ranges-map.hpp:45
Gecode::Iter::Ranges::Map::operator()
bool operator()(void) const
Test whether iterator is still at a range or done.
Gecode::Iter::Ranges::Map::init
void init(I &i)
Initialize with ranges from i.
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Iter::Ranges::Map::max
int max(void) const
Return largest value of range.
Gecode::Iter::Ranges::Map::Map
Map(void)
Default constructor.
Gecode::Iter::Ranges::Map< I, M, true >::i
I i
Input range iterator.
Definition:
ranges-map.hpp:117
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Iter::Ranges::Map< I, M, true >::m
M m
Map object.
Definition:
ranges-map.hpp:119