Generated on Wed Jan 4 17:49:14 2006 for Gecode by doxygen 1.4.6

idxarray.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004,2005
00008  *     Christian Schulte, 2004,2005
00009  *
00010  *  Last modified:
00011  *     $Date: 2005-11-11 18:26:30 +0100 (Fri, 11 Nov 2005) $ by $Author: tack $
00012  *     $Revision: 2544 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
00021  *
00022  */
00023 
00024 namespace Gecode { namespace Set { namespace Select {
00025 
00026   template <class View>
00027   forceinline IdxView<View>*
00028   IdxView<View>::allocate(Space* home, int n) {
00029     return
00030     reinterpret_cast<IdxView<View>*>(home->alloc(sizeof(IdxView<View>)*n));
00031   }
00032 
00033   template <class View>
00034   IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00035 
00036   template <class View>
00037   IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00038     n = a.n; xs = a.xs;
00039   }
00040 
00041   template <class View>
00042   IdxViewArray<View>::IdxViewArray(Space* home, const SetVarArgs& xa)
00043     : xs(NULL) {
00044     n = xa.size();
00045     if (n>0) {
00046       xs = IdxView<View>::allocate(home, n);
00047       for (int i = n; i--; ) {
00048         SetView xav(xa[i]);
00049         View xavv(xav);
00050         xs[i].idx = i; xs[i].var = xavv;
00051       }
00052     }
00053   }
00054 
00055   template <class View>
00056   forceinline int
00057   IdxViewArray<View>::size(void) const {
00058     return n;
00059   }
00060 
00061   template <class View>
00062   forceinline void
00063   IdxViewArray<View>::size(int n0) {
00064     n = n0;
00065   }
00066 
00067   template <class View>
00068   forceinline IdxView<View>&
00069   IdxViewArray<View>::operator[](int i) {
00070     assert((i >= 0) && (i < size()));
00071     return xs[i];
00072   }
00073 
00074   template <class View>
00075   forceinline const IdxView<View>&
00076   IdxViewArray<View>::operator[](int i) const {
00077     assert((i >= 0) && (i < size()));
00078     return xs[i];
00079   }
00080 
00081   template <class View>
00082   void
00083   IdxViewArray<View>::subscribe(Space* home, Propagator* p, PropCond pc) {
00084     for (int i = n; i--; )
00085       xs[i].var.subscribe(home,p,pc);
00086   }
00087 
00088   template <class View>
00089   void
00090   IdxViewArray<View>::cancel(Propagator* p, PropCond pc) {
00091     for (int i = n; i--; )
00092       xs[i].var.cancel(p,pc);
00093   }
00094 
00095   template <class View>
00096   void
00097   IdxViewArray<View>::update(Space* home, bool share, IdxViewArray<View>& a) {
00098     n = a.size();
00099     if (n>0) {
00100       xs = IdxView<View>::allocate(home,n);
00101       for (int i=n; i--; ) {
00102         xs[i].idx = a[i].idx;
00103         xs[i].var.update(home,share,a[i].var);
00104       }
00105     }
00106   }
00107 
00108 }}}
00109 
00110 // STATISTICS: set-prop
00111