Gromacs
2016.6
|
#include <gromacs/utility/scoped_cptr.h>
Stripped-down version of scoped_ptr that uses sfree() or custom deleter.
Currently only implements some operations; other operations can be added if they become necessary. The presence of a release() method is not strictly according to scoped_ptr
design, but makes it easier to make existing C code exception-safe, and does not really warrant a separate class for such a purpose.
This class provides a basic guard/smart pointer for C pointers.
Methods in this class do not throw.
Public Member Functions | |
scoped_cptr (T *ptr=NULL) | |
Initializes a scoped_cptr that frees ptr on scope exit. More... | |
~scoped_cptr () | |
Frees the pointer passed to the constructor. | |
T * | get () const |
Returns the stored pointer. | |
operator bool () const | |
Check for non-null pointer in boolean context. | |
void | reset (T *ptr) |
Sets the pointer and frees previous pointer if necessary. | |
T * | release () |
Clears the pointer without freeing the memory, and returns the old value. | |
|
inlineexplicit |
Initializes a scoped_cptr that frees ptr
on scope exit.
[in] | ptr | Pointer to use for initialization. |