27 #include "core/tb2types.hpp" 31 #include <boost/version.hpp> 32 #if (BOOST_VERSION >= 105600) 33 #include <boost/type_index.hpp> 55 template <
class T,
class V>
64 StoreStack(
const StoreStack& s);
65 StoreStack& operator=(
const StoreStack& s);
68 StoreStack(
int powbckmemory = STORE_SIZE)
70 if (pow(2., powbckmemory) >= SIZE_MAX) {
71 cerr <<
"command-line initial memory size parameter " << powbckmemory <<
" power of two too large!" << endl;
74 indexMax = (ptrdiff_t)pow(2., powbckmemory);
75 pointers =
new T*[indexMax];
76 content =
new V[indexMax];
79 if (ToulBar2::verbose > 0) {
80 cout <<
"c " << indexMax * (
sizeof(V) +
sizeof(T*)) <<
" Bytes allocated for " 82 #
if (BOOST_VERSION >= 105600)
83 << boost::typeindex::type_id<T>().pretty_name()
100 T** newpointers =
new T*[indexMax * 2];
101 V* newcontent =
new V[indexMax * 2];
102 if (!newpointers || !newcontent) {
105 #if (BOOST_VERSION >= 105600) 106 << boost::typeindex::type_id<T>().pretty_name()
111 <<
" stack out of memory!" << endl;
114 std::copy(pointers, pointers + indexMax, newpointers);
115 std::copy(content, content + indexMax, newcontent);
119 pointers = newpointers;
120 content = newcontent;
122 if (ToulBar2::verbose >= 0) {
123 cout <<
"c " << indexMax * (
sizeof(V) +
sizeof(T*)) <<
" Bytes allocated for " 125 #
if (BOOST_VERSION >= 105600)
126 << boost::typeindex::type_id<T>().pretty_name()
131 <<
" stack." << endl;
135 void store(T* x, V y)
139 if (index >= indexMax)
150 if (index >= indexMax)
160 if (index >= indexMax)
162 pointers[index] = (T*)(intptr_t)base;
170 void restore(Value** adr, Value* val, ptrdiff_t x)
176 void restore(Cost** adr, Cost* val, ptrdiff_t x)
182 void restore(BigInteger** adr, BigInteger* val, ptrdiff_t x)
187 void restore(BTList<Q>** l, DLink<Q>** elt, ptrdiff_t& x);
197 restore(pointers, content, x);
201 base = (ptrdiff_t)pointers[y];
224 StoreBasic(
const StoreBasic& elt)
229 static void store() { mystore.store(); };
230 static void restore() { mystore.restore(); };
232 StoreBasic& operator=(
const StoreBasic& elt)
241 StoreBasic& operator=(
const T vv)
247 StoreBasic& operator+=(
const T vv)
253 StoreBasic& operator-=(
const T vv)
260 static StoreStack<T, T> mystore;
264 StoreStack<T, T> StoreBasic<T>::mystore(STORE_SIZE);
266 typedef StoreBasic<Value> StoreValue;
267 typedef StoreValue StoreInt;
268 typedef StoreBasic<Cost> StoreCost;
269 typedef StoreBasic<BigInteger> StoreBigInteger;
276 virtual ~Store() = 0;
280 static StoreStack<BTList<Value>, DLink<Value>*> storeDomain;
281 static StoreStack<BTList<ConstraintLink>, DLink<ConstraintLink>*> storeConstraint;
282 static StoreStack<BTList<Variable*>, DLink<Variable*>*> storeVariable;
283 static StoreStack<BTList<Separator*>, DLink<Separator*>*> storeSeparator;
286 static int getDepth()
297 StoreBigInteger::store();
299 storeConstraint.store();
300 storeVariable.store();
301 storeSeparator.store();
305 static void restore()
308 StoreValue::restore();
309 StoreCost::restore();
310 StoreBigInteger::restore();
311 storeDomain.restore();
312 storeConstraint.restore();
313 storeVariable.restore();
314 storeSeparator.restore();
318 static void restore(
int newDepth)
320 assert(depth >= newDepth);
321 while (depth > newDepth)
326 #define storeIndexList storeDomain