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
00035
00036
00037
00038 namespace Gecode {
00039
00041 class TracerBase : public HeapAllocated {
00042 protected:
00044 GECODE_KERNEL_EXPORT
00045 static Support::Mutex m;
00046 };
00047
00048 template<class View> class ViewTraceRecorder;
00049
00054 template<class View>
00055 class ViewTracer : public TracerBase {
00056 template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
00057 private:
00064 void _init(const Space& home, const ViewTraceRecorder<View>& t);
00071 void _prune(const Space& home, const ViewTraceRecorder<View>& t,
00072 const ViewTraceInfo& vti,
00073 int i, typename TraceTraits<View>::TraceDelta& d);
00080 void _fail(const Space& home, const ViewTraceRecorder<View>& t);
00086 void _fix(const Space& home, const ViewTraceRecorder<View>& t);
00092 void _done(const Space& home, const ViewTraceRecorder<View>& t);
00093 public:
00095 ViewTracer(void);
00102 virtual void init(const Space& home,
00103 const ViewTraceRecorder<View>& t) = 0;
00113 virtual void prune(const Space& home,
00114 const ViewTraceRecorder<View>& t,
00115 const ViewTraceInfo& vti,
00116 int i, typename TraceTraits<View>::TraceDelta& d) = 0;
00123 virtual void fail(const Space& home,
00124 const ViewTraceRecorder<View>& t) = 0;
00132 virtual void fix(const Space& home,
00133 const ViewTraceRecorder<View>& t) = 0;
00140 virtual void done(const Space& home,
00141 const ViewTraceRecorder<View>& t) = 0;
00143 virtual ~ViewTracer(void);
00144 };
00145
00146
00147
00148
00153 class Tracer : public TracerBase {
00154 friend class Space;
00155 private:
00162 void _propagate(const Space& home, const PropagateTraceInfo& pti);
00169 void _commit(const Space& home, const CommitTraceInfo& cti);
00170 public:
00172 Tracer(void);
00179 virtual void propagate(const Space& home,
00180 const PropagateTraceInfo& pti) = 0;
00187 virtual void commit(const Space& home,
00188 const CommitTraceInfo& cti) = 0;
00190 virtual ~Tracer(void);
00191 };
00192
00193
00198 class GECODE_KERNEL_EXPORT StdTracer : public Tracer {
00199 protected:
00201 std::ostream& os;
00202 public:
00204 StdTracer(std::ostream& os0 = std::cerr);
00211 virtual void propagate(const Space& home,
00212 const PropagateTraceInfo& pti);
00219 virtual void commit(const Space& home,
00220 const CommitTraceInfo& cti);
00222 static StdTracer def;
00223 };
00224
00225
00226
00227
00228
00229
00230 template<class View>
00231 forceinline
00232 ViewTracer<View>::ViewTracer(void) {
00233 }
00234
00235 template<class View>
00236 forceinline void
00237 ViewTracer<View>::_init(const Space& home,
00238 const ViewTraceRecorder<View>& t) {
00239 m.acquire();
00240 init(home,t);
00241 m.release();
00242 }
00243 template<class View>
00244 forceinline void
00245 ViewTracer<View>::_prune(const Space& home,
00246 const ViewTraceRecorder<View>& t,
00247 const ViewTraceInfo& vti,
00248 int i, typename TraceTraits<View>::TraceDelta& d) {
00249 m.acquire();
00250 prune(home,t,vti,i,d);
00251 m.release();
00252 }
00253 template<class View>
00254 forceinline void
00255 ViewTracer<View>::_fail(const Space& home,
00256 const ViewTraceRecorder<View>& t) {
00257 m.acquire();
00258 fail(home,t);
00259 m.release();
00260 }
00261 template<class View>
00262 forceinline void
00263 ViewTracer<View>::_fix(const Space& home,
00264 const ViewTraceRecorder<View>& t) {
00265 m.acquire();
00266 fix(home,t);
00267 m.release();
00268 }
00269 template<class View>
00270 forceinline void
00271 ViewTracer<View>::_done(const Space& home,
00272 const ViewTraceRecorder<View>& t) {
00273 m.acquire();
00274 done(home,t);
00275 m.release();
00276 }
00277
00278 template<class View>
00279 forceinline
00280 ViewTracer<View>::~ViewTracer(void) {
00281 }
00282
00283
00284
00285
00286
00287
00288 forceinline
00289 Tracer::Tracer(void) {
00290 }
00291
00292 forceinline void
00293 Tracer::_propagate(const Space& home,
00294 const PropagateTraceInfo& pti) {
00295 m.acquire();
00296 propagate(home,pti);
00297 m.release();
00298 }
00299 forceinline void
00300 Tracer::_commit(const Space& home,
00301 const CommitTraceInfo& cti) {
00302 m.acquire();
00303 commit(home,cti);
00304 m.release();
00305 }
00306
00307 forceinline
00308 Tracer::~Tracer(void) {
00309 }
00310
00311 }
00312
00313