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 to 2019 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 requires to be freed with g_error_free().
46 * It is used in the typedefs @ref GerrorSharedHandleAnchor
47 * "GerrorSharedHandle" and @ref GerrorScopedHandleAnchor
48 * "GerrorScopedHandle". It can also be used as the second template
49 * parameter of std::unique_ptr objects.
50 */
51 class GerrorFree {
52 public:
53 void operator()(const GError* obj_p) noexcept {
54 if (obj_p) {
55 g_error_free(const_cast<GError*>(obj_p));
56 }
57 }
58 };
59
60
61 /**
62 * @typedef GerrorScopedHandle.
63 * @brief A handle comprising a typed instance of the ScopedHandle class for managing GError objects.
64 * @anchor GerrorScopedHandleAnchor
65 * @ingroup handles
66 * \#include <c++-gtk-utils/gerror_handle.h>
67 */
68 typedef ScopedHandle<GError*, GerrorFree> GerrorScopedHandle;
69
70 /**
71 * @typedef GerrorSharedHandle.
72 * @brief A handle comprising a typed instance of the SharedHandle class for managing GError objects.
73 * @anchor GerrorSharedHandleAnchor
74 * @ingroup handles
75 * \#include <c++-gtk-utils/gerror_handle.h>
76 */
77 typedef SharedHandle<GError*, GerrorFree> GerrorSharedHandle;
78
79 } // namespace Cgu
80
81 #endif
Cgu
Definition: application.h:44
Cgu::SharedHandle
This is a generic class for managing the lifetime of objects allocated on freestore.
Definition: shared_handle.h:451
shared_handle.h
Cgu::GerrorSharedHandle
SharedHandle< GError *, GerrorFree > GerrorSharedHandle
A handle comprising a typed instance of the SharedHandle class for managing GError objects.
Definition: gerror_handle.h:77
Cgu::GerrorScopedHandle
ScopedHandle< GError *, GerrorFree > GerrorScopedHandle
A handle comprising a typed instance of the ScopedHandle class for managing GError objects.
Definition: gerror_handle.h:68
Cgu::GerrorFree::operator()
void operator()(const GError *obj_p) noexcept
Definition: gerror_handle.h:53
Cgu::ScopedHandle
This is a generic scoped class for managing the lifetime of objects allocated on freestore.
Definition: shared_handle.h:452
Cgu::GerrorFree
A deleter functor for use as the second (Dealloc) template parameter of the SharedHandle,...
Definition: gerror_handle.h:51
cgu_config.h