main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Aug 27 2012 17:15:45 for Gecode by
doxygen
1.8.1.2
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
* Last modified:
10
* $Date: 2010-07-29 01:35:33 +1000 (Thu, 29 Jul 2010) $ by $Author: schulte $
11
* $Revision: 11294 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
namespace
Gecode {
namespace
Iter {
namespace
Ranges {
39
48
template
<
class
I,
class
M,
bool
strict=true>
49
class
Map
{
50
public
:
52
53
54
Map
(
void
);
56
Map
(I&
i
);
58
Map
(I& i,
const
M&
m
);
60
void
init
(I& i);
62
void
init
(I& i,
const
M& m);
64
66
67
68
bool
operator ()
(
void
)
const
;
70
void
operator ++
(
void
);
72
74
75
76
int
min
(
void
)
const
;
78
int
max
(
void
)
const
;
80
unsigned
int
width
(
void
)
const
;
82
};
83
85
template
<
class
I,
class
M>
86
class
Map
<I,M,false> :
public
MinMax
{
87
protected
:
89
I
i
;
91
M
m
;
93
void
next(
void
);
94
public
:
96
97
98
Map
(
void
);
100
Map
(I&
i
);
102
Map
(I&
i
,
const
M&
m
);
104
void
init
(I&
i
);
106
void
init
(I&
i
,
const
M&
m
);
108
110
111
112
void
operator ++
(
void
);
114
};
115
117
template
<
class
I,
class
M>
118
class
Map
<I,M,true> {
119
protected
:
121
I
i
;
123
M
m
;
124
public
:
126
127
128
Map
(
void
);
130
Map
(I&
i
);
132
Map
(I&
i
,
const
M&
m
);
134
void
init
(I&
i
);
136
void
init
(I&
i
,
const
M&
m
);
138
140
141
142
bool
operator ()
(
void
)
const
;
144
void
operator ++
(
void
);
146
148
149
150
int
min
(
void
)
const
;
152
int
max
(
void
)
const
;
154
unsigned
int
width
(
void
)
const
;
156
};
157
158
159
template
<
class
I,
class
M>
160
forceinline
161
Map<I,M,false>::Map
(
void
) {}
162
163
template
<
class
I,
class
M>
164
forceinline
void
165
Map<I,M,false>::next
(
void
) {
166
if
(
i
()) {
167
mi =
m
.min(
i
.min());
168
ma =
m
.max(
i
.max());
169
++
i
;
170
while
(
i
() && (ma+1 >=
m
.min(
i
.min()))) {
171
ma =
m
.max(
i
.max()); ++
i
;
172
}
173
}
else
{
174
finish();
175
}
176
}
177
178
template
<
class
I,
class
M>
179
forceinline
void
180
Map<I,M,false>::init
(I& i0) {
181
i
=i0; next();
182
}
183
template
<
class
I,
class
M>
184
forceinline
void
185
Map<I,M,false>::init
(I& i0,
const
M& m0) {
186
i
=i0;
m
=m0; next();
187
}
188
189
template
<
class
I,
class
M>
190
forceinline
191
Map<I,M,false>::Map
(I& i0) :
i
(i0) {
192
next();
193
}
194
template
<
class
I,
class
M>
195
forceinline
196
Map<I,M,false>::Map
(I& i0,
const
M& m0) :
i
(i0),
m
(m0) {
197
next();
198
}
199
200
template
<
class
I,
class
M>
201
forceinline
void
202
Map<I,M,false>::operator ++
(
void
) {
203
next();
204
}
205
206
207
208
template
<
class
I,
class
M>
209
forceinline
210
Map<I,M,true>::Map
(
void
) {}
211
212
template
<
class
I,
class
M>
213
forceinline
void
214
Map<I,M,true>::init
(I& i0) {
215
i
=i0;
216
}
217
template
<
class
I,
class
M>
218
forceinline
void
219
Map<I,M,true>::init
(I& i0,
const
M& m0) {
220
i
=i0;
m
=m0;
221
}
222
223
template
<
class
I,
class
M>
224
forceinline
225
Map<I,M,true>::Map
(I& i0) :
i
(i0) {}
226
template
<
class
I,
class
M>
227
forceinline
228
Map<I,M,true>::Map
(I& i0,
const
M& m0) :
i
(i0),
m
(m0) {}
229
230
template
<
class
I,
class
M>
231
forceinline
bool
232
Map<I,M,true>::operator ()
(
void
)
const
{
233
return
i
();
234
}
235
template
<
class
I,
class
M>
236
forceinline
void
237
Map<I,M,true>::operator ++
(
void
) {
238
++
i
;
239
}
240
241
template
<
class
I,
class
M>
242
forceinline
int
243
Map<I,M,true>::min
(
void
)
const
{
244
return
m
.min(
i
.min());
245
}
246
template
<
class
I,
class
M>
247
forceinline
int
248
Map<I,M,true>::max
(
void
)
const
{
249
return
m
.max(
i
.max());
250
}
251
template
<
class
I,
class
M>
252
forceinline
unsigned
int
253
Map<I,M,true>::width
(
void
)
const
{
254
return
static_cast<
unsigned
int
>
(
max
()-
min
())+1;
255
}
256
257
}}}
258
259
// STATISTICS: iter-any
260