NCBI C++ ToolKit
|
Search Toolkit Book for AutoPtr
#include <corelib/ncbimisc.hpp>
Classes | |
struct | SSafeBoolTag |
Bool operator for use in if() clause. More... | |
Public Types | |
typedef X | element_type |
Define element type. More... | |
typedef Del | deleter_type |
Alias for template argument. More... | |
typedef void(SSafeBoolTag::* | TBoolType) (SSafeBoolTag *) |
Public Member Functions | |
AutoPtr (element_type *p=0) | |
Constructor. More... | |
AutoPtr (element_type *p, const deleter_type &deleter) | |
Constructor. More... | |
AutoPtr (element_type *p, EOwnership ownership) | |
Constructor, own the pointed object if ownership == eTakeOwnership. More... | |
AutoPtr (element_type *p, const deleter_type &deleter, EOwnership ownership) | |
Constructor, own the pointed object if ownership == eTakeOwnership. More... | |
AutoPtr (const AutoPtr< X, Del > &p) | |
Copy constructor. More... | |
~AutoPtr (void) | |
Destructor. More... | |
AutoPtr< X, Del > & | operator= (const AutoPtr< X, Del > &p) |
Assignment operator. More... | |
AutoPtr< X, Del > & | operator= (element_type *p) |
Assignment operator. More... | |
operator TBoolType () const | |
element_type & | operator* (void) const |
Dereference operator. More... | |
element_type * | operator-> (void) const |
Reference operator. More... | |
element_type * | get (void) const |
Get pointer. More... | |
element_type * | release (void) |
Release will release ownership of pointer to caller. More... | |
void | reset (element_type *p=0, EOwnership ownership=eTakeOwnership) |
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership upon the new pointer by default. More... | |
void | Swap (AutoPtr< X, Del > &a) |
bool | IsOwned (void) const |
Private Member Functions | |
bool | operator== (TBoolType) const |
bool | operator!= (TBoolType) const |
element_type * | x_Release (void) const |
Release for const object. More... | |
Private Attributes | |
element_type * | m_Ptr |
Internal pointer representation. More... | |
pair_base_member< deleter_type, bool > | m_Data |
State info. More... | |
Friends | |
struct | SSafeBoolTag |
AutoPtr –.
Define an "auto_ptr" like class that can be used inside STL containers.
The Standard auto_ptr template from STL doesn't allow the auto_ptr to be put in STL containers (list, vector, map etc.). The reason for this is the absence of copy constructor and assignment operator. We decided that it would be useful to have an analog of STL's auto_ptr without this restriction - AutoPtr.
Due to the nature of AutoPtr its copy constructor and assignment operator modify the state of the source AutoPtr object as it transfers the ownership to the target AutoPtr object. Also, we added possibility to redefine the way pointer will be deleted: the second argument of the template allows pointers from "malloc" in AutoPtr, or you can use "ArrayDeleter" (see above) to properly delete an array of objects using "delete[]" instead of "delete". By default, the internal pointer is deleted by the C++ "delete" operator.
Definition at line 400 of file ncbimisc.hpp.