Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
34namespace Gecode { namespace Iter { namespace Values {
35
42 protected:
44 class ValueList : public Support::BlockClient<ValueList,Region> {
45 public:
47 int val;
50 };
52 class VLIO : public Support::BlockAllocator<ValueList,Region> {
53 public:
55 unsigned int use_cnt;
57 VLIO(Region& r);
58 };
66 void set(ValueList* l);
67 public:
69
70
71 ValueListIter(void);
77 void init(Region& r);
81
83
84
85 bool operator ()(void) const;
87 void operator ++(void);
89 void reset(void);
91
93
94
95 int val(void) const;
97
99 ~ValueListIter(void);
100 };
101
102
105 : Support::BlockAllocator<ValueList,Region>(r), use_cnt(1) {}
106
107
110 : vlio(NULL) {}
111
114 : vlio(new (r.ralloc(sizeof(VLIO))) VLIO(r)),
115 h(NULL), c(NULL) {}
116
117 forceinline void
119 vlio = new (r.ralloc(sizeof(VLIO))) VLIO(r);
120 h = c = NULL;
121 }
122
125 : vlio(i.vlio), h(i.h), c(i.c) {
126 vlio->use_cnt++;
127 }
128
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
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
156 h = c = l;
157 }
158
159 forceinline bool
161 return c != NULL;
162 }
163
164 forceinline void
166 c = c->next;
167 }
168
169 forceinline 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
NNF * l
Left subtree.
Shared object for allocation.
unsigned int use_cnt
Counter used for reference counting.
Iterator over value lists.
ValueList * h
Head of value list.
ValueListIter(void)
Default constructor.
void reset(void)
Reset iterator to start.
void init(Region &r)
Initialize.
void set(ValueList *l)
Set value lists.
ValueListIter & operator=(const ValueListIter &i)
Assignment operator (both iterators must be allocated from the same region)
bool operator()(void) const
Test whether iterator is still at a value or done.
int val(void) const
Return value.
VLIO * vlio
Reference to shared object.
void operator++(void)
Move iterator to next value (if possible)
ValueList * c
Current list element.
Handle to region.
Definition region.hpp:55
Manage memory organized into block lists (allocator)
A & allocator(void)
Return allocator used.
Client for block allocator of type T.
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
#define forceinline
Definition config.hpp:187