c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

gerror_handle.h
Go to the documentation of this file.
1 /* Copyright (C) 2007 and 2009 Chris Vine
2
3 The library comprised in this file or of which this file is part is
4 distributed by Chris Vine under the GNU Lesser General Public
5 License as follows:
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public License
9 as published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License, version 2.1, for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License, version 2.1, along with this library (see the file LGPL.TXT
19 which came with this source code package in the c++-gtk-utils
20 sub-directory); if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23 */
24
25 #ifndef CGU_GERROR_HANDLE_H
26 #define CGU_GERROR_HANDLE_H
27
28 #include <glib.h>
29 #include <c++-gtk-utils/shared_handle.h>
30 #include <c++-gtk-utils/cgu_config.h>
31
32 /**
33 * @addtogroup handles handles and smart pointers
34 */
35
36 namespace Cgu {
37
38 /**
39 * @class GerrorFree gerror_handle.h c++-gtk-utils/gerror_handle.h
40 * @brief A deleter functor for use as the second (Dealloc) template
41 * parameter of the SharedHandle, SharedLockHandle or ScopedHandle
42 * template classes, which calls glib's g_error_free().
43 * @ingroup handles
44 * @details This functor enables those classes to manage GError
45 * objects in memory which require to be freed with g_error_free().
46 * It is used in the typedefs @ref GerrorSharedHandleAnchor
47 * "GerrorSharedHandle" and @ref GerrorScopedHandleAnchor
48 * "GcharScopedHandle".
49 */
50 class GerrorFree {
51 public:
52 void operator()(const GError* obj_p) {
53 if (obj_p) {
54 g_error_free(const_cast<GError*>(obj_p));
55 }
56 }
57 };
58
59
60 /**
61 * @typedef GerrorScopedHandle.
62 * @brief A handle comprising a typed instance of the ScopedHandle class for managing GError objects.
63 * @anchor GerrorScopedHandleAnchor
64 * @ingroup handles
65 * \#include <c++-gtk-utils/gerror_handle.h>
66 */
67 typedef ScopedHandle<GError*, GerrorFree> GerrorScopedHandle;
68
69 /**
70 * @typedef GerrorSharedHandle.
71 * @brief A handle comprising a typed instance of the SharedHandle class for managing GError objects.
72 * @anchor GerrorSharedHandleAnchor
73 * @ingroup handles
74 * \#include <c++-gtk-utils/gerror_handle.h>
75 */
76 typedef SharedHandle<GError*, GerrorFree> GerrorSharedHandle;
77
78 } // namespace Cgu
79
80 #endif