idx-view.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
00039
00040
00041
00042 namespace Gecode { namespace Int {
00043
00045 template<>
00046 class ViewToVarArg<IntView> {
00047 public:
00048 typedef IntVarArgs argtype;
00049 };
00051 template<>
00052 class ViewToVarArg<MinusView> {
00053 public:
00054 typedef IntVarArgs argtype;
00055 };
00057 template<>
00058 class ViewToVarArg<BoolView> {
00059 public:
00060 typedef BoolVarArgs argtype;
00061 };
00062
00063 template<class View>
00064 forceinline IdxView<View>*
00065 IdxView<View>::allocate(Space& home, int n) {
00066 return home.alloc<IdxView<View> >(n);
00067 }
00068
00069 template<class View>
00070 forceinline
00071 IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00072
00073 template<class View>
00074 forceinline
00075 IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00076 n = a.n; xs = a.xs;
00077 }
00078
00079 template<class View>
00080 forceinline
00081 IdxViewArray<View>::IdxViewArray(Space& home,
00082 const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
00083 n = xa.size();
00084 if (n>0) {
00085 xs = IdxView<View>::allocate(home, n);
00086 for (int i = n; i--; ) {
00087 xs[i].idx = i; xs[i].view = xa[i];
00088 }
00089 }
00090 }
00091
00092 template<class View>
00093 forceinline
00094 IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
00095 n = n0;
00096 if (n>0) {
00097 xs = IdxView<View>::allocate(home, n);
00098 }
00099 }
00100
00101 template<class View>
00102 forceinline int
00103 IdxViewArray<View>::size(void) const {
00104 return n;
00105 }
00106
00107 template<class View>
00108 forceinline void
00109 IdxViewArray<View>::size(int n0) {
00110 n = n0;
00111 }
00112
00113 template<class View>
00114 forceinline IdxView<View>&
00115 IdxViewArray<View>::operator [](int i) {
00116 assert((i >= 0) && (i < size()));
00117 return xs[i];
00118 }
00119
00120 template<class View>
00121 forceinline const IdxView<View>&
00122 IdxViewArray<View>::operator [](int i) const {
00123 assert((i >= 0) && (i < size()));
00124 return xs[i];
00125 }
00126
00127 template<class View>
00128 forceinline void
00129 IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
00130 bool process) {
00131 for (int i = n; i--; )
00132 xs[i].view.subscribe(home,p,pc,process);
00133 }
00134
00135 template<class View>
00136 forceinline void
00137 IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
00138 for (int i = n; i--; )
00139 xs[i].view.cancel(home,p,pc);
00140 }
00141
00142 template<class View>
00143 forceinline void
00144 IdxViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
00145 for (int i = n; i--; )
00146 xs[i].view.reschedule(home,p,pc);
00147 }
00148
00149 template<class View>
00150 forceinline void
00151 IdxViewArray<View>::update(Space& home, bool share, IdxViewArray<View>& a) {
00152 n = a.size();
00153 if (n>0) {
00154 xs = IdxView<View>::allocate(home,n);
00155 for (int i=n; i--; ) {
00156 xs[i].idx = a[i].idx;
00157 xs[i].view.update(home,share,a[i].view);
00158 }
00159 }
00160 }
00161
00162
00163 template<class Char, class Traits, class View>
00164 std::basic_ostream<Char,Traits>&
00165 operator <<(std::basic_ostream<Char,Traits>& os,
00166 const IdxViewArray<View>& x) {
00167 std::basic_ostringstream<Char,Traits> s;
00168 s.copyfmt(os); s.width(0);
00169 s << '{';
00170 if (x.size() > 0) {
00171 s << x[0].idx << ':' << x[0].view;
00172 for (int i=1; i<x.size(); i++)
00173 s << ", " << x[i].idx << ':' << x[i].view;
00174 }
00175 s << '}';
00176 return os << s.str();
00177 }
00178
00179 }}
00180
00181
00182