]> git.saurik.com Git - wxWidgets.git/commitdiff
added convenient wxON_BLOCK_EXIT_THISn() macros wrapping wxON_BLOCK_EXIT_OBJn(*this)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 27 Mar 2008 15:37:41 +0000 (15:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 27 Mar 2008 15:37:41 +0000 (15:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52856 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/scopeguard.h
interface/scopeguard.h
tests/scopeguard/scopeguardtest.cpp

index f1f5a8204c4c7e9406468a57a844625c9a79caf0..fb756c56bfcfcd1bd4503f1fc908f7f02103a166 100644 (file)
@@ -346,6 +346,10 @@ typedef const wxScopeGuardImplBase& wxScopeGuard;
 #define wxON_BLOCK_EXIT_OBJ0(o, m) \
     wxON_BLOCK_EXIT_OBJ0_IMPL(wxGuardName, o, &m)
 
+#define wxON_BLOCK_EXIT_THIS0(m) \
+    wxON_BLOCK_EXIT_OBJ0(*this, m)
+
+
 #define wxON_BLOCK_EXIT1_IMPL(n, f, p1) \
     wxScopeGuard n = wxMakeGuard(f, p1); \
     wxPrivateUse(n)
@@ -358,6 +362,10 @@ typedef const wxScopeGuardImplBase& wxScopeGuard;
 #define wxON_BLOCK_EXIT_OBJ1(o, m, p1) \
     wxON_BLOCK_EXIT_OBJ1_IMPL(wxGuardName, o, &m, p1)
 
+#define wxON_BLOCK_EXIT_THIS1(m, p1) \
+    wxON_BLOCK_EXIT_OBJ1(*this, m, p1)
+
+
 #define wxON_BLOCK_EXIT2_IMPL(n, f, p1, p2) \
     wxScopeGuard n = wxMakeGuard(f, p1, p2); \
     wxPrivateUse(n)
@@ -370,4 +378,7 @@ typedef const wxScopeGuardImplBase& wxScopeGuard;
 #define wxON_BLOCK_EXIT_OBJ2(o, m, p1, p2) \
     wxON_BLOCK_EXIT_OBJ2_IMPL(wxGuardName, o, &m, p1, p2)
 
+#define wxON_BLOCK_EXIT_THIS2(m, p1, p2) \
+    wxON_BLOCK_EXIT_OBJ2(*this, m, p1, p2)
+
 #endif // _WX_SCOPEGUARD_H_
index 495ed93199e87a02538076bafe7785845a087257..84002945cc34d189ec31f8bdb362aab95d59ea93 100644 (file)
 #define wxON_BLOCK_EXIT_OBJ2(object, method, p1, p2)
 //@}
 
+/** @ingroup group_funcmacro_misc */
+//@{
+/**
+    This family of macros is similar to wxON_BLOCK_OBJ0(), but calls a method
+    of @c this object instead of a method of the specified object.
+
+    @header{wx/scopeguard.h}
+*/
+#define wxON_BLOCK_EXIT_THIS0(method)
+#define wxON_BLOCK_EXIT_THIS1(method, p1)
+#define wxON_BLOCK_EXIT_THIS2(method, p1, p2)
+//@}
+
index e6a20c2473dd2861330944fafc36a6133e5d5c70..977e316af29c8237a7f85b5432742f123ec9e8ec 100644 (file)
@@ -60,12 +60,21 @@ public:
         CPPUNIT_TEST(Dismiss);
         CPPUNIT_TEST(BlockExit);
         CPPUNIT_TEST(BlockExitObj);
+        CPPUNIT_TEST(BlockExitThis);
     CPPUNIT_TEST_SUITE_END();
 
     void Normal();
     void Dismiss();
     void BlockExit();
     void BlockExitObj();
+    void BlockExitThis();
+
+private:
+    void Zero() { m_count = 0; }
+    void Set(int n) { m_count = n; }
+    void Sum(int n, int m) { m_count = n + m; }
+
+    int m_count;
 };
 
 // register in the unnamed registry so that these tests are run by default
@@ -172,3 +181,28 @@ void ScopeGuardTestCase::BlockExitObj()
     CPPUNIT_ASSERT_EQUAL( 5, count2.GetCount() );
 }
 
+void ScopeGuardTestCase::BlockExitThis()
+{
+    m_count = 1;
+
+    {
+        wxON_BLOCK_EXIT_THIS0(ScopeGuardTestCase::Zero);
+
+        CPPUNIT_ASSERT_EQUAL( 1, m_count );
+    }
+    CPPUNIT_ASSERT_EQUAL( 0, m_count );
+
+    {
+        wxON_BLOCK_EXIT_THIS1(ScopeGuardTestCase::Set, 17);
+
+        CPPUNIT_ASSERT_EQUAL( 0, m_count );
+    }
+    CPPUNIT_ASSERT_EQUAL( 17, m_count );
+
+    {
+        wxON_BLOCK_EXIT_THIS2(ScopeGuardTestCase::Sum, 2, 3);
+        CPPUNIT_ASSERT_EQUAL( 17, m_count );
+    }
+    CPPUNIT_ASSERT_EQUAL( 5, m_count );
+}
+