Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Iter { namespace Ranges {
00039
00045 class RangeListIter {
00046 protected:
00048 class RangeList : public Support::BlockClient<RangeList,Region> {
00049 public:
00051 int min, max;
00053 RangeList* next;
00054 };
00056 class RLIO : public Support::BlockAllocator<RangeList,Region> {
00057 public:
00059 unsigned int use_cnt;
00061 RLIO(Region& r);
00062 };
00064 RLIO* rlio;
00066 RangeList* h;
00068 RangeList* c;
00070 void set(RangeList* l);
00071 public:
00073
00074
00075 RangeListIter(void);
00077 RangeListIter(const RangeListIter& i);
00079 RangeListIter(Region& r);
00081 void init(Region& r);
00083 RangeListIter& operator =(const RangeListIter& i);
00085
00087
00088
00089 bool operator ()(void) const;
00091 void operator ++(void);
00093 void reset(void);
00095
00097
00098
00099 int min(void) const;
00101 int max(void) const;
00103 unsigned int width(void) const;
00105
00107 ~RangeListIter(void);
00108 };
00109
00110
00111 forceinline
00112 RangeListIter::RLIO::RLIO(Region& r)
00113 : Support::BlockAllocator<RangeList,Region>(r), use_cnt(1) {}
00114
00115
00116 forceinline
00117 RangeListIter::RangeListIter(void)
00118 : rlio(NULL) {}
00119
00120 forceinline
00121 RangeListIter::RangeListIter(Region& r)
00122 : rlio(new (r.ralloc(sizeof(RLIO))) RLIO(r)),
00123 h(NULL), c(NULL) {}
00124
00125 forceinline void
00126 RangeListIter::init(Region& r) {
00127 rlio = new (r.ralloc(sizeof(RLIO))) RLIO(r);
00128 h = c = NULL;
00129 }
00130
00131 forceinline
00132 RangeListIter::RangeListIter(const RangeListIter& i)
00133 : rlio(i.rlio), h(i.h), c(i.c) {
00134 rlio->use_cnt++;
00135 }
00136
00137 forceinline RangeListIter&
00138 RangeListIter::operator =(const RangeListIter& i) {
00139 if (&i != this) {
00140 if (--rlio->use_cnt == 0) {
00141 Region& r = rlio->allocator();
00142 rlio->~RLIO();
00143 r.rfree(rlio,sizeof(RLIO));
00144 }
00145 rlio = i.rlio;
00146 rlio->use_cnt++;
00147 c=i.c; h=i.h;
00148 }
00149 return *this;
00150 }
00151
00152 forceinline
00153 RangeListIter::~RangeListIter(void) {
00154 if (--rlio->use_cnt == 0) {
00155 Region& r = rlio->allocator();
00156 rlio->~RLIO();
00157 r.rfree(rlio,sizeof(RLIO));
00158 }
00159 }
00160
00161
00162 forceinline void
00163 RangeListIter::set(RangeList* l) {
00164 h = c = l;
00165 }
00166
00167 forceinline bool
00168 RangeListIter::operator ()(void) const {
00169 return c != NULL;
00170 }
00171
00172 forceinline void
00173 RangeListIter::operator ++(void) {
00174 c = c->next;
00175 }
00176
00177 forceinline void
00178 RangeListIter::reset(void) {
00179 c = h;
00180 }
00181
00182 forceinline int
00183 RangeListIter::min(void) const {
00184 return c->min;
00185 }
00186 forceinline int
00187 RangeListIter::max(void) const {
00188 return c->max;
00189 }
00190 forceinline unsigned int
00191 RangeListIter::width(void) const {
00192 return static_cast<unsigned int>(c->max-c->min)+1;
00193 }
00194
00195 }}}
00196
00197
00198