c++-gtk-utils
|
This is a generic scoped class for managing the lifetime of objects allocated on freestore. More...
#include <c++-gtk-utils/shared_handle.h>
Public Member Functions | |
ScopedHandle (const ScopedHandle &)=delete | |
ScopedHandle & | operator= (const ScopedHandle &)=delete |
ScopedHandle (ScopedHandle &&sc_hand) | |
ScopedHandle & | operator= (ScopedHandle &&sc_hand) |
ScopedHandle (T ptr=0) | |
void | reset (T ptr=0) |
T | release () |
T | get () const |
operator T () const | |
~ScopedHandle () | |
This is a generic scoped class for managing the lifetime of objects allocated on freestore.
This class deletes its object as soon as it goes out of scope. It can be viewed as a SharedHandle which cannot be copy assigned to or used as the argument to a copy constructor and therefore which cannot have a reference count of more than 1.
ScopedHandle objects can be instantiated for pointers to constant objects (such as ScopedHandle<const char*>), provided the deleter functor will take such pointers.
This library provides StandardArrayDelete, CFree, GFree, GerrorFree, GSliceFree, GSliceFreeSize and GSliceDestroy deleter functors, which can be used as the second template parameter of the ScopedHandle class. StandardArrayDelete is the default, and some typedef'ed instances of ScopedHandle for gchar (with the GFree deleter) and for GError (with the GerrorFree deleter) are provided: GcharScopedHandle and GerrorScopedHandle)
Comparison with std::unique_ptr
This class is mainly retained to retain compatibility with series 1.2 of the library, since most of the things that can be done with it can also be done using std::unique_ptr. However, this class is a little easier to use when managing objects with associated C functions (such as in glib), because it provides a type conversion operator.
From version 2.0.19, this class has a move constructor and move assignment operator. Prior to that, it could not be moved from or to.
|
delete |
This class cannot be copied. The copy constructor is deleted.
|
inline |
The move constructor does not throw.
sc_hand | The handle to be moved. |
Since 2.0.19
|
inlineexplicit |
This constructor does not throw.
ptr | The object which the ScopedHandle is to manage (if any). |
ScopedHandle objects can be instantiated for pointers to constant objects (such as SharedHandle<const char*>), provided the deleter functor will take such pointers.
|
inline |
The destructor does not throw unless the destructor of a handled object throws - that should never happen.
|
inline |
This method does not throw.
|
inline |
This method does not throw.
|
delete |
This class cannot be copied. The copy assignment operator is deleted.
|
inline |
The move assignment operator. It will delete the object managed prior to the move, if any. It does not throw unless the destructor of that object throws.
sc_hand | The handle to be moved. |
Since 2.0.19
|
inline |
Causes the ScopedHandle to cease to manage the handled object, but does not delete that object. This method does not throw.
|
inline |
Causes the ScopedHandle to delete its managed object (if any), and if the argument passed is not NULL, the ScopedHandle object will manage the new object passed (which must not be managed by any other ScopedHandle object). This method does not throw (assuming the destructor of a managed object does not throw).
ptr | NULL (the default), or a new unmanaged object to manage. |