Changeset 56194
- Timestamp:
- 10/09/08 04:26:50 (6 weeks ago)
- Location:
- wxWidgets/trunk
- Files:
-
- 2 modified
-
include/wx/scopeguard.h (modified) (3 diffs)
-
interface/wx/scopeguard.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wxWidgets/trunk/include/wx/scopeguard.h
r52857 r56194 227 227 } 228 228 229 // ---------------------------------------------------------------------------- 230 // wxScopeGuardImpl3: scope guard for actions with 3 parameters 231 // ---------------------------------------------------------------------------- 232 233 template <class F, class P1, class P2, class P3> 234 class wxScopeGuardImpl3 : public wxScopeGuardImplBase 235 { 236 public: 237 static wxScopeGuardImpl3<F, P1, P2, P3> MakeGuard(F fun, P1 p1, P2 p2, P3 p3) 238 { 239 return wxScopeGuardImpl3<F, P1, P2, P3>(fun, p1, p2, p3); 240 } 241 242 ~wxScopeGuardImpl3() { wxPrivateOnScopeExit(*this); } 243 244 void Execute() { m_fun(m_p1, m_p2, m_p3); } 245 246 protected: 247 wxScopeGuardImpl3(F fun, P1 p1, P2 p2, P3 p3) 248 : m_fun(fun), m_p1(p1), m_p2(p2), m_p3(p3) { } 249 250 F m_fun; 251 const P1 m_p1; 252 const P2 m_p2; 253 const P3 m_p3; 254 255 wxScopeGuardImpl3& operator=(const wxScopeGuardImpl3&); 256 }; 257 258 template <class F, class P1, class P2, class P3> 259 inline wxScopeGuardImpl3<F, P1, P2, P3> wxMakeGuard(F fun, P1 p1, P2 p2, P3 p3) 260 { 261 return wxScopeGuardImpl3<F, P1, P2, P3>::MakeGuard(fun, p1, p2, p3); 262 } 263 229 264 // ============================================================================ 230 265 // wxScopeGuards for object methods … … 323 358 return wxObjScopeGuardImpl2<Obj, MemFun, P1, P2>:: 324 359 MakeObjGuard(obj, memFun, p1, p2); 360 } 361 362 template <class Obj, class MemFun, class P1, class P2, class P3> 363 class wxObjScopeGuardImpl3 : public wxScopeGuardImplBase 364 { 365 public: 366 static wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3> 367 MakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2, P3 p3) 368 { 369 return wxObjScopeGuardImpl3<Obj, MemFun, P1, P3>(obj, memFun, p1, p2, p3); 370 } 371 372 ~wxObjScopeGuardImpl3() { wxPrivateOnScopeExit(*this); } 373 374 void Execute() { (m_obj.*m_memfun)(m_p1, m_p2, m_p3); } 375 376 protected: 377 wxObjScopeGuardImpl3(Obj& obj, MemFun memFun, P1 p1, P2 p2, P3 p3) 378 : m_obj(obj), m_memfun(memFun), m_p1(p1), m_p2(p2), m_p3(p3) { } 379 380 Obj& m_obj; 381 MemFun m_memfun; 382 const P1 m_p1; 383 const P2 m_p2; 384 const P3 m_p3; 385 }; 386 387 template <class Obj, class MemFun, class P1, class P2, class P3> 388 inline wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3> 389 wxMakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2, P3 p3) 390 { 391 return wxObjScopeGuardImpl3<Obj, MemFun, P1, P2, P3>:: 392 MakeObjGuard(obj, memFun, p1, p2, p3); 325 393 } 326 394 … … 466 534 467 535 536 #define wxON_BLOCK_EXIT3_IMPL(n, f, p1, p2, p3) \ 537 wxScopeGuard n = wxMakeGuard(f, p1, p2, p3); \ 538 wxPrivateUse(n) 539 #define wxON_BLOCK_EXIT3(f, p1, p2, p3) \ 540 wxON_BLOCK_EXIT3_IMPL(wxGuardName, f, p1, p2, p3) 541 542 #define wxON_BLOCK_EXIT_OBJ3_IMPL(n, o, m, p1, p2, p3) \ 543 wxScopeGuard n = wxMakeObjGuard(o, m, p1, p2, p3); \ 544 wxPrivateUse(n) 545 #define wxON_BLOCK_EXIT_OBJ3(o, m, p1, p2, p3) \ 546 wxON_BLOCK_EXIT_OBJ3_IMPL(wxGuardName, o, &m, p1, p2, p3) 547 548 #define wxON_BLOCK_EXIT_THIS3(m, p1, p2, p3) \ 549 wxON_BLOCK_EXIT_OBJ3(*this, m, p1, p2, p3) 550 551 468 552 #define wxSetterName wxMAKE_UNIQUE_NAME(wxVarSetter) 469 553 -
wxWidgets/trunk/interface/wx/scopeguard.h
r54385 r56194 7 7 ///////////////////////////////////////////////////////////////////////////// 8 8 9 /** 10 Scope guard is an object which allows executing an action on scope exit. 11 12 The objects of this class must be constructed using wxMakeGuard() function. 13 */ 14 class wxScopeGuard 15 { 16 public: 17 /** 18 Call this method to dismiss the execution of the action on scope exit. 19 20 A typical example: 21 @code 22 Update1(); 23 24 // ensure that changes done so far are rolled back if the next 25 // operation throws 26 wxScopeGuard guard = wxMakeGuard(RollBack); 27 Update2(); 28 29 // it didn't throw so commit the changes, i.e. avoid rolling back 30 guard.Dismiss(); 31 @endcode 32 */ 33 void Dismiss(); 34 }; 35 9 36 /** @ingroup group_funcmacro_misc */ 10 37 //@{ 11 38 /** 12 This macro ensures that the global @a function with 0, 1, 2 or more 13 parameters (up to some implementation-defined limit) is executed on scope 14 exit, whether due to a normal function return or because an exception has 15 been thrown. A typical example of its usage: 39 Returns a scope guard object which will call the specified function with 40 the given parameters on scope exit. 41 42 This function is overloaded to take several parameters up to some 43 implementation-defined (but relatively low) limit. 44 45 The @a func should be a functor taking parameters of the types P1, ..., PN, 46 i.e. the expression @c func(p1, ..., pN) should be valid. 47 */ 48 template <typename F, typename P1, ..., typename PN> 49 wxScopeGuard wxMakeGuard(F func, P1 p1, ..., PN pN); 50 51 //@} 52 53 /** @ingroup group_funcmacro_misc */ 54 //@{ 55 /** 56 Ensure that the global @a function with a few (up to some 57 implementation-defined limit) is executed on scope exit, whether due to a 58 normal function return or because an exception has been thrown. 59 60 A typical example of its usage: 16 61 17 62 @code … … 27 72 @header{wx/scopeguard.h} 28 73 */ 74 #define wxON_BLOCK_EXIT(function, ...) 29 75 #define wxON_BLOCK_EXIT0(function) 30 76 #define wxON_BLOCK_EXIT1(function, p1) 31 77 #define wxON_BLOCK_EXIT2(function, p1, p2) 78 #define wxON_BLOCK_EXIT3(function, p1, p2, p3) 32 79 //@} 33 80 … … 35 82 //@{ 36 83 /** 37 This family of macros is similar to wxON_BLOCK_EXIT 0(), but calls a method84 This family of macros is similar to wxON_BLOCK_EXIT(), but calls a method 38 85 of the given object instead of a free function. 39 86 40 87 @header{wx/scopeguard.h} 41 88 */ 89 #define wxON_BLOCK_EXIT_OBJ(object, method, ...) 42 90 #define wxON_BLOCK_EXIT_OBJ0(object, method) 43 91 #define wxON_BLOCK_EXIT_OBJ1(object, method, p1) 44 92 #define wxON_BLOCK_EXIT_OBJ2(object, method, p1, p2) 93 #define wxON_BLOCK_EXIT_OBJ3(object, method, p1, p2, p3) 45 94 //@} 46 95 … … 48 97 //@{ 49 98 /** 50 This family of macros is similar to wxON_BLOCK_OBJ 0(), but calls a method99 This family of macros is similar to wxON_BLOCK_OBJ(), but calls a method 51 100 of @c this object instead of a method of the specified object. 52 101 53 102 @header{wx/scopeguard.h} 54 103 */ 104 #define wxON_BLOCK_EXIT_THIS(method, ...) 55 105 #define wxON_BLOCK_EXIT_THIS0(method) 56 106 #define wxON_BLOCK_EXIT_THIS1(method, p1) 57 107 #define wxON_BLOCK_EXIT_THIS2(method, p1, p2) 108 #define wxON_BLOCK_EXIT_THIS3(method, p1, p2, p3) 58 109 //@} 59 110
