FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | List of all members
fei::SharedPtr< T > Class Template Reference

#include <fei_SharedPtr.hpp>

Inheritance diagram for fei::SharedPtr< T >:
Inheritance graph
[legend]

Public Types

typedef T element_type
 

Public Member Functions

 SharedPtr (T *p)
 
 ~SharedPtr ()
 
template<typename Y >
 SharedPtr (const SharedPtr< Y > &x)
 
template<typename Y >
SharedPtroperator= (const SharedPtr< Y > &x)
 
 SharedPtr (const SharedPtr &x)
 
SharedPtroperator= (const SharedPtr &x)
 
void reset (T *p=0)
 
T & operator* () const
 
T * operator-> () const
 
T * get () const
 
long use_count () const
 
bool unique () const
 
void share (T *xpointer, long *xcount)
 
void dispose ()
 

Detailed Description

template<typename T>
class fei::SharedPtr< T >

A smart pointer with reference counted copy semantics. This class is a close copy of boost::shared_ptr. See www.boost.org, and www.boost.org/libs/smart_ptr/smart_ptr.htm. For logistical reasons it was deemed easier to make a copy of the boost::shared_ptr rather than having FEI be dependent on boost. According to TR1 (C++ Technical Report 1), referenced on the boost web site, shared_ptr will be migrating into the C++ standard.

fei::SharedPtr usage notes:

Construction:

Assignment:

Comparison:

The object pointed to is deleted when the last SharedPtr pointing to it is destroyed or reset.

Author
Kevin Copps
Date
12/4/2001

Definition at line 65 of file fei_SharedPtr.hpp.

Member Typedef Documentation

template<typename T>
typedef T fei::SharedPtr< T >::element_type

The type of the stored pointer.

Definition at line 72 of file fei_SharedPtr.hpp.

Constructor & Destructor Documentation

template<typename T>
fei::SharedPtr< T >::SharedPtr ( T *  p)
inlineexplicit

Constructs a SharedPtr, storing a copy of p, which must have been allocated via a C++ new expression or be 0. On exit, use_count() is 1 (even if p==0; see the destructor).

The only exception which may be thrown by this constructor is std::bad_alloc. If an exception is thrown, delete p is called.

Parameters
pthe pointer value recently allocated

Definition at line 84 of file fei_SharedPtr.hpp.

template<typename T>
fei::SharedPtr< T >::~SharedPtr ( )
inline

Destructor. If use_count() == 1, deletes the object pointed to by the stored pointer. Otherwise, use_count() for any remaining copies is decremented by 1. Note that in C++ delete on a pointer with a value of 0 is harmless.

Never throws an exception.

Definition at line 109 of file fei_SharedPtr.hpp.

template<typename T>
template<typename Y >
fei::SharedPtr< T >::SharedPtr ( const SharedPtr< Y > &  x)
inline

Constructs a SharedPtr, as if by storing a copy of the pointer stored in x. Afterwards, use_count() for all copies is 1 more than the initial x.use_count().

Never throws an exception.

Parameters
xa shared pointer to another type

Definition at line 122 of file fei_SharedPtr.hpp.

template<typename T>
fei::SharedPtr< T >::SharedPtr ( const SharedPtr< T > &  x)
inline

Constructs a SharedPtr, as if by storing a copy of the pointer stored in x. Afterwards, use_count() for all copies is 1 more than the initial x.use_count().

Never throws an exception.

Parameters
xthe shared pointer to copy

Definition at line 160 of file fei_SharedPtr.hpp.

Member Function Documentation

template<typename T>
template<typename Y >
SharedPtr& fei::SharedPtr< T >::operator= ( const SharedPtr< Y > &  x)
inline

Assignment to a shared pointer of another type.

First, if use_count() == 1, deletes the object pointed to by the stored pointer. Otherwise, use_count() for any remaining copies is decremented by 1. Note that in C++ delete on a pointer with a value of 0 is harmless.

Then replaces the contents of this, as if by storing a copy of the pointer stored in x. Afterwards, use_count() for all copies is 1 more than the initial x.use_count().

Never throws an exception.

Parameters
xa shared pointer to another type

Definition at line 145 of file fei_SharedPtr.hpp.

template<typename T>
SharedPtr& fei::SharedPtr< T >::operator= ( const SharedPtr< T > &  x)
inline

Assignment to another shared pointer. First, if use_count() == 1, deletes the object pointed to by the stored pointer. Otherwise, use_count() for any remaining copies is decremented by 1. Note that in C++ delete on a pointer with a value of 0 is harmless.

Then replaces the contents of this, as if by storing a copy of the pointer stored in x. Afterwards, use_count() for all copies is 1 more than the initial x.use_count().

Does not throw any exception.

Parameters
xthe shared pointer to copy

Definition at line 181 of file fei_SharedPtr.hpp.

template<typename T>
void fei::SharedPtr< T >::reset ( T *  p = 0)
inline

Reset the pointer value of this shared pointer. First, if use_count() == 1, deletes the object pointed to by the stored pointer. Otherwise, use_count() for any remaining copies is decremented by 1. Then replaces the contents of this, as if by storing a copy of p, which must have been allocated via a C++ new expression or be 0. Afterwards, use_count() is 1 (even if p==0; see ~SharedPtr).

Note that in C++ delete on a pointer with a value of 0 is harmless.

The only exception which may be thrown is std::bad_alloc. If an exception is thrown, delete p is called.

Parameters
pa pointer value, or 0 if not present

Definition at line 203 of file fei_SharedPtr.hpp.

template<typename T>
T& fei::SharedPtr< T >::operator* ( ) const
inline

Returns a reference to the object pointed to by the stored pointer.

Never throws an exception.

Definition at line 228 of file fei_SharedPtr.hpp.

template<typename T>
T* fei::SharedPtr< T >::operator-> ( ) const
inline

Return the stored pointer.

Never throws an exception.

Definition at line 235 of file fei_SharedPtr.hpp.

template<typename T>
T* fei::SharedPtr< T >::get ( ) const
inline

Return the stored pointer. T is not required to be a complete type.

Never throws an exception.

Definition at line 242 of file fei_SharedPtr.hpp.

template<typename T>
long fei::SharedPtr< T >::use_count ( ) const
inline

Returns the number of SharedPtr's sharing ownership of the stored pointer. T is not required to be a complete type.

Never throws an exception.

Definition at line 250 of file fei_SharedPtr.hpp.

template<typename T>
bool fei::SharedPtr< T >::unique ( ) const
inline

Returns use_count() == 1. T is not required to be a complete type.

Never throws an exception.

Definition at line 258 of file fei_SharedPtr.hpp.

template<typename T>
void fei::SharedPtr< T >::share ( T *  xpointer,
long *  xcount 
)
inline

power users only

Definition at line 261 of file fei_SharedPtr.hpp.

template<typename T>
void fei::SharedPtr< T >::dispose ( )
inline

power users only

Definition at line 271 of file fei_SharedPtr.hpp.


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