c++-gtk-utils
|
00001 /* Copyright (C) 2007 and 2009 Chris Vine 00002 00003 The library comprised in this file or of which this file is part is 00004 distributed by Chris Vine under the GNU Lesser General Public 00005 License as follows: 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public License 00009 as published by the Free Software Foundation; either version 2.1 of 00010 the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, but 00013 WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License, version 2.1, for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License, version 2.1, along with this library (see the file LGPL.TXT 00019 which came with this source code package in the c++-gtk-utils 00020 sub-directory); if not, write to the Free Software Foundation, Inc., 00021 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00022 00023 */ 00024 00025 #ifndef CGU_GERROR_HANDLE_H 00026 #define CGU_GERROR_HANDLE_H 00027 00028 #include <glib.h> 00029 #include <c++-gtk-utils/shared_handle.h> 00030 #include <c++-gtk-utils/cgu_config.h> 00031 00032 /** 00033 * @addtogroup handles handles and smart pointers 00034 */ 00035 00036 namespace Cgu { 00037 00038 /** 00039 * @class GerrorFree gerror_handle.h c++-gtk-utils/gerror_handle.h 00040 * @brief A deleter functor for use as the second (Dealloc) template 00041 * parameter of the SharedHandle, SharedLockHandle or ScopedHandle 00042 * template classes, which calls glib's g_error_free(). 00043 * @ingroup handles 00044 * @details This functor enables those classes to manage GError 00045 * objects in memory which require to be freed with g_error_free(). 00046 * It is used in the typedefs @ref GerrorSharedHandleAnchor 00047 * "GerrorSharedHandle" and @ref GerrorScopedHandleAnchor 00048 * "GcharScopedHandle". 00049 */ 00050 class GerrorFree { 00051 public: 00052 void operator()(const GError* obj_p) { 00053 if (obj_p) { 00054 g_error_free(const_cast<GError*>(obj_p)); 00055 } 00056 } 00057 }; 00058 00059 00060 /** 00061 * @typedef GerrorScopedHandle. 00062 * @brief A handle comprising a typed instance of the ScopedHandle class for managing GError objects. 00063 * @anchor GerrorScopedHandleAnchor 00064 * @ingroup handles 00065 * \#include <c++-gtk-utils/gerror_handle.h> 00066 */ 00067 typedef ScopedHandle<GError*, GerrorFree> GerrorScopedHandle; 00068 00069 /** 00070 * @typedef GerrorSharedHandle. 00071 * @brief A handle comprising a typed instance of the SharedHandle class for managing GError objects. 00072 * @anchor GerrorSharedHandleAnchor 00073 * @ingroup handles 00074 * \#include <c++-gtk-utils/gerror_handle.h> 00075 */ 00076 typedef SharedHandle<GError*, GerrorFree> GerrorSharedHandle; 00077 00078 } // namespace Cgu 00079 00080 #endif