Generated on Fri Aug 24 2012 04:52:06 for Gecode by doxygen 1.8.1.2
visualnode.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2006
8  *
9  * Last modified:
10  * $Date: 2010-09-03 19:25:49 +1000 (Fri, 03 Sep 2010) $ by $Author: tack $
11  * $Revision: 11387 $
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 Gist {
39 
41  Extent::Extent(void) : l(-1), r(-1) {}
42 
44  Extent::Extent(int l0, int r0) : l(l0), r(r0) {}
45 
46  inline
47  Extent::Extent(int width) {
48  int halfWidth = width / 2;
49  l = 0 - halfWidth;
50  r = 0 + halfWidth;
51  }
52 
53  inline void
54  Extent::extend(int deltaL, int deltaR) {
55  l += deltaL; r += deltaR;
56  }
57 
58  inline void
59  Extent::move(int delta) {
60  l += delta; r += delta;
61  }
62 
63  forceinline int
64  Shape::depth(void) const { return _depth+1; }
65 
66  forceinline void
68  assert(d <= _depth+1);
69  _depth = d-1;
70  }
71 
72  forceinline const Extent&
73  Shape::operator [](int i) const {
74  assert(i < _depth+1);
75  return i == 0 ? leaf->shape[0] : shape[i-1];
76  }
77 
80  assert(i < _depth+1);
81  return i == 0 ? leaf->shape[0] : shape[i-1];
82  }
83 
84  inline Shape*
86  Shape* ret;
87  if (d == 1) {
88  ret = static_cast<Shape*>(heap.ralloc(sizeof(Shape)));
89  ret->shape[0] = Extent(Layout::extent);
90  } else {
91  ret = static_cast<Shape*>(heap.ralloc(sizeof(Shape) +
92  (d-2)*sizeof(Extent)));
93  }
94  ret->_depth = d-1;
95  return ret;
96  }
97 
98  forceinline void
100  if (shape != hidden && shape != leaf)
101  heap.rfree(shape);
102  }
103 
104  forceinline bool
106  if (d > depth())
107  return false;
108  extent = Extent(0,0);
109  for (int i=0; i <= d; i++) {
110  Extent currentExtent = (*this)[i];
111  extent.l += currentExtent.l;
112  extent.r += currentExtent.r;
113  }
114  return true;
115  }
116 
117  forceinline void
119  int lastLeft = 0;
120  int lastRight = 0;
121  bb.left = 0;
122  bb.right = 0;
123  for (int i=0; i<depth(); i++) {
124  lastLeft = lastLeft + (*this)[i].l;
125  lastRight = lastRight + (*this)[i].r;
126  bb.left = std::min(bb.left,lastLeft);
127  bb.right = std::max(bb.right,lastRight);
128  }
129  }
130 
131  forceinline const BoundingBox&
132  Shape::getBoundingBox(void) const {
133  return bb;
134  }
135 
136  forceinline bool
138  return getFlag(HIDDEN);
139  }
140 
141  forceinline void
143  setFlag(HIDDEN, h);
144  }
145 
146  forceinline void
148  if (getStatus() == BRANCH && h)
149  setStatus(STOP);
150  else if (getStatus() == STOP && !h)
151  setStatus(UNSTOP);
152  }
153 
154  forceinline int
155  VisualNode::getOffset(void) { return offset; }
156 
157  forceinline void
159 
160  forceinline bool
162  return getFlag(DIRTY);
163  }
164 
165  forceinline void
167  setFlag(DIRTY, d);
168  }
169 
170  forceinline bool
172  return getFlag(CHILDRENLAYOUTDONE);
173  }
174 
175  forceinline void
178  }
179 
180  forceinline bool
182  return getFlag(MARKED);
183  }
184 
185  forceinline void
187  setFlag(MARKED, m);
188  }
189 
190  forceinline bool
192  return getFlag(BOOKMARKED);
193  }
194 
195  forceinline void
197  setFlag(BOOKMARKED, m);
198  }
199 
200  forceinline bool
202  return getFlag(ONPATH);
203  }
204 
205  forceinline void
207  setFlag(ONPATH, b);
208  }
209 
212  return isHidden() ? Shape::hidden : shape;
213  }
214 
217 
218 }}
219 
220 // STATISTICS: gist-any