InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
K2::scoped_ptr< T > Class Template Reference

#include <K2SmartPtr.h>

Inheritance diagram for K2::scoped_ptr< T >:

Public Types

typedef T element_type
 

Public Member Functions

 scoped_ptr (T *p=0)
 
 ~scoped_ptr ()
 
void reset (T *p=0)
 
T * release ()
 
T & operator* () const
 
T * operator-> () const
 
T * get () const
 
bool operator! () const
 
 operator void * () const
 

Friends

bool operator== (const Self &lhs, const T *rhs)
 
bool operator== (const T *lhs, const Self &rhs)
 
bool operator!= (const Self &lhs, const T *rhs)
 
bool operator!= (const T *lhs, const Self &rhs)
 

Detailed Description

template<typename T>
class K2::scoped_ptr< T >

scoped_ptr mimics a built-in pointer except that it guarantees deletion of the object pointed to, either on destruction of the scoped_ptr or via an explicit reset(). scoped_ptr is a simple solution for simple needs; see std::auto_ptr if your needs are more complex. Because scoped_ptr is simple, in its usual implementation every operation is as fast as for a built-in pointer and it has no more space overhead that a built-in pointer. scoped_ptr cannot be used in C++ Standard Library containers. Use a scoped_array if you need to manage a pointer to an array.

Constructor & Destructor Documentation

template<typename T>
K2::scoped_ptr< T >::scoped_ptr(T * p = 0)
inlineexplicit

Constructs a scoped_ptr, storing a copy of p which MUST have been allocated using the operator new (or must be nil).

Parameters
p[IN] - pointer to the resource that will transfer the ownership to this object.
template<typename T>
K2::scoped_ptr< T >::~scoped_ptr()
inline

Destroys the object pointed by stored pointer by calling the operator delete.

Member Function Documentation

template<typename T>
T* K2::scoped_ptr< T >::get () const
inline

Gets the stored pointer.

Returns
the stored pointer.
template<typename T>
T& K2::scoped_ptr< T >::operator* () const
inline

De-reference operator. Behavior is undefined if the stored pointer is nil.

Returns
a reference to the object pointed by the stored pointer.
template<typename T>
T* K2::scoped_ptr< T >::operator-> () const
inline

Indirection operator. Behavior is undefined if the stored pointer is nil.

Returns
the stored pointer.
template<typename T>
T* K2::scoped_ptr< T >::release ()
inline

Detaches from the stored pointer by transferring the ownership to the caller. Note: the signature of this method is error prone because it allows the caller to lose the resource by not assign it to anything.

Returns
the stored pointer.
template<typename T>
void K2::scoped_ptr< T >::reset (T * p = 0)
inline

Destroys the object pointed by the stored pointer and then re-assigns it to the new value.