Generated on Tue Apr 18 10:21:46 2017 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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
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; }
00065 
00066   forceinline void
00067   Shape::setDepth(int d) {
00068     assert(d <= _depth);
00069     _depth = d;
00070   }
00071 
00072   forceinline const Extent&
00073   Shape::operator [](int i) const {
00074     assert(i < _depth);
00075     return shape[i];
00076   }
00077 
00078   forceinline Extent&
00079   Shape::operator [](int i) {
00080     assert(i < _depth);
00081     return shape[i];
00082   }
00083 
00084   inline Shape*
00085   Shape::allocate(int d) {
00086     assert(d >= 1);
00087     Shape* ret;
00088     ret =
00089       static_cast<Shape*>(heap.ralloc(sizeof(Shape)+(d-1)*sizeof(Extent)));
00090     ret->_depth = d;
00091     return ret;
00092   }
00093 
00094   forceinline void
00095   Shape::deallocate(Shape* shape) {
00096     if (shape != hidden && shape != leaf)
00097       heap.rfree(shape);
00098   }
00099 
00100   forceinline bool
00101   Shape::getExtentAtDepth(int d, Extent& extent) {
00102     if (d > depth())
00103       return false;
00104     extent = Extent(0,0);
00105     for (int i=0; i <= d; i++) {
00106       Extent currentExtent = (*this)[i];
00107       extent.l += currentExtent.l;
00108       extent.r += currentExtent.r;
00109     }
00110     return true;
00111   }
00112 
00113   forceinline void
00114   Shape::computeBoundingBox(void) {
00115     int lastLeft = 0;
00116     int lastRight = 0;
00117     bb.left = 0;
00118     bb.right = 0;
00119     for (int i=0; i<depth(); i++) {
00120       lastLeft = lastLeft + (*this)[i].l;
00121       lastRight = lastRight + (*this)[i].r;
00122       bb.left = std::min(bb.left,lastLeft);
00123       bb.right = std::max(bb.right,lastRight);
00124     }
00125   }
00126 
00127   forceinline const BoundingBox&
00128   Shape::getBoundingBox(void) const {
00129     return bb;
00130   }
00131 
00132   forceinline bool
00133   VisualNode::isHidden(void) {
00134     return getFlag(HIDDEN);
00135   }
00136 
00137   forceinline void
00138   VisualNode::setHidden(bool h) {
00139     setFlag(HIDDEN, h);
00140   }
00141 
00142   forceinline void
00143   VisualNode::setStop(bool h) {
00144     if (getStatus() == BRANCH && h)
00145       setStatus(STOP);
00146     else if (getStatus() == STOP && !h)
00147       setStatus(UNSTOP);
00148   }
00149 
00150   forceinline int
00151   VisualNode::getOffset(void) { return offset; }
00152 
00153   forceinline void
00154   VisualNode::setOffset(int n) { offset = n; }
00155 
00156   forceinline bool
00157   VisualNode::isDirty(void) {
00158     return getFlag(DIRTY);
00159   }
00160 
00161   forceinline void
00162   VisualNode::setDirty(bool d) {
00163     setFlag(DIRTY, d);
00164   }
00165 
00166   forceinline bool
00167   VisualNode::childrenLayoutIsDone(void) {
00168     return getFlag(CHILDRENLAYOUTDONE);
00169   }
00170 
00171   forceinline void
00172   VisualNode::setChildrenLayoutDone(bool d) {
00173     setFlag(CHILDRENLAYOUTDONE, d);
00174   }
00175 
00176   forceinline bool
00177   VisualNode::isMarked(void) {
00178     return getFlag(MARKED);
00179   }
00180 
00181   forceinline void
00182   VisualNode::setMarked(bool m) {
00183     setFlag(MARKED, m);
00184   }
00185 
00186   forceinline bool
00187   VisualNode::isBookmarked(void) {
00188     return getFlag(BOOKMARKED);
00189   }
00190 
00191   forceinline void
00192   VisualNode::setBookmarked(bool m) {
00193     setFlag(BOOKMARKED, m);
00194   }
00195 
00196   forceinline bool
00197   VisualNode::isOnPath(void) {
00198     return getFlag(ONPATH);
00199   }
00200 
00201   forceinline void
00202   VisualNode::setOnPath(bool b) {
00203     setFlag(ONPATH, b);
00204   }
00205 
00206   forceinline Shape*
00207   VisualNode::getShape(void) {
00208     return isHidden() ? Shape::hidden : shape;
00209   }
00210 
00211   forceinline BoundingBox
00212   VisualNode::getBoundingBox(void) { return getShape()->getBoundingBox(); }
00213 
00214 }}
00215 
00216 // STATISTICS: gist-any