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() {
153template <
typename F,
typename P1>
175template <
typename F,
typename P1>
180template <
typename F,
typename P1,
typename P2>
203template <
typename F,
typename P1,
typename P2>
208template <
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) {}
232template <
typename F,
typename P1,
typename P2,
typename P3>
239template <
class Obj,
typename MemFun>
261template <
class Obj,
typename MemFun>
266template <
typename Ret,
class Obj1,
class Obj2>
267inline ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()> MakeGuard(Ret (Obj2::*memFun)(), Obj1& obj) {
268 return ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()>::MakeObjGuard(obj, memFun);
271template <
typename Ret,
class Obj1,
class Obj2>
272inline ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()> MakeGuard(Ret (Obj2::*memFun)(), Obj1* obj) {
273 return ObjScopeGuardImpl0<Obj1, Ret (Obj2::*)()>::MakeObjGuard(*obj, memFun);
276template <
class Obj,
typename MemFun,
typename P1>
288 (obj_.*memFun_)(p1_);
292 ObjScopeGuardImpl1(Obj& obj, MemFun memFun, P1 p1) : obj_(obj), memFun_(memFun), p1_(p1) {}
299template <
class Obj,
typename MemFun,
typename P1>
304template <
typename Ret,
class Obj1,
class Obj2,
typename P1a,
typename P1b>
305inline ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b> MakeGuard(Ret (Obj2::*memFun)(P1a),
308 return ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b>::MakeObjGuard(obj, memFun, p1);
311template <
typename Ret,
class Obj1,
class Obj2,
typename P1a,
typename P1b>
312inline ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b> MakeGuard(Ret (Obj2::*memFun)(P1a),
315 return ObjScopeGuardImpl1<Obj1, Ret (Obj2::*)(P1a), P1b>::MakeObjGuard(*obj, memFun, p1);
318template <
class Obj,
typename MemFun,
typename P1,
typename P2>
333 (obj_.*memFun_)(p1_, p2_);
338 : obj_(obj), memFun_(memFun), p1_(p1), p2_(p2) {}
346template <
class Obj,
typename MemFun,
typename P1,
typename P2>
351template <
typename Ret,
358inline 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);
364template <
typename Ret,
371inline 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
Definition scopeguard.h:240
Definition scopeguard.h:277
Definition scopeguard.h:319
Transports a reference as a value Serves to implement the Colvin/Gibbons trick for SmartPtr/ScopeGuar...
Definition scopeguard.h:30
Definition scopeguard.h:128
Definition scopeguard.h:154
Definition scopeguard.h:181
Definition scopeguard.h:209
ScopeGuard.
Definition scopeguard.h:85
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20
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