Generated on Thu Mar 22 10:39:32 2012 for Gecode by doxygen 1.6.3

visualnode.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-09-03 11:25:49 +0200 (Fri, 03 Sep 2010) $ by $Author: tack $
00011  *     $Revision: 11387 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  * Permission is hereby granted, free of charge, to any person obtaining
00018  * a copy of this software and associated documentation files (the
00019  * "Software"), to deal in the Software without restriction, including
00020  * without limitation the rights to use, copy, modify, merge, publish,
00021  * distribute, sublicense, and/or sell copies of the Software, and to
00022  * permit persons to whom the Software is furnished to do so, subject to
00023  * the following conditions:
00024  *
00025  * The above copyright notice and this permission notice shall be
00026  * included in all copies or substantial portions of the Software.
00027  *
00028  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Gist {
00039 
00040   forceinline
00041   Extent::Extent(void) : l(-1), r(-1) {}
00042 
00043   forceinline
00044   Extent::Extent(int l0, int r0) : l(l0), r(r0) {}
00045 
00046   inline
00047   Extent::Extent(int width) {
00048     int halfWidth = width / 2;
00049     l = 0 - halfWidth;
00050     r = 0 + halfWidth;
00051   }
00052 
00053   inline void
00054   Extent::extend(int deltaL, int deltaR) {
00055     l += deltaL; r += deltaR;
00056   }
00057 
00058   inline void
00059   Extent::move(int delta) {
00060     l += delta; r += delta;
00061   }
00062 
00063   forceinline int
00064   Shape::depth(void) const { return _depth+1; }
00065 
00066   forceinline void
00067   Shape::setDepth(int d) {
00068     assert(d <= _depth+1);
00069     _depth = d-1;
00070   }
00071 
00072   forceinline const Extent&
00073   Shape::operator [](int i) const {
00074     assert(i < _depth+1);
00075     return i == 0 ? leaf->shape[0] : shape[i-1];
00076   }
00077 
00078   forceinline Extent&
00079   Shape::operator [](int i) {
00080     assert(i < _depth+1);
00081     return i == 0 ? leaf->shape[0] : shape[i-1];
00082   }
00083 
00084   inline Shape*
00085   Shape::allocate(int d) {
00086     Shape* ret;
00087     if (d == 1) {
00088       ret = static_cast<Shape*>(heap.ralloc(sizeof(Shape)));
00089       ret->shape[0] = Extent(Layout::extent);      
00090     } else {
00091       ret = static_cast<Shape*>(heap.ralloc(sizeof(Shape) +
00092                                             (d-2)*sizeof(Extent)));
00093     }
00094     ret->_depth = d-1;
00095     return ret;
00096   }
00097 
00098   forceinline void
00099   Shape::deallocate(Shape* shape) {
00100     if (shape != hidden && shape != leaf)
00101       heap.rfree(shape);
00102   }
00103 
00104   forceinline bool
00105   Shape::getExtentAtDepth(int d, Extent& extent) {
00106     if (d > depth())
00107       return false;
00108     extent = Extent(0,0);
00109     for (int i=0; i <= d; i++) {
00110       Extent currentExtent = (*this)[i];
00111       extent.l += currentExtent.l;
00112       extent.r += currentExtent.r;
00113     }
00114     return true;
00115   }
00116 
00117   forceinline void
00118   Shape::computeBoundingBox(void) {
00119     int lastLeft = 0;
00120     int lastRight = 0;
00121     bb.left = 0;
00122     bb.right = 0;
00123     for (int i=0; i<depth(); i++) {
00124       lastLeft = lastLeft + (*this)[i].l;
00125       lastRight = lastRight + (*this)[i].r;
00126       bb.left = std::min(bb.left,lastLeft);
00127       bb.right = std::max(bb.right,lastRight);
00128     }
00129   }
00130 
00131   forceinline const BoundingBox&
00132   Shape::getBoundingBox(void) const {
00133     return bb;
00134   }
00135 
00136   forceinline bool
00137   VisualNode::isHidden(void) {
00138     return getFlag(HIDDEN);
00139   }
00140 
00141   forceinline void
00142   VisualNode::setHidden(bool h) {
00143     setFlag(HIDDEN, h);
00144   }
00145 
00146   forceinline void
00147   VisualNode::setStop(bool h) {
00148     if (getStatus() == BRANCH && h)
00149       setStatus(STOP);
00150     else if (getStatus() == STOP && !h)
00151       setStatus(UNSTOP);
00152   }
00153 
00154   forceinline int
00155   VisualNode::getOffset(void) { return offset; }
00156 
00157   forceinline void
00158   VisualNode::setOffset(int n) { offset = n; }
00159 
00160   forceinline bool
00161   VisualNode::isDirty(void) {
00162     return getFlag(DIRTY);
00163   }
00164 
00165   forceinline void
00166   VisualNode::setDirty(bool d) {
00167     setFlag(DIRTY, d);
00168   }
00169 
00170   forceinline bool
00171   VisualNode::childrenLayoutIsDone(void) {
00172     return getFlag(CHILDRENLAYOUTDONE);
00173   }
00174 
00175   forceinline void
00176   VisualNode::setChildrenLayoutDone(bool d) {
00177     setFlag(CHILDRENLAYOUTDONE, d);
00178   }
00179 
00180   forceinline bool
00181   VisualNode::isMarked(void) {
00182     return getFlag(MARKED);
00183   }
00184 
00185   forceinline void
00186   VisualNode::setMarked(bool m) {
00187     setFlag(MARKED, m);
00188   }
00189 
00190   forceinline bool
00191   VisualNode::isBookmarked(void) {
00192     return getFlag(BOOKMARKED);
00193   }
00194 
00195   forceinline void
00196   VisualNode::setBookmarked(bool m) {
00197     setFlag(BOOKMARKED, m);
00198   }
00199 
00200   forceinline bool
00201   VisualNode::isOnPath(void) {
00202     return getFlag(ONPATH);
00203   }
00204 
00205   forceinline void
00206   VisualNode::setOnPath(bool b) {
00207     setFlag(ONPATH, b);
00208   }
00209 
00210   forceinline Shape*
00211   VisualNode::getShape(void) {
00212     return isHidden() ? Shape::hidden : shape;
00213   }
00214 
00215   forceinline BoundingBox
00216   VisualNode::getBoundingBox(void) { return getShape()->getBoundingBox(); }
00217 
00218 }}
00219 
00220 // STATISTICS: gist-any