FEI Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
fei::SharedPtr< T > Class Template Reference

#include <fei_SharedPtr.hpp>

Inheritance diagram for fei::SharedPtr< T >:

Public Types

typedef T element_type

Public Member Functions

 SharedPtr (T *p)
 SharedPtr (void)
 ~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 ()

Private Attributes

T * pointer
long * count

Friends

template<typename Y>
class SharedPtr

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:

  • fei::SharedPtr objects can be assigned to each other. You can not assign a raw pointer to a fei::SharedPtr. Instead, use the reset member: myptr.reset(new MyObject);

Comparison:

  • fei::SharedPtr objects can be compared to each other, but can not be compared to raw pointers. Instead, use the get member: if (myptr.get() == NULL) {...

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

◆ element_type

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

◆ SharedPtr() [1/4]

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.

References count, and pointer.

◆ SharedPtr() [2/4]

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

Definition at line 95 of file fei_SharedPtr.hpp.

References count, and pointer.

◆ ~SharedPtr()

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.

References dispose().

◆ SharedPtr() [3/4]

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.

References count, pointer, and SharedPtr.

◆ SharedPtr() [4/4]

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.

References count, pointer, and SharedPtr.

Member Function Documentation

◆ operator=() [1/2]

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.

References count, pointer, share(), and SharedPtr.

◆ operator=() [2/2]

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.

References count, pointer, share(), and SharedPtr.

◆ reset()

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.

References count, and pointer.

Referenced by snl_fei::Factory::clone(), fei::create_LibraryWrapper(), test_VectorSpace::create_VectorSpace(), fei::MatrixGraph_Impl2::createGraph(), snl_fei::Broker_FEData::createMatrix(), snl_fei::Broker_LinSysCore::createMatrix(), Factory_Aztec::createVector(), Factory_Aztec::createVector(), snl_fei::Broker_FEData::createVector(), snl_fei::Broker_LinSysCore::createVector(), snl_fei::LinearSystem_General::enforceEssentialBC_LinSysCore(), extractDirichletBCs(), feiDriver_main(), poisson_main(), and test_FEI::test1().

◆ operator*()

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.

References pointer.

◆ operator->()

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.

References pointer.

◆ get()

◆ use_count()

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.

References count.

◆ unique()

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.

References count.

◆ share()

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.

References count, dispose(), and pointer.

Referenced by operator=(), and operator=().

◆ dispose()

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

power users only

Definition at line 271 of file fei_SharedPtr.hpp.

References count, and pointer.

Referenced by share(), and ~SharedPtr().

◆ SharedPtr

template<typename T>
template<typename Y>
friend class SharedPtr
friend

Definition at line 288 of file fei_SharedPtr.hpp.

References SharedPtr.

Referenced by operator=(), operator=(), SharedPtr, SharedPtr(), and SharedPtr().

Member Data Documentation

◆ pointer

template<typename T>
T* fei::SharedPtr< T >::pointer
private

◆ count

template<typename T>
long* fei::SharedPtr< T >::count
private

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