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-add.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, 2005
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
41
template
<
class
I>
42
class
AddRange
:
public
MinMax
{
43
protected
:
45
I
i
;
47
int
r_min
;
49
int
r_max
;
50
public
:
52
53
AddRange
(
void
);
56
AddRange
(I&
i
,
int
min
,
int
max
);
58
void
init
(I&
i
,
int
min
,
int
max
);
60
62
63
void
operator ++
(
void
);
66
};
67
68
74
template
<
class
I>
75
class
SubRange
:
public
AddRange
<I> {
76
public
:
78
79
SubRange
(
void
);
82
SubRange
(I&
i
,
int
min
,
int
max
);
84
void
init
(I&
i
,
int
min
,
int
max
);
86
};
87
88
template
<
class
I>
89
forceinline
90
AddRange<I>::AddRange
(
void
) {}
91
92
template
<
class
I>
93
forceinline
void
94
AddRange<I>::operator ++
(
void
) {
95
if
(
i
()) {
96
mi = r_min +
i
.min();
97
ma = r_max +
i
.max();
98
++
i
;
99
while
(
i
() && (ma+1 >= r_min+
i
.min())) {
100
ma = r_max +
i
.max(); ++
i
;
101
}
102
}
else
{
103
finish();
104
}
105
}
106
107
template
<
class
I>
108
forceinline
109
AddRange<I>::AddRange
(I& i0,
int
r_min0,
int
r_max0)
110
:
i
(i0), r_min(r_min0), r_max(r_max0) {
111
operator ++
();
112
}
113
114
template
<
class
I>
115
forceinline
void
116
AddRange<I>::init
(I& i0,
int
r_min0,
int
r_max0) {
117
i
= i0; r_min = r_min0; r_max = r_max0;
118
operator ++();
119
}
120
121
122
template
<
class
I>
123
forceinline
124
SubRange<I>::SubRange
(
void
) {}
125
126
template
<
class
I>
127
forceinline
128
SubRange<I>::SubRange
(I&
i
,
int
r_min,
int
r_max)
129
:
AddRange
<I>(
i
,-r_max,-r_min) {}
130
131
template
<
class
I>
132
forceinline
void
133
SubRange<I>::init
(I&
i
,
int
r_min,
int
r_max) {
134
AddRange<I>::init
(
i
,-r_max,-r_min);
135
}
136
137
}}}
138
139
// STATISTICS: iter-any
140
Gecode::Iter::Ranges::SubRange::init
void init(I &i, int min, int max)
Initialize with ranges i and range min to max.
Definition:
ranges-add.hpp:133
Gecode::Iter::Ranges::AddRange
Range iterator for adding a single range to a range iterator.
Definition:
ranges-add.hpp:42
Gecode::Iter::Ranges::AddRange::r_max
int r_max
Maximum of range to be added.
Definition:
ranges-add.hpp:49
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::MinMax::min
int min(void) const
Return smallest value of range.
Definition:
ranges-minmax.hpp:99
Gecode::Iter::Ranges::SubRange
Range iterator for subtracting a single range from a range iterator.
Definition:
ranges-add.hpp:75
Gecode::Iter::Ranges::AddRange::r_min
int r_min
Minimum of range to be added.
Definition:
ranges-add.hpp:47
Gecode::Iter::Ranges::AddRange::init
void init(I &i, int min, int max)
Initialize with ranges i and range min to max.
Definition:
ranges-add.hpp:116
Gecode::Iter::Ranges::MinMax::max
int max(void) const
Return largest value of range.
Definition:
ranges-minmax.hpp:103
Gecode::Iter::Ranges::AddRange::i
I i
Iterator to which the range is to be added.
Definition:
ranges-add.hpp:45
Gecode::Iter::Ranges::AddRange::AddRange
AddRange(void)
Default constructor.
Definition:
ranges-add.hpp:90
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Iter::Ranges::AddRange::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-add.hpp:94
Gecode::Iter::Ranges::SubRange::SubRange
SubRange(void)
Default constructor.
Definition:
ranges-add.hpp:124
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})