idxarray.icc
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
00039
00040 namespace Gecode { namespace Set { namespace Element {
00041
00042 template <class View>
00043 forceinline IdxView<View>*
00044 IdxView<View>::allocate(Space* home, int n) {
00045 return static_cast<IdxView<View>*>(home->alloc(sizeof(IdxView<View>)*n));
00046 }
00047
00048 template <class View>
00049 IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00050
00051 template <class View>
00052 IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00053 n = a.n; xs = a.xs;
00054 }
00055
00056 template <class View>
00057 IdxViewArray<View>::IdxViewArray(Space* home, const SetVarArgs& xa)
00058 : xs(NULL) {
00059 n = xa.size();
00060 if (n>0) {
00061 xs = IdxView<View>::allocate(home, n);
00062 for (int i = n; i--; ) {
00063 SetView xav(xa[i]);
00064 View xavv(xav);
00065 xs[i].idx = i; xs[i].var = xavv;
00066 }
00067 }
00068 }
00069
00070 template <class View>
00071 forceinline int
00072 IdxViewArray<View>::size(void) const {
00073 return n;
00074 }
00075
00076 template <class View>
00077 forceinline void
00078 IdxViewArray<View>::size(int n0) {
00079 n = n0;
00080 }
00081
00082 template <class View>
00083 forceinline IdxView<View>&
00084 IdxViewArray<View>::operator[](int i) {
00085 assert((i >= 0) && (i < size()));
00086 return xs[i];
00087 }
00088
00089 template <class View>
00090 forceinline const IdxView<View>&
00091 IdxViewArray<View>::operator[](int i) const {
00092 assert((i >= 0) && (i < size()));
00093 return xs[i];
00094 }
00095
00096 template <class View>
00097 void
00098 IdxViewArray<View>::subscribe(Space* home, Propagator* p, PropCond pc,
00099 bool process) {
00100 for (int i = n; i--; )
00101 xs[i].var.subscribe(home,p,pc,process);
00102 }
00103
00104 template <class View>
00105 void
00106 IdxViewArray<View>::cancel(Space* home, Propagator* p, PropCond pc) {
00107 for (int i = n; i--; )
00108 xs[i].var.cancel(home,p,pc);
00109 }
00110
00111 template <class View>
00112 void
00113 IdxViewArray<View>::update(Space* home, bool share, IdxViewArray<View>& a) {
00114 n = a.size();
00115 if (n>0) {
00116 xs = IdxView<View>::allocate(home,n);
00117 for (int i=n; i--; ) {
00118 xs[i].idx = a[i].idx;
00119 xs[i].var.update(home,share,a[i].var);
00120 }
00121 }
00122 }
00123
00124 template <class View>
00125 Reflection::Arg*
00126 IdxViewArray<View>::spec(const Space* home, Reflection::VarMap& m) const {
00127 Reflection::IntArrayArg* is = Reflection::Arg::newIntArray(n);
00128 for (int i = 0; i<n; i++)
00129 (*is)[i] = xs[i].idx;
00130 Reflection::ArrayArg* s = Reflection::Arg::newArray(n);
00131 for (int i = 0; i<n; i++)
00132 (*s)[i] = xs[i].var.spec(home, m);
00133 return Reflection::Arg::newPair(is,s);
00134 }
00135
00136 template <class View>
00137 IdxViewArray<View>::IdxViewArray(Space* home,
00138 const Reflection::VarMap& vars,
00139 Reflection::Arg* spec) : xs(NULL) {
00140 Reflection::IntArrayArg* is = spec->first()->toIntArray();
00141 Reflection::ArrayArg* s = spec->second()->toArray();
00142 n = is->size();
00143 if (n>0) {
00144 xs = IdxView<View>::allocate(home, n);
00145 for (int i = n; i--; ) {
00146 View xavv(home, vars, (*s)[i]);
00147 xs[i].idx = (*is)[i]; xs[i].var = xavv;
00148 }
00149 }
00150 }
00151
00152 }}}
00153
00154
00155