]> git.saurik.com Git - wxWidgets.git/commitdiff
added tiny wxInitializer class
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 8 Jun 2001 23:11:15 +0000 (23:11 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 8 Jun 2001 23:11:15 +0000 (23:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10462 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/app.h

index c25f74ae29f91bbf717a12aabac422524a13ba21..2770a1c58eea47cbfcc9580f5790977acdfa791e 100644 (file)
@@ -351,6 +351,27 @@ extern bool WXDLLEXPORT wxInitialize();
 // wxUninitialize()
 extern void WXDLLEXPORT wxUninitialize();
 
+// create an object of this class on stack to initialize/cleanup thel ibrary
+// automatically
+class WXDLLEXPORT wxInitializer
+{
+public:
+    // initialize the library
+    wxInitializer() { m_ok = wxInitialize(); }
+
+    // has the initialization been successful? (explicit test)
+    bool IsOk() const { return m_ok; }
+
+    // has the initialization been successful? (implicit test)
+    operator bool() const { return m_ok; }
+
+    // dtor only does clean up if we initialized the library properly
+    ~wxInitializer() { if ( m_ok ) wxUninitialize(); }
+
+private:
+    bool m_ok;
+};
+
 #endif // !wxUSE_GUI
 
 // ----------------------------------------------------------------------------