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 #include <functional>
00039
00040 namespace Gecode {
00041
00043 template<class Var, class Val>
00044 using VarValPrint = std::function<void(const Space& home, const Brancher& b,
00045 unsigned int a,
00046 Var x, int i, const Val& m,
00047 std::ostream& o)>;
00048
00050 template<class View, class Val>
00051 class BrancherPrint {
00052 public:
00054 typedef typename View::VarType Var;
00055 protected:
00056 SharedData<VarValPrint<Var,Val>> p;
00057 public:
00059 BrancherPrint(VarValPrint<Var,Val> vvp);
00061 BrancherPrint(Space& home, bool shared, BrancherPrint& bp);
00063 operator bool(void) const;
00065 void operator ()(const Space& home, const Brancher& b,
00066 unsigned int a,
00067 View x, int i, const Val& m,
00068 std::ostream& o) const;
00070 bool notice(void) const;
00072 void dispose(Space& home);
00073 };
00074
00076 template<class View, class Val>
00077 class BrancherNoPrint {
00078 public:
00080 typedef typename View::VarType Var;
00081 public:
00083 BrancherNoPrint(VarValPrint<Var,Val> vvp);
00085 BrancherNoPrint(Space& home, bool shared, BrancherNoPrint& bp);
00087 operator bool(void) const;
00089 void operator ()(const Space& home, const Brancher& b,
00090 unsigned int a,
00091 View x, int i, const Val& m,
00092 std::ostream& o) const;
00094 bool notice(void) const;
00096 void dispose(Space& home);
00097 };
00098
00099
00100
00101 template<class View, class Val>
00102 forceinline
00103 BrancherPrint<View,Val>::BrancherPrint(VarValPrint<Var,Val> vvp) : p(vvp) {
00104 if (!vvp)
00105 throw Gecode::InvalidFunction("BrancherPrint::BrancherPrint");
00106 }
00107
00108 template<class View, class Val>
00109 forceinline
00110 BrancherPrint<View,Val>::BrancherPrint(Space& home, bool shared,
00111 BrancherPrint<View,Val>& bp) {
00112 p.update(home,shared,bp.p);
00113 }
00114
00115 template<class View, class Val>
00116 forceinline
00117 BrancherPrint<View,Val>::operator bool(void) const {
00118 return true;
00119 }
00120
00121 template<class View, class Val>
00122 forceinline void
00123 BrancherPrint<View,Val>::operator ()(const Space& home, const Brancher& b,
00124 unsigned int a,
00125 View x, int i, const Val& m,
00126 std::ostream& o) const {
00127 GECODE_VALID_FUNCTION(p());
00128 Var xv(x.varimp());
00129 p()(home,b,a,xv,i,m,o);
00130 }
00131
00132 template<class View, class Val>
00133 forceinline bool
00134 BrancherPrint<View,Val>::notice(void) const {
00135 return true;
00136 }
00137
00138 template<class View, class Val>
00139 forceinline void
00140 BrancherPrint<View,Val>::dispose(Space&) {
00141 p.~SharedData<VarValPrint<Var,Val>>();
00142 }
00143
00144
00145 template<class View, class Val>
00146 forceinline
00147 BrancherNoPrint<View,Val>::BrancherNoPrint(VarValPrint<Var,Val> vvp) {
00148 assert(!vvp);
00149 }
00150
00151 template<class View, class Val>
00152 forceinline
00153 BrancherNoPrint<View,Val>::BrancherNoPrint(Space&, bool,
00154 BrancherNoPrint<View,Val>&) {}
00155
00156 template<class View, class Val>
00157 forceinline
00158 BrancherNoPrint<View,Val>::operator bool(void) const {
00159 return false;
00160 }
00161
00162 template<class View, class Val>
00163 forceinline void
00164 BrancherNoPrint<View,Val>::operator ()(const Space&, const Brancher&,
00165 unsigned int,
00166 View, int, const Val&,
00167 std::ostream&) const {}
00168 template<class View, class Val>
00169 forceinline bool
00170 BrancherNoPrint<View,Val>::notice(void) const {
00171 return false;
00172 }
00173
00174 template<class View, class Val>
00175 forceinline void
00176 BrancherNoPrint<View,Val>::dispose(Space&) {}
00177
00178 }
00179
00180