22#pragma clang diagnostic warning "-W#warnings"
26#pragma GCC diagnostic warning "-Wcpp"
27#pragma GCC diagnostic ignored "-Wnoexcept-type"
38 RefHolder(T& ref) : ref_(ref) {}
45 RefHolder& operator=(
const RefHolder&);
55class ScopeGuardImplBase
57 ScopeGuardImplBase& operator =(
const ScopeGuardImplBase&);
63 ScopeGuardImplBase(
const ScopeGuardImplBase& other)
throw()
64 : dismissed_(other.dismissed_)
70 static void SafeExecute(J& j)
throw()
82 mutable bool dismissed_;
84 ScopeGuardImplBase()
throw() : dismissed_(
false)
87 void Dismiss()
const throw()
97class ScopeGuardImpl0 :
public ScopeGuardImplBase
100 static ScopeGuardImpl0<F> MakeGuard(F fun)
102 return ScopeGuardImpl0<F>(fun);
104 ~ScopeGuardImpl0()
throw()
113 ScopeGuardImpl0(F fun) : fun_(fun)
123 return ScopeGuardImpl0<F>::MakeGuard(fun);
127template <
typename F,
typename P1>
128class ScopeGuardImpl1 :
public ScopeGuardImplBase
131 static ScopeGuardImpl1<F, P1> MakeGuard(F fun, P1 p1)
133 return ScopeGuardImpl1<F, P1>(fun, p1);
135 ~ScopeGuardImpl1()
throw()
144 ScopeGuardImpl1(F fun, P1 p1) : fun_(fun), p1_(p1)
152template <
typename F,
typename P1>
155 return ScopeGuardImpl1<F, P1>::MakeGuard(fun, p1);
159template <
typename F,
typename P1,
typename P2>
160class ScopeGuardImpl2:
public ScopeGuardImplBase
163 static ScopeGuardImpl2<F, P1, P2> MakeGuard(F fun, P1 p1, P2 p2)
165 return ScopeGuardImpl2<F, P1, P2>(fun, p1, p2);
167 ~ScopeGuardImpl2()
throw()
176 ScopeGuardImpl2(F fun, P1 p1, P2 p2) : fun_(fun), p1_(p1), p2_(p2)
185template <
typename F,
typename P1,
typename P2>
188 return ScopeGuardImpl2<F, P1, P2>::MakeGuard(fun, p1, p2);
192template <
typename F,
typename P1,
typename P2,
typename P3>
193class ScopeGuardImpl3 :
public ScopeGuardImplBase
196 static ScopeGuardImpl3<F, P1, P2, P3> MakeGuard(F fun, P1 p1, P2 p2, P3 p3)
198 return ScopeGuardImpl3<F, P1, P2, P3>(fun, p1, p2, p3);
200 ~ScopeGuardImpl3()
throw()
209 ScopeGuardImpl3(F fun, P1 p1, P2 p2, P3 p3) : fun_(fun), p1_(p1), p2_(p2), p3_(p3)
218template <
typename F,
typename P1,
typename P2,
typename P3>
221 return ScopeGuardImpl3<F, P1, P2, P3>::MakeGuard(fun, p1, p2, p3);
227template <
class Obj,
typename MemFun>
228class ObjScopeGuardImpl0 :
public ScopeGuardImplBase
231 static ObjScopeGuardImpl0<Obj, MemFun> MakeObjGuard(Obj& obj, MemFun memFun)
233 return ObjScopeGuardImpl0<Obj, MemFun>(obj, memFun);
235 ~ObjScopeGuardImpl0()
throw()
244 ObjScopeGuardImpl0(Obj& obj, MemFun memFun)
245 : obj_(obj), memFun_(memFun) {}
250template <
class Obj,
typename MemFun>
253 return ObjScopeGuardImpl0<Obj, MemFun>::MakeObjGuard(obj, memFun);
257template <
class Obj,
typename MemFun,
typename P1>
258class ObjScopeGuardImpl1 :
public ScopeGuardImplBase
261 static ObjScopeGuardImpl1<Obj, MemFun, P1> MakeObjGuard(Obj& obj, MemFun memFun, P1 p1)
263 return ObjScopeGuardImpl1<Obj, MemFun, P1>(obj, memFun, p1);
265 ~ObjScopeGuardImpl1()
throw()
271 (obj_.*memFun_)(p1_);
274 ObjScopeGuardImpl1(Obj& obj, MemFun memFun, P1 p1)
275 : obj_(obj), memFun_(memFun), p1_(p1) {}
281template <
class Obj,
typename MemFun,
typename P1>
284 return ObjScopeGuardImpl1<Obj, MemFun, P1>::MakeObjGuard(obj, memFun, p1);
288template <
class Obj,
typename MemFun,
typename P1,
typename P2>
289class ObjScopeGuardImpl2 :
public ScopeGuardImplBase
292 static ObjScopeGuardImpl2<Obj, MemFun, P1, P2> MakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2)
294 return ObjScopeGuardImpl2<Obj, MemFun, P1, P2>(obj, memFun, p1, p2);
296 ~ObjScopeGuardImpl2()
throw()
302 (obj_.*memFun_)(p1_, p2_);
305 ObjScopeGuardImpl2(Obj& obj, MemFun memFun, P1 p1, P2 p2)
306 : obj_(obj), memFun_(memFun), p1_(p1), p2_(p2) {}
313template <
class Obj,
typename MemFun,
typename P1,
typename P2>
316 return ObjScopeGuardImpl2<Obj, MemFun, P1, P2>::MakeObjGuard(obj, memFun, p1, p2);
319#define CONCATENATE_DIRECT(s1, s2) s1##s2
320#define CONCATENATE(s1, s2) CONCATENATE_DIRECT(s1, s2)
321#define ANONYMOUS_VARIABLE(str) CONCATENATE(str, __LINE__)
324# define UNUSED_VARIABLE __attribute__((unused))
326# define UNUSED_VARIABLE
329#define ON_BLOCK_EXIT ScopeGuard UNUSED_VARIABLE ANONYMOUS_VARIABLE(scopeGuard) = MakeGuard
330#define ON_BLOCK_EXIT_OBJ ScopeGuard UNUSED_VARIABLE ANONYMOUS_VARIABLE(scopeGuard) = MakeObjGuard
scope guard class
Definition ScopeGuard.h:229
scope guard class
Definition ScopeGuard.h:259
scope guard class
Definition ScopeGuard.h:290
templated class for ScopeGuard to hold a c++ reference
Definition ScopeGuard.h:35
scope guard class
Definition ScopeGuard.h:98
scope guard class
Definition ScopeGuard.h:129
scope guard class
Definition ScopeGuard.h:161
scope guard class
Definition ScopeGuard.h:194
scope guard class
Definition ScopeGuard.h:56