Generated on Fri Jan 10 2020 11:38:25 for Gecode by doxygen 1.8.16
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;
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  ValueListIter(void);
77  void init(Region& r);
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 
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 
void init(Region &r)
Initialize.
~ValueListIter(void)
Destructor.
void reset(void)
Reset iterator to start.
A & allocator(void)
Return allocator used.
Manage memory organized into block lists (allocator)
Value list class.
Definition: values-list.hpp:44
ValueList * next
Next element.
Definition: values-list.hpp:49
unsigned int use_cnt
Counter used for reference counting.
Definition: values-list.hpp:55
Client for block allocator of type T.
int val(void) const
Return value.
Gecode toplevel namespace
Iterator over value lists.
Definition: values-list.hpp:41
Handle to region.
Definition: region.hpp:55
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
ValueListIter(void)
Default constructor.
ValueList * c
Current list element.
Definition: values-list.hpp:64
VLIO * vlio
Reference to shared object.
Definition: values-list.hpp:60
int val
Value.
Definition: values-list.hpp:47
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
void operator++(void)
Move iterator to next value (if possible)
#define forceinline
Definition: config.hpp:185
VLIO(Region &r)
Initialize.
ValueListIter & operator=(const ValueListIter &i)
Assignment operator (both iterators must be allocated from the same region)
Gecode::FloatVal c(-8, 8)
Shared object for allocation.
Definition: values-list.hpp:52
ValueList * h
Head of value list.
Definition: values-list.hpp:62
Gecode::IntArgs i({1, 2, 3, 4})
void set(ValueList *l)
Set value lists.
bool operator()(void) const
Test whether iterator is still at a value or done.