X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c66cca2af072daf7abe63f784038cbd9125ca4bd..d24b23b76eca69c0faecf6146f52f6d8f93d4b78:/include/wx/scopeguard.h diff --git a/include/wx/scopeguard.h b/include/wx/scopeguard.h index 2b794dc43f..c46f443569 100644 --- a/include/wx/scopeguard.h +++ b/include/wx/scopeguard.h @@ -5,7 +5,7 @@ // Modified by: // Created: 03.07.2003 // RCS-ID: $Id$ -// Copyright: (c) 2003 Vadim Zeitlin +// Copyright: (c) 2003 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -20,6 +20,8 @@ #include "wx/defs.h" +#include "wx/except.h" + // ---------------------------------------------------------------------------- // helpers // ---------------------------------------------------------------------------- @@ -30,22 +32,16 @@ namespace wxPrivate // ScopeGuardImplBase but gcc 2.8 which is still used for OS/2 doesn't // support member templates and so we must make it global template - void OnScopeExit(ScopeGuardImpl& guard) + void OnScopeExit(ScopeGuardImpl& guard) { if ( !guard.WasDismissed() ) { // we're called from ScopeGuardImpl dtor and so we must not throw -#if wxUSE_EXCEPTIONS - try -#endif // wxUSE_EXCEPTIONS + wxTRY { guard.Execute(); } -#if wxUSE_EXCEPTIONS - catch ( ... ) - { - } -#endif // wxUSE_EXCEPTIONS + wxCATCH_ALL(;) // do nothing, just eat the exception } } @@ -55,7 +51,7 @@ namespace wxPrivate { } } // namespace wxPrivate - + // ============================================================================ // wxScopeGuard for functions and functors // ============================================================================ @@ -77,7 +73,7 @@ public: protected: ~wxScopeGuardImplBase() { } - wxScopeGuardImplBase(const wxScopeGuardImplBase& other) + wxScopeGuardImplBase(const wxScopeGuardImplBase& other) : m_wasDismissed(other.m_wasDismissed) { other.Dismiss(); @@ -115,7 +111,7 @@ protected: wxScopeGuardImpl0& operator=(const wxScopeGuardImpl0&); }; -template +template inline wxScopeGuardImpl0 wxMakeGuard(F fun) { return wxScopeGuardImpl0::MakeGuard(fun); @@ -147,7 +143,7 @@ protected: wxScopeGuardImpl1& operator=(const wxScopeGuardImpl1&); }; -template +template inline wxScopeGuardImpl1 wxMakeGuard(F fun, P1 p1) { return wxScopeGuardImpl1::MakeGuard(fun, p1); @@ -237,7 +233,7 @@ public: void Execute() { (m_obj.*m_memfun)(m_p1); } protected: - wxObjScopeGuardImpl1(Obj& obj, MemFun memFun, P1 p1) + wxObjScopeGuardImpl1(Obj& obj, MemFun memFun, P1 p1) : m_obj(obj), m_memfun(memFun), m_p1(p1) { } Obj& m_obj; @@ -267,7 +263,7 @@ public: void Execute() { (m_obj.*m_memfun)(m_p1, m_p2); } protected: - wxObjScopeGuardImpl2(Obj& obj, MemFun memFun, P1 p1, P2 p2) + wxObjScopeGuardImpl2(Obj& obj, MemFun memFun, P1 p1, P2 p2) : m_obj(obj), m_memfun(memFun), m_p1(p1), m_p2(p2) { } Obj& m_obj; @@ -297,27 +293,27 @@ typedef const wxScopeGuardImplBase& wxScopeGuard; // but this results in compiler warnings about unused variables and I // didn't find a way to work around this other than by having different // macros with different names -#define ON_BLOCK_EXIT0(f) \ +#define wxON_BLOCK_EXIT0(f) \ wxScopeGuard wxMAKE_UNIQUE_NAME(scopeGuard) = wxMakeGuard(f); \ wxPrivate::Use(wxMAKE_UNIQUE_NAME(scopeGuard)) -#define ON_BLOCK_EXIT_OBJ0(o, m) \ +#define wxON_BLOCK_EXIT_OBJ0(o, m) \ wxScopeGuard wxMAKE_UNIQUE_NAME(scopeGuard) = wxMakeObjGuard(o, m); \ wxPrivate::Use(wxMAKE_UNIQUE_NAME(scopeGuard)) -#define ON_BLOCK_EXIT1(f, p1) \ +#define wxON_BLOCK_EXIT1(f, p1) \ wxScopeGuard wxMAKE_UNIQUE_NAME(scopeGuard) = wxMakeGuard(f, p1); \ wxPrivate::Use(wxMAKE_UNIQUE_NAME(scopeGuard)) -#define ON_BLOCK_EXIT_OBJ1(o, m, p1) \ +#define wxON_BLOCK_EXIT_OBJ1(o, m, p1) \ wxScopeGuard wxMAKE_UNIQUE_NAME(scopeGuard) = wxMakeObjGuard(o, m, p1); \ wxPrivate::Use(wxMAKE_UNIQUE_NAME(scopeGuard)) -#define ON_BLOCK_EXIT2(f, p1, p2) \ +#define wxON_BLOCK_EXIT2(f, p1, p2) \ wxScopeGuard wxMAKE_UNIQUE_NAME(scopeGuard) = wxMakeGuard(f, p1, p2); \ wxPrivate::Use(wxMAKE_UNIQUE_NAME(scopeGuard)) -#define ON_BLOCK_EXIT_OBJ2(o, m, p1, p2) \ +#define wxON_BLOCK_EXIT_OBJ2(o, m, p1, p2) \ wxScopeGuard wxMAKE_UNIQUE_NAME(scopeGuard) = wxMakeObjGuard(o, m, p1, p2); \ wxPrivate::Use(wxMAKE_UNIQUE_NAME(scopeGuard))