/* * Copyright (C) 2011-2014 Canonical, Ltd. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Authors: * - Aurélien Gâteau */ #ifndef GSCOPEDPOINTER_H #define GSCOPEDPOINTER_H // Local // Qt #include // GLib #include /** * Helper class for GScopedPointer */ template class GScopedPointerDeleter { public: static void cleanup(T* ptr) { if (ptr) { cleanup_fcn(ptr); } } }; /** * A GScopedPointer works like a QScopedPointer, except the cleanup static * method is replaced with a cleanup function, making it useful to handle C * structs whose cleanup function prototype is "void cleanup(T*)" * * Best way to use it is to define a typedef for your C struct, like this: * * typedef GScopedPointer GFooPointer; */ template class GScopedPointer : public QScopedPointer > { public: GScopedPointer(T* ptr = 0) : QScopedPointer >(ptr) {} }; /** * Helper class for GObjectScopedPointer */ template class GObjectScopedPointerDeleter { public: static void cleanup(T* ptr) { if (ptr) { cleanup_fcn(ptr); } } }; /** * A GObjectScopedPointer is similar to a GScopedPointer. The only difference * is its cleanup function signature is "void cleanup(gpointer)" and defaults to * g_object_unref(), making it useful for GObject-based classes. * * You can use it directly like this: * * GObjectScopedPointer foo; * * Or define a typedef for your class: * * typedef GObjectScopedPointer GFooPointer; * * Note: GObjectScopedPointer does *not* call gobject_ref() when assigned a * pointer. */ template class GObjectScopedPointer : public QScopedPointer > { public: GObjectScopedPointer(T* ptr = 0) : QScopedPointer >(ptr) {} }; // A Generic GObject pointer typedef GObjectScopedPointer GObjectPointer; // Take advantage of the cleanup signature of GObjectScopedPointer to define // a GCharPointer typedef GObjectScopedPointer GCharPointer; #endif /* GSCOPEDPOINTER_H */