val-sel.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 {
00035
00042
00043 template<class _View, class _Val>
00044 class ValSel {
00045 public:
00047 typedef _View View;
00049 typedef typename View::VarType Var;
00051 typedef _Val Val;
00052 public:
00054 ValSel(Space& home, const ValBranch<Var>& vb);
00056 ValSel(Space& home, ValSel<View,Val>& vs);
00058 bool notice(void) const;
00060 void dispose(Space& home);
00061 };
00062
00064 template<class View>
00065 class ValSelFunction :
00066 public ValSel<View,
00067 typename BranchTraits<typename View::VarType>::ValType> {
00068 using typename ValSel<View,
00069 typename BranchTraits<typename View::VarType>::ValType>::Var;
00070 public:
00072 typedef typename ValSel<View,
00073 typename BranchTraits<typename View::VarType>
00074 ::ValType>::Val Val;
00076 typedef typename BranchTraits<Var>::Val ValFunction;
00077 protected:
00079 SharedData<ValFunction> v;
00080 public:
00082 ValSelFunction(Space& home, const ValBranch<Var>& vb);
00084 ValSelFunction(Space& home, ValSelFunction<View>& vs);
00086 Val val(const Space& home, View x, int i);
00088 bool notice(void) const;
00090 void dispose(Space& home);
00091 };
00093
00094
00095
00096 template<class View, class Val>
00097 forceinline
00098 ValSel<View,Val>::ValSel(Space&, const ValBranch<Var>&) {}
00099 template<class View, class Val>
00100 forceinline
00101 ValSel<View,Val>::ValSel(Space&, ValSel<View,Val>&) {}
00102 template<class View, class Val>
00103 forceinline bool
00104 ValSel<View,Val>::notice(void) const {
00105 return false;
00106 }
00107 template<class View, class Val>
00108 forceinline void
00109 ValSel<View,Val>::dispose(Space&) {}
00110
00111
00112
00113 template<class View>
00114 forceinline
00115 ValSelFunction<View>::ValSelFunction
00116 (Space& home, const ValBranch<ValSelFunction<View>::Var>& vb)
00117 : ValSel<View,Val>(home,vb), v(vb.val()) {
00118 if (!v())
00119 throw InvalidFunction("ValSelFunction::ValSelFunction");
00120 }
00121 template<class View>
00122 forceinline
00123 ValSelFunction<View>::ValSelFunction(Space& home, ValSelFunction<View>& vs)
00124 : ValSel<View,Val>(home,vs), v(vs.v) {
00125 }
00126 template<class View>
00127 forceinline typename ValSelFunction<View>::Val
00128 ValSelFunction<View>::val(const Space& home, View x, int i) {
00129 typename View::VarType y(x.varimp());
00130 GECODE_VALID_FUNCTION(v());
00131 return v()(home,y,i);
00132 }
00133 template<class View>
00134 forceinline bool
00135 ValSelFunction<View>::notice(void) const {
00136 return true;
00137 }
00138 template<class View>
00139 forceinline void
00140 ValSelFunction<View>::dispose(Space&) {
00141 v.~SharedData<ValFunction>();
00142 }
00143
00144 }
00145
00146