main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 7 2013 10:21:37 for Gecode by
doxygen
1.8.3.1
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: 2010-07-29 01:58:23 +1000 (Thu, 29 Jul 2010) $ by $Author: tack $
11
* $Revision: 11296 $
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
75
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
89
bool
operator ()
(
void
)
const
;
91
void
operator ++
(
void
);
93
void
reset
(
void
);
95
97
98
99
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