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