main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
gecode
iter
values-list.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, 2010
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
Values {
35
41
class
ValueListIter
{
42
protected
:
44
class
ValueList
:
public
Support::BlockClient
<ValueList,Region> {
45
public
:
47
int
val
;
49
ValueList
*
next
;
50
};
52
class
VLIO
:
public
Support::BlockAllocator
<ValueList,Region> {
53
public
:
55
unsigned
int
use_cnt
;
57
VLIO
(
Region
&
r
);
58
};
60
VLIO
*
vlio
;
62
ValueList
*
h
;
64
ValueList
*
c
;
66
void
set
(
ValueList
*
l
);
67
public
:
69
70
ValueListIter
(
void
);
73
ValueListIter
(
const
ValueListIter
&
i
);
75
ValueListIter
(
Region
&
r
);
77
void
init
(
Region
&
r
);
79
ValueListIter
&
operator =
(
const
ValueListIter
&
i
);
81
83
84
bool
operator ()
(
void
)
const
;
87
void
operator ++
(
void
);
89
void
reset
(
void
);
91
93
94
int
val
(
void
)
const
;
97
99
~ValueListIter
(
void
);
100
};
101
102
103
forceinline
104
ValueListIter::VLIO::VLIO
(
Region
&
r
)
105
: Support::BlockAllocator<
ValueList
,
Region
>(
r
), use_cnt(1) {}
106
107
108
forceinline
109
ValueListIter::ValueListIter
(
void
)
110
:
vlio
(NULL) {}
111
112
forceinline
113
ValueListIter::ValueListIter
(
Region
&
r
)
114
: vlio(new (
r
.ralloc(sizeof(
VLIO
)))
VLIO
(
r
)),
115
h(NULL),
c
(NULL) {}
116
117
forceinline
void
118
ValueListIter::init
(
Region
&
r
) {
119
vlio
=
new
(
r
.ralloc(
sizeof
(
VLIO
)))
VLIO
(
r
);
120
h
=
c
= NULL;
121
}
122
123
forceinline
124
ValueListIter::ValueListIter
(
const
ValueListIter
&
i
)
125
: vlio(
i
.vlio), h(
i
.h),
c
(
i
.
c
) {
126
vlio
->
use_cnt
++;
127
}
128
129
forceinline
ValueListIter
&
130
ValueListIter::operator =
(
const
ValueListIter
&
i
) {
131
if
(&
i
!=
this
) {
132
if
(--
vlio
->
use_cnt
== 0) {
133
Region
&
r
=
vlio
->
allocator
();
134
vlio
->~VLIO();
135
r
.rfree(
vlio
,
sizeof
(
VLIO
));
136
}
137
vlio
=
i
.vlio;
138
vlio
->
use_cnt
++;
139
c
=
i
.c;
h
=
i
.h;
140
}
141
return
*
this
;
142
}
143
144
forceinline
145
ValueListIter::~ValueListIter
(
void
) {
146
if
(--
vlio
->
use_cnt
== 0) {
147
Region
&
r
=
vlio
->
allocator
();
148
vlio
->~VLIO();
149
r
.rfree(
vlio
,
sizeof
(
VLIO
));
150
}
151
}
152
153
154
forceinline
void
155
ValueListIter::set
(
ValueList
*
l
) {
156
h
=
c
=
l
;
157
}
158
159
forceinline
bool
160
ValueListIter::operator ()
(
void
)
const
{
161
return
c
!= NULL;
162
}
163
164
forceinline
void
165
ValueListIter::operator ++
(
void
) {
166
c
=
c
->
next
;
167
}
168
169
forceinline
void
170
ValueListIter::reset
(
void
) {
171
c
=
h
;
172
}
173
174
forceinline
int
175
ValueListIter::val
(
void
)
const
{
176
return
c
->
val
;
177
}
178
179
}}}
180
181
// STATISTICS: iter-any
182
Gecode::Iter::Values::ValueListIter::init
void init(Region &r)
Initialize.
Definition:
values-list.hpp:118
Gecode::Iter::Values::ValueListIter::~ValueListIter
~ValueListIter(void)
Destructor.
Definition:
values-list.hpp:145
Gecode::Iter::Values::ValueListIter::reset
void reset(void)
Reset iterator to start.
Definition:
values-list.hpp:170
Gecode::Support::BlockAllocator::allocator
A & allocator(void)
Return allocator used.
Definition:
block-allocator.hpp:116
Gecode::Support::BlockAllocator
Manage memory organized into block lists (allocator)
Definition:
block-allocator.hpp:45
Gecode::Iter::Values::ValueListIter::ValueList
Value list class.
Definition:
values-list.hpp:44
Gecode::Iter::Values::ValueListIter::ValueList::next
ValueList * next
Next element.
Definition:
values-list.hpp:49
Gecode::Iter::Values::ValueListIter::VLIO::use_cnt
unsigned int use_cnt
Counter used for reference counting.
Definition:
values-list.hpp:55
Gecode::Support::BlockClient
Client for block allocator of type T.
Definition:
block-allocator.hpp:84
Gecode::Iter::Values::ValueListIter::val
int val(void) const
Return value.
Definition:
values-list.hpp:175
Gecode
Gecode toplevel namespace
Gecode::Iter::Values::ValueListIter
Iterator over value lists.
Definition:
values-list.hpp:41
Gecode::Region
Handle to region.
Definition:
region.hpp:55
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::Iter::Values::ValueListIter::ValueListIter
ValueListIter(void)
Default constructor.
Definition:
values-list.hpp:109
Gecode::Iter::Values::ValueListIter::c
ValueList * c
Current list element.
Definition:
values-list.hpp:64
Gecode::Iter::Values::ValueListIter::vlio
VLIO * vlio
Reference to shared object.
Definition:
values-list.hpp:60
Gecode::Iter::Values::ValueListIter::ValueList::val
int val
Value.
Definition:
values-list.hpp:47
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:240
Gecode::Iter::Values::ValueListIter::operator++
void operator++(void)
Move iterator to next value (if possible)
Definition:
values-list.hpp:165
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Iter::Values::ValueListIter::VLIO::VLIO
VLIO(Region &r)
Initialize.
Definition:
values-list.hpp:104
Gecode::Iter::Values::ValueListIter::operator=
ValueListIter & operator=(const ValueListIter &i)
Assignment operator (both iterators must be allocated from the same region)
Definition:
values-list.hpp:130
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::Iter::Values::ValueListIter::VLIO
Shared object for allocation.
Definition:
values-list.hpp:52
Gecode::Iter::Values::ValueListIter::h
ValueList * h
Head of value list.
Definition:
values-list.hpp:62
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Iter::Values::ValueListIter::set
void set(ValueList *l)
Set value lists.
Definition:
values-list.hpp:155
Gecode::Iter::Values::ValueListIter::operator()
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition:
values-list.hpp:160