Generated on Sat Feb 7 2015 02:01:27 for Gecode by doxygen 1.8.9.1
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: 2012-09-07 17:42:21 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13069 $
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;
54  };
56  class VLIO : public Support::BlockAllocator<ValueList,Region> {
57  public:
59  unsigned int use_cnt;
61  VLIO(Region& r);
62  };
70  void set(ValueList* l);
71  public:
73 
74  ValueListIter(void);
81  void init(Region& r);
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 
109  : Support::BlockAllocator<ValueList,Region>(r), use_cnt(1) {}
110 
111 
114  : vlio(NULL) {}
115 
118  : vlio(new (r.ralloc(sizeof(VLIO))) VLIO(r)),
119  h(NULL), c(NULL) {}
120 
121  forceinline void
123  vlio = new (r.ralloc(sizeof(VLIO))) VLIO(r);
124  h = c = NULL;
125  }
126 
129  : vlio(i.vlio), h(i.h), c(i.c) {
130  vlio->use_cnt++;
131  }
132 
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 
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
160  h = c = l;
161  }
162 
163  forceinline bool
165  return c != NULL;
166  }
167 
168  forceinline void
170  c = c->next;
171  }
172 
173  forceinline 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 
void rfree(void *p, size_t s)
Free memory previously allocated.
Definition: region.hpp:310
void init(Region &r)
Initialize.
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
A & allocator(void)
Return allocator used.
Handle to region.
Definition: region.hpp:61
Iterator over value lists.
Definition: values-list.hpp:45
unsigned int use_cnt
Counter used for reference counting.
Definition: values-list.hpp:59
Gecode::FloatVal c(-8, 8)
Manage memory organized into block lists (allocator)
Gecode::IntArgs i(4, 1, 2, 3, 4)
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
VLIO * vlio
Reference to shared object.
Definition: values-list.hpp:64
ValueListIter(void)
Default constructor.
bool operator()(void) const
Test whether iterator is still at a value or done.
Client for block allocator of type T.
int val(void) const
Return value.
ValueList * c
Current list element.
Definition: values-list.hpp:68
#define forceinline
Definition: config.hpp:132
ValueListIter & operator=(const ValueListIter &i)
Assignment operator (both iterators must be allocated from the same region)
void operator++(void)
Move iterator to next value (if possible)
ValueList * h
Head of value list.
Definition: values-list.hpp:66
Gecode toplevel namespace
Shared object for allocation.
Definition: values-list.hpp:56
void set(ValueList *l)
Set value lists.
void * ralloc(size_t s)
Allocate memory from region.
Definition: region.hpp:302
void reset(void)
Reset iterator to start.