Generated on Tue May 22 09:40:07 2018 for Gecode by doxygen 1.6.3

values-list.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2010
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 Iter { namespace Values {
00035 
00041   class ValueListIter {
00042   protected:
00044     class ValueList : public Support::BlockClient<ValueList,Region> {
00045     public:
00047       int val;
00049       ValueList* next;
00050     };
00052     class VLIO : public Support::BlockAllocator<ValueList,Region> {
00053     public:
00055       unsigned int use_cnt;
00057       VLIO(Region& r);
00058     };
00060     VLIO* vlio;
00062     ValueList* h;
00064     ValueList* c;
00066     void set(ValueList* l);
00067   public:
00069 
00070 
00071     ValueListIter(void);
00073     ValueListIter(const ValueListIter& i);
00075     ValueListIter(Region& r);
00077     void init(Region& r);
00079     ValueListIter& operator =(const ValueListIter& i);
00081 
00083 
00084 
00085     bool operator ()(void) const;
00087     void operator ++(void);
00089     void reset(void);
00091 
00093 
00094 
00095     int val(void) const;
00097 
00099     ~ValueListIter(void);
00100   };
00101 
00102 
00103   forceinline
00104   ValueListIter::VLIO::VLIO(Region& r)
00105     : Support::BlockAllocator<ValueList,Region>(r), use_cnt(1) {}
00106 
00107 
00108   forceinline
00109   ValueListIter::ValueListIter(void)
00110     : vlio(NULL) {}
00111 
00112   forceinline
00113   ValueListIter::ValueListIter(Region& r)
00114     : vlio(new (r.ralloc(sizeof(VLIO))) VLIO(r)),
00115       h(NULL), c(NULL) {}
00116 
00117   forceinline void
00118   ValueListIter::init(Region& r) {
00119     vlio = new (r.ralloc(sizeof(VLIO))) VLIO(r);
00120     h = c = NULL;
00121   }
00122 
00123   forceinline
00124   ValueListIter::ValueListIter(const ValueListIter& i)
00125     : vlio(i.vlio), h(i.h), c(i.c)  {
00126     vlio->use_cnt++;
00127   }
00128 
00129   forceinline ValueListIter&
00130   ValueListIter::operator =(const ValueListIter& i) {
00131     if (&i != this) {
00132       if (--vlio->use_cnt == 0) {
00133         Region& r = vlio->allocator();
00134         vlio->~VLIO();
00135         r.rfree(vlio,sizeof(VLIO));
00136       }
00137       vlio = i.vlio;
00138       vlio->use_cnt++;
00139       c=i.c; h=i.h;
00140     }
00141     return *this;
00142   }
00143 
00144   forceinline
00145   ValueListIter::~ValueListIter(void) {
00146     if (--vlio->use_cnt == 0) {
00147       Region& r = vlio->allocator();
00148       vlio->~VLIO();
00149       r.rfree(vlio,sizeof(VLIO));
00150     }
00151   }
00152 
00153 
00154   forceinline void
00155   ValueListIter::set(ValueList* l) {
00156     h = c = l;
00157   }
00158 
00159   forceinline bool
00160   ValueListIter::operator ()(void) const {
00161     return c != NULL;
00162   }
00163 
00164   forceinline void
00165   ValueListIter::operator ++(void) {
00166     c = c->next;
00167   }
00168 
00169   forceinline void
00170   ValueListIter::reset(void) {
00171     c = h;
00172   }
00173 
00174   forceinline int
00175   ValueListIter::val(void) const {
00176     return c->val;
00177   }
00178 
00179 }}}
00180 
00181 // STATISTICS: iter-any
00182