ACE  6.3.2
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ACE::Value_Ptr< T > Class Template Reference

Smart pointer implementation designed for use as a class member. More...

#include <Value_Ptr.h>

Public Member Functions

 Value_Ptr (T *p=0)
 Constructor. More...
 
 ~Value_Ptr (void)
 Destructor. More...
 
T & operator* (void) const
 Deference operator. More...
 
T * operator-> (void) const
 Pointer operator. More...
 
void swap (Value_Ptr &other)
 
 Value_Ptr (Value_Ptr const &other)
 Copy constructor. More...
 
Value_Ptroperator= (Value_Ptr const &other)
 Assignment operator. More...
 
template<typename U >
 Value_Ptr (Value_Ptr< U > const &other)
 Converting copy constructor. More...
 
template<typename U >
Value_Ptroperator= (Value_Ptr< U > const &other)
 Converting assignment operator. More...
 

Private Member Functions

template<typename U >
T * create_from (U const *p) const
 Copying method invoked when copy constructing. More...
 

Private Attributes

T * p_
 Object owned by this Value_Ptr. More...
 

Friends

template<typename U >
class Value_Ptr
 

Detailed Description

template<typename T>
class ACE::Value_Ptr< T >

Smart pointer implementation designed for use as a class member.

Using a std::auto_ptr<> as a class member is sometimes problematic since ownership of memory is transferred when copying such members. This Value_Ptr class is explicitly designed to avoid such problems by performing copies of the underlying object rather than transfer ownership. This, for example, allows it to be readily used as a member in classes placed inside STL containers.

See also
Item 31 in "More Exceptional C++" by Herb Sutter.

Constructor & Destructor Documentation

template<typename T >
ACE::Value_Ptr< T >::Value_Ptr ( T *  p = 0)
inlineexplicit

Constructor.

template<typename T >
ACE::Value_Ptr< T >::~Value_Ptr ( void  )
inline

Destructor.

template<typename T >
ACE::Value_Ptr< T >::Value_Ptr ( Value_Ptr< T > const &  other)
inline

Copy constructor.

template<typename T >
template<typename U >
ACE::Value_Ptr< T >::Value_Ptr ( Value_Ptr< U > const &  other)
inline

Converting copy constructor.

Member Function Documentation

template<typename T >
template<typename U >
T* ACE::Value_Ptr< T >::create_from ( U const *  p) const
inlineprivate

Copying method invoked when copy constructing.

template<typename T >
T& ACE::Value_Ptr< T >::operator* ( void  ) const
inline

Deference operator.

template<typename T >
T* ACE::Value_Ptr< T >::operator-> ( void  ) const
inline

Pointer operator.

template<typename T >
Value_Ptr& ACE::Value_Ptr< T >::operator= ( Value_Ptr< T > const &  other)
inline

Assignment operator.

template<typename T >
template<typename U >
Value_Ptr& ACE::Value_Ptr< T >::operator= ( Value_Ptr< U > const &  other)
inline

Converting assignment operator.

template<typename T >
void ACE::Value_Ptr< T >::swap ( Value_Ptr< T > &  other)
inline

Non-throwing swap operation used to make assignment strongly exception-safe.

Note
As implemented, the swap operation may not work correctly for auto_ptr<>s, but why would one use an auto_ptr<> as the template argument for this particular template class!?

Friends And Related Function Documentation

template<typename T >
template<typename U >
friend class Value_Ptr
friend

Member Data Documentation

template<typename T >
T* ACE::Value_Ptr< T >::p_
private

Object owned by this Value_Ptr.


The documentation for this class was generated from the following file: