NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
AutoPtr< X, Del > Class Template Reference

Search Toolkit Book for AutoPtr

AutoPtr –. More...

#include <corelib/ncbimisc.hpp>

+ Inheritance diagram for AutoPtr< X, Del >:
+ Collaboration diagram for AutoPtr< X, Del >:


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_typeoperator* (void) const
 Dereference operator. More...
element_typeoperator-> (void) const
 Reference operator. More...
element_typeget (void) const
 Get pointer. More...
element_typerelease (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_typex_Release (void) const
 Release for const object. More...

Private Attributes

 Internal pointer representation. More...
pair_base_member< deleter_type, boolm_Data
 State info. More...


struct SSafeBoolTag

Detailed Description

template<class X, class Del = Deleter<X>>
class AutoPtr< X, Del >

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.

See also
Deleter(), ArrayDeleter(), CDeleter()

Definition at line 400 of file ncbimisc.hpp.

The documentation for this class was generated from the following file:
Modified on Tue Apr 23 07:41:01 2024 by rev. 669887