trace-recorder.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 { namespace Search {
00035
00037 class WrapTraceRecorder {
00038 public:
00040 static void engine(SearchTracer* tracer,
00041 SearchTracer::EngineType t, unsigned int n);
00042 };
00043
00045 class TraceRecorder {
00046 protected:
00048 SearchTracer& tracer;
00050 unsigned int _eid;
00052 unsigned int _wid;
00054 unsigned int _nid;
00055 public:
00057 class ID {
00058 protected:
00060 unsigned int _id;
00061 public:
00063 ID(void);
00065 ID(unsigned int id);
00067 operator unsigned int(void) const;
00068 };
00070 TraceRecorder(SearchTracer* t);
00072 void engine(SearchTracer::EngineType t, unsigned int n);
00074 void worker(void);
00076 unsigned int nid(void);
00078 unsigned int wid(void) const;
00080 void round(void);
00082 void skip(const SearchTracer::EdgeInfo& ei);
00084 void node(const SearchTracer::EdgeInfo& ei,
00085 const SearchTracer::NodeInfo& ni);
00087 void done(void);
00089 operator bool(void) const;
00090 };
00091
00093 class EdgeTraceRecorder : public TraceRecorder {
00094 protected:
00096 SearchTracer::EdgeInfo _ei;
00097 public:
00099 EdgeTraceRecorder(SearchTracer* t);
00101 void invalidate(void);
00103 SearchTracer::EdgeInfo* ei(void);
00104 };
00105
00107 class NoTraceRecorder {
00108 public:
00110 class ID {
00111 public:
00113 ID(void);
00115 ID(unsigned int id);
00117 operator unsigned int(void) const;
00118 };
00120 NoTraceRecorder(SearchTracer* t);
00122 void engine(SearchTracer::EngineType t, unsigned int n);
00124 void worker(void);
00126 unsigned int wid(void) const;
00128 unsigned int nid(void);
00130 void invalidate(void);
00132 SearchTracer::EdgeInfo* ei(void);
00134 void round(void);
00136 void skip(const SearchTracer::EdgeInfo& ei);
00138 void node(const SearchTracer::EdgeInfo& ei,
00139 const SearchTracer::NodeInfo& ni);
00141 void done(void);
00143 operator bool(void) const;
00144 };
00145
00146
00147
00148
00149
00150
00151 forceinline void
00152 WrapTraceRecorder::engine(SearchTracer* tracer,
00153 SearchTracer::EngineType t, unsigned int n) {
00154 if (tracer) tracer->engine(t,n);
00155 }
00156
00157
00158
00159
00160
00161
00162 forceinline
00163 TraceRecorder::ID::ID(void) {}
00164
00165 forceinline
00166 TraceRecorder::ID::ID(unsigned int id) : _id(id) {}
00167
00168 forceinline
00169 TraceRecorder::ID::operator unsigned int(void) const {
00170 return _id;
00171 }
00172
00173 forceinline
00174 TraceRecorder::TraceRecorder(SearchTracer* t)
00175 : tracer(*t), _eid(0U), _wid(0U), _nid(0U) {}
00176
00177 forceinline void
00178 TraceRecorder::engine(SearchTracer::EngineType t, unsigned int n) {
00179 tracer.engine(t,n);
00180 }
00181
00182 forceinline void
00183 TraceRecorder::worker(void) {
00184 tracer.worker(_wid,_eid);
00185 }
00186
00187 forceinline unsigned int
00188 TraceRecorder::nid(void) {
00189 return _nid++;
00190 }
00191
00192 forceinline unsigned int
00193 TraceRecorder::wid(void) const {
00194 return _wid;
00195 }
00196
00197 forceinline void
00198 TraceRecorder::round(void) {
00199 tracer._round(_eid);
00200 }
00201
00202 forceinline void
00203 TraceRecorder::skip(const SearchTracer::EdgeInfo& ei) {
00204 tracer._skip(ei);
00205 }
00206
00207 forceinline void
00208 TraceRecorder::node(const SearchTracer::EdgeInfo& ei,
00209 const SearchTracer::NodeInfo& ni) {
00210 tracer._node(ei,ni);
00211 }
00212
00213 forceinline void
00214 TraceRecorder::done(void) {
00215 tracer.worker();
00216 }
00217
00218 forceinline
00219 TraceRecorder::operator bool(void) const {
00220 return true;
00221 }
00222
00223
00224
00225
00226
00227
00228 forceinline
00229 EdgeTraceRecorder::EdgeTraceRecorder(SearchTracer* t)
00230 : TraceRecorder(t) {}
00231
00232 forceinline void
00233 EdgeTraceRecorder::invalidate(void) {
00234 _ei.invalidate();
00235 }
00236
00237 forceinline SearchTracer::EdgeInfo*
00238 EdgeTraceRecorder::ei(void) {
00239 return &_ei;
00240 }
00241
00242
00243
00244
00245
00246
00247 forceinline
00248 NoTraceRecorder::ID::ID(void) {}
00249
00250 forceinline
00251 NoTraceRecorder::ID::ID(unsigned int) {}
00252
00253 forceinline
00254 NoTraceRecorder::ID::operator unsigned int(void) const {
00255 return 0U;
00256 }
00257
00258 forceinline
00259 NoTraceRecorder::NoTraceRecorder(SearchTracer*) {}
00260
00261 forceinline void
00262 NoTraceRecorder::engine(SearchTracer::EngineType, unsigned int) {}
00263
00264 forceinline void
00265 NoTraceRecorder::worker(void) {}
00266
00267 forceinline unsigned int
00268 NoTraceRecorder::wid(void) const {
00269 return 0U;
00270 }
00271
00272 forceinline unsigned int
00273 NoTraceRecorder::nid(void) {
00274 return 0U;
00275 }
00276
00277 forceinline void
00278 NoTraceRecorder::invalidate(void) {}
00279
00280 forceinline SearchTracer::EdgeInfo*
00281 NoTraceRecorder::ei(void) {
00282 return nullptr;
00283 }
00284
00285 forceinline void
00286 NoTraceRecorder::round(void) {}
00287
00288 forceinline void
00289 NoTraceRecorder::skip(const SearchTracer::EdgeInfo&) {}
00290
00291 forceinline void
00292 NoTraceRecorder::node(const SearchTracer::EdgeInfo&,
00293 const SearchTracer::NodeInfo&) {
00294 }
00295
00296 forceinline void
00297 NoTraceRecorder::done(void) {
00298 }
00299
00300 forceinline
00301 NoTraceRecorder::operator bool(void) const {
00302 return false;
00303 }
00304
00305 }}
00306
00307