]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/private/error.h
Add a private wrapper for GError to wxGTK.
[wxWidgets.git] / include / wx / gtk / private / error.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/private/error.h
3 // Purpose: Wrapper around GError.
4 // Author: Vadim Zeitlin
5 // Created: 2012-07-25
6 // RCS-ID: $Id$
7 // Copyright: (c) 2012 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GTK_PRIVATE_ERROR_H_
12 #define _WX_GTK_PRIVATE_ERROR_H_
13
14 // ----------------------------------------------------------------------------
15 // wxGtkError wraps GError and releases it automatically.
16 // ----------------------------------------------------------------------------
17
18 // Create an object of this class and pass the result of its Out() method to a
19 // function taking "GError**", then use GetMessage() if the function returned
20 // false.
21 class wxGtkError
22 {
23 public:
24 wxGtkError() { m_error = NULL; }
25 ~wxGtkError() { if ( m_error ) g_error_free(m_error); }
26
27 GError** Out()
28 {
29 // This would result in a GError leak.
30 wxASSERT_MSG( !m_error, wxS("Can't reuse the same object.") );
31
32 return &m_error;
33 }
34
35 wxString GetMessage() const
36 {
37 return wxString::FromUTF8(m_error->message);
38 }
39
40 private:
41 GError* m_error;
42
43 wxDECLARE_NO_COPY_CLASS(wxGtkError);
44 };
45
46 #endif // _WX_GTK_PRIVATE_ERROR_H_