tracer.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
00037 class TracerBase : public HeapAllocated {
00038 protected:
00040 GECODE_KERNEL_EXPORT
00041 static Support::Mutex m;
00042 };
00043
00044 template<class View> class ViewTraceRecorder;
00045
00050 template<class View>
00051 class ViewTracer : public TracerBase {
00052 template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
00053 private:
00060 void _init(const Space& home, const ViewTraceRecorder<View>& t);
00067 void _prune(const Space& home, const ViewTraceRecorder<View>& t,
00068 const ViewTraceInfo& vti,
00069 int i, typename TraceTraits<View>::TraceDelta& d);
00076 void _fail(const Space& home, const ViewTraceRecorder<View>& t);
00082 void _fix(const Space& home, const ViewTraceRecorder<View>& t);
00088 void _done(const Space& home, const ViewTraceRecorder<View>& t);
00089 public:
00091 ViewTracer(void);
00098 virtual void init(const Space& home,
00099 const ViewTraceRecorder<View>& t) = 0;
00109 virtual void prune(const Space& home,
00110 const ViewTraceRecorder<View>& t,
00111 const ViewTraceInfo& vti,
00112 int i, typename TraceTraits<View>::TraceDelta& d) = 0;
00119 virtual void fail(const Space& home,
00120 const ViewTraceRecorder<View>& t) = 0;
00128 virtual void fix(const Space& home,
00129 const ViewTraceRecorder<View>& t) = 0;
00136 virtual void done(const Space& home,
00137 const ViewTraceRecorder<View>& t) = 0;
00139 virtual ~ViewTracer(void);
00140 };
00141
00142
00143
00144
00149 class Tracer : public TracerBase {
00150 friend class Space;
00151 private:
00158 void _propagate(const Space& home, const PropagateTraceInfo& pti);
00165 void _commit(const Space& home, const CommitTraceInfo& cti);
00166 public:
00168 Tracer(void);
00175 virtual void propagate(const Space& home,
00176 const PropagateTraceInfo& pti) = 0;
00183 virtual void commit(const Space& home,
00184 const CommitTraceInfo& cti) = 0;
00186 virtual ~Tracer(void);
00187 };
00188
00189
00194 class GECODE_KERNEL_EXPORT StdTracer : public Tracer {
00195 protected:
00197 std::ostream& os;
00198 public:
00200 StdTracer(std::ostream& os = std::cerr);
00207 virtual void propagate(const Space& home,
00208 const PropagateTraceInfo& pti);
00215 virtual void commit(const Space& home,
00216 const CommitTraceInfo& cti);
00218 static StdTracer def;
00219 };
00220
00221
00222
00223
00224
00225
00226 template<class View>
00227 forceinline
00228 ViewTracer<View>::ViewTracer(void) {
00229 }
00230
00231 template<class View>
00232 forceinline void
00233 ViewTracer<View>::_init(const Space& home,
00234 const ViewTraceRecorder<View>& t) {
00235 m.acquire();
00236 init(home,t);
00237 m.release();
00238 }
00239 template<class View>
00240 forceinline void
00241 ViewTracer<View>::_prune(const Space& home,
00242 const ViewTraceRecorder<View>& t,
00243 const ViewTraceInfo& vti,
00244 int i, typename TraceTraits<View>::TraceDelta& d) {
00245 m.acquire();
00246 prune(home,t,vti,i,d);
00247 m.release();
00248 }
00249 template<class View>
00250 forceinline void
00251 ViewTracer<View>::_fail(const Space& home,
00252 const ViewTraceRecorder<View>& t) {
00253 m.acquire();
00254 fail(home,t);
00255 m.release();
00256 }
00257 template<class View>
00258 forceinline void
00259 ViewTracer<View>::_fix(const Space& home,
00260 const ViewTraceRecorder<View>& t) {
00261 m.acquire();
00262 fix(home,t);
00263 m.release();
00264 }
00265 template<class View>
00266 forceinline void
00267 ViewTracer<View>::_done(const Space& home,
00268 const ViewTraceRecorder<View>& t) {
00269 m.acquire();
00270 done(home,t);
00271 m.release();
00272 }
00273
00274 template<class View>
00275 forceinline
00276 ViewTracer<View>::~ViewTracer(void) {
00277 }
00278
00279
00280
00281
00282
00283
00284 forceinline
00285 Tracer::Tracer(void) {
00286 }
00287
00288 forceinline void
00289 Tracer::_propagate(const Space& home,
00290 const PropagateTraceInfo& pti) {
00291 m.acquire();
00292 propagate(home,pti);
00293 m.release();
00294 }
00295 forceinline void
00296 Tracer::_commit(const Space& home,
00297 const CommitTraceInfo& cti) {
00298 m.acquire();
00299 commit(home,cti);
00300 m.release();
00301 }
00302
00303 forceinline
00304 Tracer::~Tracer(void) {
00305 }
00306
00307 }
00308
00309