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 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
00182