main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 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
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
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
Values {
39
45
class
ValueListIter
{
46
protected
:
48
class
ValueList
:
public
Support::BlockClient
<ValueList,Region> {
49
public
:
51
int
val
;
53
ValueList
*
next
;
54
};
56
class
VLIO
:
public
Support::BlockAllocator
<ValueList,Region> {
57
public
:
59
unsigned
int
use_cnt
;
61
VLIO
(
Region
&
r
);
62
};
64
VLIO
*
vlio
;
66
ValueList
*
h
;
68
ValueList
*
c
;
70
void
set
(
ValueList
*
l
);
71
public
:
73
74
ValueListIter
(
void
);
77
ValueListIter
(
const
ValueListIter
&
i
);
79
ValueListIter
(
Region
&
r
);
81
void
init
(
Region
&
r
);
83
ValueListIter
&
operator =
(
const
ValueListIter
&
i
);
85
87
88
bool
operator ()
(
void
)
const
;
91
void
operator ++
(
void
);
93
void
reset
(
void
);
95
97
98
int
val
(
void
)
const
;
101
103
~ValueListIter
(
void
);
104
};
105
106
107
forceinline
108
ValueListIter::VLIO::VLIO
(
Region
&
r
)
109
: Support::BlockAllocator<
ValueList
,
Region
>(
r
), use_cnt(1) {}
110
111
112
forceinline
113
ValueListIter::ValueListIter
(
void
)
114
:
vlio
(NULL) {}
115
116
forceinline
117
ValueListIter::ValueListIter
(
Region
&
r
)
118
: vlio(new (
r
.ralloc(sizeof(
VLIO
)))
VLIO
(
r
)),
119
h(NULL),
c
(NULL) {}
120
121
forceinline
void
122
ValueListIter::init
(
Region
&
r
) {
123
vlio
=
new
(
r
.ralloc(
sizeof
(
VLIO
)))
VLIO
(
r
);
124
h
=
c
= NULL;
125
}
126
127
forceinline
128
ValueListIter::ValueListIter
(
const
ValueListIter
&
i
)
129
: vlio(
i
.vlio), h(
i
.h),
c
(
i
.
c
) {
130
vlio
->
use_cnt
++;
131
}
132
133
forceinline
ValueListIter
&
134
ValueListIter::operator =
(
const
ValueListIter
&
i
) {
135
if
(&
i
!=
this
) {
136
if
(--
vlio
->
use_cnt
== 0) {
137
Region
&
r
=
vlio
->
allocator
();
138
vlio
->~VLIO();
139
r
.rfree(
vlio
,
sizeof
(
VLIO
));
140
}
141
vlio
=
i
.vlio;
142
vlio
->
use_cnt
++;
143
c
=
i
.c;
h
=
i
.h;
144
}
145
return
*
this
;
146
}
147
148
forceinline
149
ValueListIter::~ValueListIter
(
void
) {
150
if
(--
vlio
->
use_cnt
== 0) {
151
Region
&
r
=
vlio
->
allocator
();
152
vlio
->~VLIO();
153
r
.rfree(
vlio
,
sizeof
(
VLIO
));
154
}
155
}
156
157
158
forceinline
void
159
ValueListIter::set
(
ValueList
*
l
) {
160
h
=
c
=
l
;
161
}
162
163
forceinline
bool
164
ValueListIter::operator ()
(
void
)
const
{
165
return
c
!= NULL;
166
}
167
168
forceinline
void
169
ValueListIter::operator ++
(
void
) {
170
c
=
c
->
next
;
171
}
172
173
forceinline
void
174
ValueListIter::reset
(
void
) {
175
c
=
h
;
176
}
177
178
forceinline
int
179
ValueListIter::val
(
void
)
const
{
180
return
c
->
val
;
181
}
182
183
}}}
184
185
// STATISTICS: iter-any
186
Gecode::Iter::Values::ValueListIter::init
void init(Region &r)
Initialize.
Definition:
values-list.hpp:122
Gecode::Iter::Values::ValueListIter::~ValueListIter
~ValueListIter(void)
Destructor.
Definition:
values-list.hpp:149
Gecode::Iter::Values::ValueListIter::reset
void reset(void)
Reset iterator to start.
Definition:
values-list.hpp:174
Gecode::Support::BlockAllocator::allocator
A & allocator(void)
Return allocator used.
Definition:
block-allocator.hpp:120
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Support::BlockAllocator
Manage memory organized into block lists (allocator)
Definition:
block-allocator.hpp:49
Gecode::Iter::Values::ValueListIter::ValueList
Value list class.
Definition:
values-list.hpp:48
Gecode::Iter::Values::ValueListIter::ValueList::next
ValueList * next
Next element.
Definition:
values-list.hpp:53
Gecode::Iter::Values::ValueListIter::VLIO::use_cnt
unsigned int use_cnt
Counter used for reference counting.
Definition:
values-list.hpp:59
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Support::BlockClient
Client for block allocator of type T.
Definition:
block-allocator.hpp:88
Gecode::Iter::Values::ValueListIter::val
int val(void) const
Return value.
Definition:
values-list.hpp:179
Gecode
Gecode toplevel namespace
Gecode::Iter::Values::ValueListIter
Iterator over value lists.
Definition:
values-list.hpp:45
Gecode::Region
Handle to region.
Definition:
region.hpp:61
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::Iter::Values::ValueListIter::ValueListIter
ValueListIter(void)
Default constructor.
Definition:
values-list.hpp:113
Gecode::Iter::Values::ValueListIter::c
ValueList * c
Current list element.
Definition:
values-list.hpp:68
Gecode::Iter::Values::ValueListIter::vlio
VLIO * vlio
Reference to shared object.
Definition:
values-list.hpp:64
Gecode::Iter::Values::ValueListIter::ValueList::val
int val
Value.
Definition:
values-list.hpp:51
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:244
Gecode::Iter::Values::ValueListIter::operator++
void operator++(void)
Move iterator to next value (if possible)
Definition:
values-list.hpp:169
Gecode::Iter::Values::ValueListIter::VLIO::VLIO
VLIO(Region &r)
Initialize.
Definition:
values-list.hpp:108
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:134
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::Iter::Values::ValueListIter::VLIO
Shared object for allocation.
Definition:
values-list.hpp:56
Gecode::Iter::Values::ValueListIter::h
ValueList * h
Head of value list.
Definition:
values-list.hpp:66
Gecode::Iter::Values::ValueListIter::set
void set(ValueList *l)
Set value lists.
Definition:
values-list.hpp:159
Gecode::Iter::Values::ValueListIter::operator()
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition:
values-list.hpp:164