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