values-list.hpp
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 Values {
00039
00045 class ValueListIter {
00046 protected:
00048 class ValueList : public Support::BlockClient<ValueList,Region> {
00049 public:
00051 int val;
00053 ValueList* next;
00054 };
00056 class VLIO : public Support::BlockAllocator<ValueList,Region> {
00057 public:
00059 unsigned int use_cnt;
00061 VLIO(Region& r);
00062 };
00064 VLIO* vlio;
00066 ValueList* h;
00068 ValueList* c;
00070 void set(ValueList* l);
00071 public:
00073
00074
00075 ValueListIter(void);
00077 ValueListIter(const ValueListIter& i);
00079 ValueListIter(Region& r);
00081 void init(Region& r);
00083 ValueListIter& operator =(const ValueListIter& i);
00085
00087
00088
00089 bool operator ()(void) const;
00091 void operator ++(void);
00093 void reset(void);
00095
00097
00098
00099 int val(void) const;
00101
00103 ~ValueListIter(void);
00104 };
00105
00106
00107 forceinline
00108 ValueListIter::VLIO::VLIO(Region& r)
00109 : Support::BlockAllocator<ValueList,Region>(r), use_cnt(1) {}
00110
00111
00112 forceinline
00113 ValueListIter::ValueListIter(void)
00114 : vlio(NULL) {}
00115
00116 forceinline
00117 ValueListIter::ValueListIter(Region& r)
00118 : vlio(new (r.ralloc(sizeof(VLIO))) VLIO(r)),
00119 h(NULL), c(NULL) {}
00120
00121 forceinline void
00122 ValueListIter::init(Region& r) {
00123 vlio = new (r.ralloc(sizeof(VLIO))) VLIO(r);
00124 h = c = NULL;
00125 }
00126
00127 forceinline
00128 ValueListIter::ValueListIter(const ValueListIter& i)
00129 : vlio(i.vlio), h(i.h), c(i.c) {
00130 vlio->use_cnt++;
00131 }
00132
00133 forceinline ValueListIter&
00134 ValueListIter::operator =(const ValueListIter& i) {
00135 if (&i != this) {
00136 if (--vlio->use_cnt == 0) {
00137 Region& r = vlio->allocator();
00138 vlio->~VLIO();
00139 r.rfree(vlio,sizeof(VLIO));
00140 }
00141 vlio = i.vlio;
00142 vlio->use_cnt++;
00143 c=i.c; h=i.h;
00144 }
00145 return *this;
00146 }
00147
00148 forceinline
00149 ValueListIter::~ValueListIter(void) {
00150 if (--vlio->use_cnt == 0) {
00151 Region& r = vlio->allocator();
00152 vlio->~VLIO();
00153 r.rfree(vlio,sizeof(VLIO));
00154 }
00155 }
00156
00157
00158 forceinline void
00159 ValueListIter::set(ValueList* l) {
00160 h = c = l;
00161 }
00162
00163 forceinline bool
00164 ValueListIter::operator ()(void) const {
00165 return c != NULL;
00166 }
00167
00168 forceinline void
00169 ValueListIter::operator ++(void) {
00170 c = c->next;
00171 }
00172
00173 forceinline void
00174 ValueListIter::reset(void) {
00175 c = h;
00176 }
00177
00178 forceinline int
00179 ValueListIter::val(void) const {
00180 return c->val;
00181 }
00182
00183 }}}
00184
00185
00186