15 #ifndef LOKI_SCOPEGUARD_H_
16 #define LOKI_SCOPEGUARD_H_
18 #include "mongo/platform/compiler.h"
96 static void SafeExecute(J& j)
throw() {
104 mutable bool dismissed_;
109 void Dismiss()
const throw() {
127 template <
typename F>
148 template <
typename F>
153 template <
typename F,
typename P1>
175 template <
typename F,
typename P1>
180 template <
typename F,
typename P1,
typename P2>
203 template <
typename F,
typename P1,
typename P2>
208 template <
typename F,
typename P1,
typename P2,
typename P3>
224 ScopeGuardImpl3(F fun, P1 p1, P2 p2, P3 p3) : fun_(fun), p1_(p1), p2_(p2), p3_(p3) {}
232 template <
typename F,
typename P1,
typename P2,
typename P3>
239 template <
class Obj,
typename MemFun>
261 template <
class Obj,
typename MemFun>
266 template <
typename Ret,
class Obj1,
class Obj2>
267 inline ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()> MakeGuard(Ret (Obj2::*memFun)(), Obj1& obj) {
268 return ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()>::MakeObjGuard(obj, memFun);
271 template <
typename Ret,
class Obj1,
class Obj2>
272 inline ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()> MakeGuard(Ret (Obj2::*memFun)(), Obj1* obj) {
273 return ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()>::MakeObjGuard(*obj, memFun);
276 template <
class Obj,
typename MemFun,
typename P1>
288 (obj_.*memFun_)(p1_);
292 ObjScopeGuardImpl1(Obj& obj, MemFun memFun, P1 p1) : obj_(obj), memFun_(memFun), p1_(p1) {}
299 template <
class Obj,
typename MemFun,
typename P1>
304 template <
typename Ret,
class Obj1,
class Obj2,
typename P1a,
typename P1b>
305 inline ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b> MakeGuard(Ret (Obj2::*memFun)(P1a),
308 return ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b>::MakeObjGuard(obj, memFun, p1);
311 template <
typename Ret,
class Obj1,
class Obj2,
typename P1a,
typename P1b>
312 inline ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b> MakeGuard(Ret (Obj2::*memFun)(P1a),
315 return ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b>::MakeObjGuard(*obj, memFun, p1);
318 template <
class Obj,
typename MemFun,
typename P1,
typename P2>
333 (obj_.*memFun_)(p1_, p2_);
338 : obj_(obj), memFun_(memFun), p1_(p1), p2_(p2) {}
346 template <
class Obj,
typename MemFun,
typename P1,
typename P2>
351 template <
typename Ret,
358 inline ObjScopeGuardImpl2<Obj1, Ret (Obj2::*)(P1a, P2a), P1b, P2b> MakeGuard(
359 Ret (Obj2::*memFun)(P1a, P2a), Obj1& obj, P1b p1, P2b p2) {
360 return ObjScopeGuardImpl2<Obj1, Ret (Obj2::*)(P1a, P2a), P1b, P2b>::MakeObjGuard(
361 obj, memFun, p1, p2);
364 template <
typename Ret,
371 inline ObjScopeGuardImpl2<Obj1, Ret (Obj2::*)(P1a, P2a), P1b, P2b> MakeGuard(
372 Ret (Obj2::*memFun)(P1a, P2a), Obj1* obj, P1b p1, P2b p2) {
373 return ObjScopeGuardImpl2<Obj1, Ret (Obj2::*)(P1a, P2a), P1b, P2b>::MakeObjGuard(
374 *obj, memFun, p1, p2);
379 #define LOKI_CONCATENATE_DIRECT(s1, s2) s1##s2
380 #define LOKI_CONCATENATE(s1, s2) LOKI_CONCATENATE_DIRECT(s1, s2)
381 #define LOKI_ANONYMOUS_VARIABLE(str) LOKI_CONCATENATE(str, __LINE__)
383 #define ON_BLOCK_EXIT \
384 MONGO_COMPILER_VARIABLE_UNUSED ScopeGuard LOKI_ANONYMOUS_VARIABLE(scopeGuard) = MakeGuard
385 #define ON_BLOCK_EXIT_OBJ \
386 MONGO_COMPILER_VARIABLE_UNUSED ScopeGuard LOKI_ANONYMOUS_VARIABLE(scopeGuard) = MakeObjGuard
388 #endif // LOKI_SCOPEGUARD_H_
Definition: scopeguard.h:277
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Definition: scopeguard.h:128
RefToValue< T > ByRef(T &t)
RefToValue creator.
Definition: scopeguard.h:54
const ScopeGuardImplBase & ScopeGuard
See Andrei's and Petru Marginean's CUJ article http://www.cuj.com/documents/s=8000/cujcexp1812alexand...
Definition: scopeguard.h:125
Transports a reference as a value Serves to implement the Colvin/Gibbons trick for SmartPtr/ScopeGuar...
Definition: scopeguard.h:30
Definition: scopeguard.h:240
Definition: scopeguard.h:181
ScopeGuard.
Definition: scopeguard.h:85
Definition: scopeguard.h:209
Definition: scopeguard.h:154
Definition: scopeguard.h:319