Reference counting smart pointer class for automatic garbage collection.


Classes

class  Teuchos::DeallocDelete< T >
 Deallocator for new which calls delete. More...
class  Teuchos::DeallocArrayDelete< T >
 Deallocator for new [] which calls delete []. More...
class  Teuchos::RefCountPtr< T >
  More...

Enumerations

enum  Teuchos::ENull
 Used to initialize a RefCountPtr object to NULL using an implicit conversion! More...
enum  Teuchos::EPrePostDestruction
 Used to specify a pre or post destruction of extra data. More...

Functions

template<class T>
RefCountPtr< T > Teuchos::rcp (T *p, bool owns_mem=true)
 Create a RefCountPtr object properly typed.
template<class T, class Dealloc_T>
RefCountPtr< T > Teuchos::rcp (T *p, Dealloc_T dealloc, bool owns_mem)
 Initialize from a raw pointer with a deallocation policy.
template<class T>
bool Teuchos::is_null (const RefCountPtr< T > &p)
 Returns true if p.get()==NULL.
template<class T>
bool Teuchos::operator== (const RefCountPtr< T > &p, ENull)
 Returns true if p.get()==NULL.
template<class T>
bool Teuchos::operator!= (const RefCountPtr< T > &p, ENull)
 Returns true if p.get()!=NULL.
template<class T1, class T2>
bool Teuchos::operator== (const RefCountPtr< T1 > &p1, const RefCountPtr< T2 > &p2)
 Return true if two RefCountPtr objects point to the same referenced-counted object and have the same node.
template<class T1, class T2>
bool Teuchos::operator!= (const RefCountPtr< T1 > &p1, const RefCountPtr< T2 > &p2)
 Return true if two RefCountPtr objects do not point to the same referenced-counted object and have the same node.
template<class T2, class T1>
RefCountPtr< T2 > Teuchos::rcp_implicit_cast (const RefCountPtr< T1 > &p1)
 Implicit cast of underlying RefCountPtr type from T1* to T2*.
template<class T2, class T1>
RefCountPtr< T2 > Teuchos::rcp_static_cast (const RefCountPtr< T1 > &p1)
 Static cast of underlying RefCountPtr type from T1* to T2*.
template<class T2, class T1>
RefCountPtr< T2 > Teuchos::rcp_const_cast (const RefCountPtr< T1 > &p1)
 Constant cast of underlying RefCountPtr type from T1* to T2*.
template<class T2, class T1>
RefCountPtr< T2 > Teuchos::rcp_dynamic_cast (const RefCountPtr< T1 > &p1, bool throw_on_fail=false)
 Dynamic cast of underlying RefCountPtr type from T1* to T2*.
template<class T1, class T2>
void Teuchos::set_extra_data (const T1 &extra_data, const std::string &name, RefCountPtr< T2 > *p, bool force_unique=true, EPrePostDestruction destroy_when=POST_DESTROY)
 Set extra data associated with a RefCountPtr object.
template<class T1, class T2>
T1 & Teuchos::get_extra_data (RefCountPtr< T2 > &p, const std::string &name)
 Get a non-const reference to extra data associated with a RefCountPtr object.
template<class T1, class T2>
const T1 & Teuchos::get_extra_data (const RefCountPtr< T2 > &p, const std::string &name)
 Get a const reference to extra data associated with a RefCountPtr object.
template<class T1, class T2>
T1 * Teuchos::get_optional_extra_data (RefCountPtr< T2 > &p, const std::string &name)
 Get a pointer to non-const extra data (if it exists) associated with a RefCountPtr object.
template<class T1, class T2>
const T1 * Teuchos::get_optional_extra_data (const RefCountPtr< T2 > &p, const std::string &name)
 Get a pointer to const extra data (if it exists) associated with a RefCountPtr object.
template<class Dealloc_T, class T>
Dealloc_T & Teuchos::get_dealloc (RefCountPtr< T > &p)
 Return a non-const reference to the underlying deallocator object.
template<class Dealloc_T, class T>
const Dealloc_T & Teuchos::get_dealloc (const RefCountPtr< T > &p)
 Return a const reference to the underlying deallocator object.
template<class Dealloc_T, class T>
Dealloc_T * Teuchos::get_optional_dealloc (RefCountPtr< T > &p)
 Return a pointer to the underlying non-const deallocator object if it exists.
template<class Dealloc_T, class T>
const Dealloc_T * Teuchos::get_optional_dealloc (const RefCountPtr< T > &p)
 Return a pointer to the underlying const deallocator object if it exists.

Detailed Description

For a carefully written discussion about what this class is and basic details on how to use it see the beginners guide.

Quickstart for RefCountPtr

Here we present a short, but fairly comprehensive, quick-start for the use of RefCountPtr<>. The use cases described here should cover the overwhelming majority of the use instances of RefCountPtr<> in a typical program.

The following class hierarchy will be used in the C++ examples given below.

class A { public: virtual ~A(){} virtual void f(){} };
class B1 : virtual public A {};
class B2 : virtual public A {};
class C : virtual public B1, virtual public B2 {};

class D {};
class E : public D {};

All of the following code examples used in this quickstart are assumed to be in the namespace Teuchos or have appropriate using Teuchos::... declarations. This removes the need to explicitly use Teuchos:: to qualify classes, functions and other declarations from the Teuchos namespace. Note that some of the runtime checks are denoted as "debug runtime checked" which means that checking will only be performed in a debug build (that is one where the macro _DEBUG is defined at compile time).

  1. Creation of RefCountPtr<> objects

    1. Creating a RefCountPtr<> object using new

      RefCountPtr<C> c_ptr = rcp(new C);
      

    2. Creating a RefCountPtr<> object to an array allocated using new[n] : Teuchos::DeallocArrayDelete

      RefCountPtr<C> c_ptr = rcp(new C[n],DeallocArrayDelete<C>(),true);
      

    3. Initializing a RefCountPtr<> object to NULL

      RefCountPtr<C> c_ptr;
      
      or
      RefCountPtr<C> c_ptr = null;
      

    4. Initializing a RefCountPtr<> object to an object {not} allocated with new

      C              c;
      RefCountPtr<C> c_ptr = rcp(&c,false);
      

    5. Copy constructor (implicit casting)

      RefCountPtr<C>       c_ptr  = rcp(new C); // No cast
      RefCountPtr<A>       a_ptr  = c_ptr;      // Cast to base class
      RefCountPtr<const A> ca_ptr = a_ptr;      // Cast from non-const to const
      

    6. Representing constantness and non-constantness

      1. Non-constant pointer to non-constant object
        RefCountPtr<C> c_ptr;
        

      2. Constant pointer to non-constant object
        const RefCountPtr<C> c_ptr;
        

      3. Non-Constant pointer to constant object
        RefCountPtr<const C> c_ptr;
        

      4. Constant pointer to constant object
        const RefCountPtr<const C> c_ptr;
        

  2. Reinitialization of RefCountPtr<> objects (using assignment operator)

    1. Resetting from a raw pointer

      RefCountPtr<A> a_ptr;
      a_ptr = rcp(new C());
      

    2. Resetting to null

      RefCountPtr<A> a_ptr = rcp(new C());
      a_ptr = null; // The C object will be deleted here
      

    3. Assigning from a RefCountPtr<> object

      RefCountPtr<A> a_ptr1;
      RefCountPtr<A> a_ptr2 = rcp(new C());
      a_ptr1 = a_ptr2; // Now a_ptr1 and a_ptr2 point to same C object
      

  3. Accessing the reference-counted object

    1. Access to object reference (debug runtime checked) : Teuchos::RefCountPtr::operator*()

      C &c_ref = *c_ptr;
      

    2. Access to object pointer (unchecked, may return NULL) : Teuchos::RefCountPtr::get()

      C *c_rptr = c_ptr.get();
      

    3. Access to object pointer (debug runtime checked, will not return NULL) : Teuchos::RefCountPtr::operator*()

      C *c_rptr = &*c_ptr;
      

    4. Access of object's member (debug runtime checked) : Teuchos::RefCountPtr::operator->()

      c_ptr->f();
      

    5. Testing for non-null : Teuchos::RefCountPtr::get(), Teuchos::operator==(), Teuchos::operator!=()

      if( a_ptr.get() ) std::cout << "a_ptr is not null!\n";
      

      or

      if( a_ptr != null ) std::cout << "a_ptr is not null!\n";
      

      or

    6. Testing for null

      if( !a_ptr.get() ) std::cout << "a_ptr is null!\n";
      

      or

      if( a_ptr == null ) std::cout << "a_ptr is null!\n";
      

      or

      if( is_null(a_ptr) ) std::cout << "a_ptr is null!\n";
      

  4. Casting

    1. Implicit casting (see copy constructor above)

      1. Using copy constructor (see above)

      2. Using conversion function

        RefCountPtr<C>       c_ptr  = rcp(new C);                       // No cast
        RefCountPtr<A>       a_ptr  = rcp_implicit_cast<A>(c_ptr);      // To base
        RefCountPtr<const A> ca_ptr = rcp_implicit_cast<const A>(a_ptr);// To const
        

    2. Casting away const : rcp_const_cast()

      RefCountPtr<const A>  ca_ptr = rcp(new C);
      RefCountPtr<A>        a_ptr  = rcp_const_cast<A>(ca_ptr); // cast away const!
      

    3. Static cast (no runtime check) : rcp_static_cast()

      RefCountPtr<D>     d_ptr = rcp(new E);
      RefCountPtr<E>     e_ptr = rcp_static_cast<E>(d_ptr); // Unchecked, unsafe?
      

    4. Dynamic cast (runtime checked, failed cast allowed) : rcp_dynamic_cast()

      RefCountPtr<A>     a_ptr  = rcp(new C);
      RefCountPtr<B1>    b1_ptr = rcp_dynamic_cast<B1>(a_ptr);  // Checked, safe!
      RefCountPtr<B2>    b2_ptr = rcp_dynamic_cast<B2>(b1_ptr); // Checked, safe!
      RefCountPtr<C>     c_ptr  = rcp_dynamic_cast<C>(b2_ptr);  // Checked, safe!
      

    5. Dynamic cast (runtime checked, failed cast not allowed) : rcp_dynamic_cast()

      RefCountPtr<A>     a_ptr1  = rcp(new C);
      RefCountPtr<A>     a_ptr2  = rcp(new A);
      RefCountPtr<B1>    b1_ptr1 = rcp_dynamic_cast<B1>(a_ptr1,true);  // Success!
      RefCountPtr<B1>    b1_ptr2 = rcp_dynamic_cast<B1>(a_ptr2,true);  // Throw std::bad_cast!
      

  5. Customized deallocators

    1. Creating a RefCountPtr<> object with a custom deallocator : Teuchos::DeallocArrayDelete

      RefCountPtr<C> c_ptr = rcp(new C[N],DeallocArrayDelete<C>(),true);
      

    2. Access customized deallocator (runtime checked, throws on failure) : Teuchos::get_dealloc()

      const DeallocArrayDelete<C>
        &dealloc = get_dealloc<DeallocArrayDelete<C> >(c_ptr);
      

    3. Access optional customized deallocator : Teuchos::get_optional_dealloc()

      const DeallocArrayDelete<C>
        *dealloc = get_optional_dealloc<DeallocArrayDelete<C> >(c_ptr);
      if(dealloc) std::cout << "This deallocator exits!\n";
      

  6. Managing extra data

    1. Adding extra data (post destruction of extra data) : Teuchos::set_extra_data()

      set_extra_data(rcp(new B1),"A:B1",&a_ptr);
      

    2. Adding extra data (pre destruction of extra data) : Teuchos::get_extra_data()

      set_extra_data(rcp(new B1),"A:B1",&a_ptr,PRE_DESTORY);
      

    3. Retrieving extra data : Teuchos::get_extra_data()

      get_extra_data<RefCountPtr<B1> >(a_ptr,"A:B1")->f();
      

    4. Resetting extra data : Teuchos::get_extra_data()

      get_extra_data<RefCountPtr<B1> >(a_ptr,"A:B1") = rcp(new C);
      

    5. Retrieving optional extra data : Teuchos::get_optional_extra_data()

      const RefCountPtr<B1>
        *b1 = get_optional_extra_data<RefCountPtr<B1> >(a_ptr,"A:B1");
      if(b1) (*b1)->f();
      


Enumeration Type Documentation

enum ENull
 

Used to initialize a RefCountPtr object to NULL using an implicit conversion!

Definition at line 396 of file Teuchos_RefCountPtrDecl.hpp.

enum EPrePostDestruction
 

Used to specify a pre or post destruction of extra data.

Definition at line 399 of file Teuchos_RefCountPtrDecl.hpp.


Function Documentation

template<class T>
Teuchos::RefCountPtr< T > Teuchos::rcp T *  p,
bool  owns_mem = true
[inline]
 

Create a RefCountPtr object properly typed.

Parameters:
p [in] Pointer to an object to be reference counted.
owns_mem [in] If owns_mem==true then delete p will be called when the last reference to this object is removed. If owns_mem==false then nothing will happen to delete the the object pointed to by p when the last reference is removed.
Preconditions:
  • If owns_mem==true then p must have been created by calling new to create the object since delete p will be called eventually.

If the pointer p did not come from new then either the client should use the version of rcp() that that uses a deallocator policy object or should pass in owns_mem = false.

Definition at line 321 of file Teuchos_RefCountPtr.hpp.

template<class T, class Dealloc_T>
Teuchos::RefCountPtr< T > Teuchos::rcp T *  p,
Dealloc_T  dealloc,
bool  owns_mem
[inline]
 

Initialize from a raw pointer with a deallocation policy.

Parameters:
p [in] Raw C++ pointer that this will represent.
dealloc [in] Deallocator policy object (copied by value) that defines a function void Dealloc_T::free(T* p) that will free the underlying object.
owns_mem [in] If true then return is allowed to delete the underlying pointer by calling dealloc.free(p). when all references have been removed.
Preconditions:
  • The function void Dealloc_T::free(T* p) exists.

Postconditions:

  • return.get() == p
  • If p == NULL then
    • return.count() == 0
    • return.has_ownership() == false
  • else
    • return.count() == 1
    • return.has_ownership() == owns_mem

By default, return has ownership to delete the object pointed to by p when return is deleted (see ~RefCountPtr()). If owns_mem==true, it is vital that the address p passed in is the same address that was returned by new. With multiple inheritance this is not always the case. See the above discussion. This class is templated to accept a deallocator object that will free the pointer. The other functions use a default deallocator of type DeallocDelete which has a method DeallocDelete::free() which just calls delete p.

Definition at line 329 of file Teuchos_RefCountPtr.hpp.

template<class T>
REFCOUNTPTR_INLINE bool Teuchos::is_null const RefCountPtr< T > &  p  ) 
 

Returns true if p.get()==NULL.

Examples:
test/RefCountPtr/cxx_main.cpp.

Definition at line 336 of file Teuchos_RefCountPtr.hpp.

template<class T>
REFCOUNTPTR_INLINE bool Teuchos::operator== const RefCountPtr< T > &  p,
ENull 
 

Returns true if p.get()==NULL.

Definition at line 343 of file Teuchos_RefCountPtr.hpp.

template<class T>
REFCOUNTPTR_INLINE bool Teuchos::operator!= const RefCountPtr< T > &  p,
ENull 
 

Returns true if p.get()!=NULL.

Definition at line 350 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE bool Teuchos::operator== const RefCountPtr< T1 > &  p1,
const RefCountPtr< T2 > &  p2
 

Return true if two RefCountPtr objects point to the same referenced-counted object and have the same node.

Definition at line 357 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE bool Teuchos::operator!= const RefCountPtr< T1 > &  p1,
const RefCountPtr< T2 > &  p2
 

Return true if two RefCountPtr objects do not point to the same referenced-counted object and have the same node.

Definition at line 364 of file Teuchos_RefCountPtr.hpp.

template<class T2, class T1>
REFCOUNTPTR_INLINE Teuchos::RefCountPtr< T2 > Teuchos::rcp_implicit_cast const RefCountPtr< T1 > &  p1  ) 
 

Implicit cast of underlying RefCountPtr type from T1* to T2*.

The function will compile only if (T2* p2 = p1.get();) compiles.

This is to be used for conversions up an inheritance hierarchy and from non-const to const and any other standard implicit pointer conversions allowed by C++.

Definition at line 372 of file Teuchos_RefCountPtr.hpp.

template<class T2, class T1>
REFCOUNTPTR_INLINE Teuchos::RefCountPtr< T2 > Teuchos::rcp_static_cast const RefCountPtr< T1 > &  p1  ) 
 

Static cast of underlying RefCountPtr type from T1* to T2*.

The function will compile only if (static_cast<T2*>(p1.get());) compiles.

This can safely be used for conversion down an inheritance hierarchy with polymorphic types only if dynamic_cast<T2>(p1.get()) == static_cast<T2>(p1.get()). If not then you have to use rcp_dynamic_cast<t2>(p1).

Definition at line 387 of file Teuchos_RefCountPtr.hpp.

template<class T2, class T1>
REFCOUNTPTR_INLINE Teuchos::RefCountPtr< T2 > Teuchos::rcp_const_cast const RefCountPtr< T1 > &  p1  ) 
 

Constant cast of underlying RefCountPtr type from T1* to T2*.

This function will compile only if (const_cast<T2*>(p1.get());) compiles.

Definition at line 402 of file Teuchos_RefCountPtr.hpp.

template<class T2, class T1>
REFCOUNTPTR_INLINE Teuchos::RefCountPtr< T2 > Teuchos::rcp_dynamic_cast const RefCountPtr< T1 > &  p1,
bool  throw_on_fail = false
 

Dynamic cast of underlying RefCountPtr type from T1* to T2*.

Parameters:
p1 [in] The smart pointer casting from
throw_on_fail [in] If true then if the cast fails (for p1.get()!=NULL) then a std::bad_cast exception is thrown with a very informative error message.
Postconditions:
  • If ( p1.get()!=NULL && throw_on_fail==true && dynamic_cast<T2*>(p1.get())==NULL ) == true then an std::bad_cast exception is thrown with a very informative error message.
  • If ( p1.get()!=NULL && dynamic_cast<T2*>(p1.get())!=NULL ) == true then return.get() == dynamic_cast<T2*>(p1.get()).
  • If ( p1.get()!=NULL && throw_on_fail==false && dynamic_cast<T2*>(p1.get())==NULL ) == true then return.get() == NULL.
  • If ( p1.get()==NULL ) == true then return.get() == NULL.

This function will compile only if (dynamic_cast<T2*>(p1.get());) compiles.

Definition at line 417 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE void Teuchos::set_extra_data const T1 &  extra_data,
const std::string &  name,
RefCountPtr< T2 > *  p,
bool  force_unique = true,
EPrePostDestruction  destroy_when = POST_DESTROY
 

Set extra data associated with a RefCountPtr object.

Parameters:
extra_data [in] Data object that will be set (copied)
name [in] The name given to the extra data. The value of name together with the data type T1 of the extra data must be unique from any other such data or the other data will be overwritten.
p [out] On output, will be updated with the input extra_data
force_unique [in] Determines if this type and name pair must be unique in which case if an object with this same type and name already exists, then an exception will be thrown. The default is true for safety.
destroy_when [in] Determines when extra_data will be destoryed in relation to the underlying reference-counted object. If destroy_when==PRE_DESTROY then extra_data will be deleted before the underlying reference-counted object. If destroy_when==POST_DESTROY (the default) then extra_data will be deleted after the underlying reference-counted object.
If there is a call to this function with the same type of extra data T1 and same arguments p and name has already been made, then the current piece of extra data already set will be overwritten with extra_data. However, if the type of the extra data T1 is different, then the extra data can be added and not overwrite existing extra data. This means that extra data is keyed on both the type and name. This helps to minimize the chance that clients will unexpectedly overwrite data by accident.

When the last RefcountPtr object is removed and the reference-count node is deleted, then objects are deleted in the following order: (1) All of the extra data that where added with destroy_when==PRE_DESTROY are first, (2) then the underlying reference-counted object is deleted, and (3) the rest of the extra data that was added with destroy_when==PRE_DESTROY is then deleted. The order in which the objects are destroyed is not guaranteed. Therefore, clients should be careful not to add extra data that has deletion dependancies (instead consider using nested RefCountPtr objects as extra data which will guarantee the order of deletion).

Preconditions:

  • p->get() != NULL (throws std::logic_error)
  • If this function has already been called with the same template type T1 for extra_data and the same string name and force_unique==true, then an std::invalid_argument exception will be thrown.

Note, this function is made a non-member function to be consistent with the non-member get_extra_data() functions.

Examples:
test/RefCountPtr/cxx_main.cpp.

Definition at line 437 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE T1 & Teuchos::get_extra_data RefCountPtr< T2 > &  p,
const std::string &  name
 

Get a non-const reference to extra data associated with a RefCountPtr object.

Parameters:
p [in] Smart pointer object that extra data is being extraced from.
name [in] Name of the extra data.
Returns:
Returns a non-const reference to the extra_data object.
Preconditions:
  • p.get() != NULL (throws std::logic_error)
  • name and T1 must have been used in a previous call to set_extra_data() (throws std::invalid_argument).

Note, this function must be a non-member function since the client must manually select the first template argument.

Definition at line 445 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE const T1 & Teuchos::get_extra_data const RefCountPtr< T2 > &  p,
const std::string &  name
 

Get a const reference to extra data associated with a RefCountPtr object.

Parameters:
p [in] Smart pointer object that extra data is being extraced from.
name [in] Name of the extra data.
Returns:
Returns a const reference to the extra_data object.
Preconditions:
  • p.get() != NULL (throws std::logic_error)
  • name and T1 must have been used in a previous call to set_extra_data() (throws std::invalid_argument).

Note, this function must be a non-member function since the client must manually select the first template argument.

Also note that this const version is a false sense of security since a client can always copy a const RefCountPtr object into a non-const object and then use the non-const version to change the data. However, its presence will help to avoid some types of accidental changes to this extra data.

Definition at line 453 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE T1 * Teuchos::get_optional_extra_data RefCountPtr< T2 > &  p,
const std::string &  name
 

Get a pointer to non-const extra data (if it exists) associated with a RefCountPtr object.

Parameters:
p [in] Smart pointer object that extra data is being extraced from.
name [in] Name of the extra data.
Returns:
Returns a non-const pointer to the extra_data object.
Preconditions:
  • p.get() != NULL (throws std::logic_error)

Postconditions:

  • If name and T1 have been used in a previous call to set_extra_data() then return !=NULL and otherwise return == NULL.

Note, this function must be a non-member function since the client must manually select the first template argument.

Definition at line 461 of file Teuchos_RefCountPtr.hpp.

template<class T1, class T2>
REFCOUNTPTR_INLINE const T1 * Teuchos::get_optional_extra_data const RefCountPtr< T2 > &  p,
const std::string &  name
 

Get a pointer to const extra data (if it exists) associated with a RefCountPtr object.

Parameters:
p [in] Smart pointer object that extra data is being extraced from.
name [in] Name of the extra data.
Returns:
Returns a const pointer to the extra_data object if it exists.
Preconditions:
  • p.get() != NULL (throws std::logic_error)

Postconditions:

  • If name and T1 have been used in a previous call to set_extra_data() then return !=NULL and otherwise return == NULL.

Note, this function must be a non-member function since the client must manually select the first template argument.

Also note that this const version is a false sense of security since a client can always copy a const RefCountPtr object into a non-const object and then use the non-const version to change the data. However, its presence will help to avoid some types of accidental changes to this extra data.

Definition at line 471 of file Teuchos_RefCountPtr.hpp.

template<class Dealloc_T, class T>
REFCOUNTPTR_INLINE Dealloc_T & Teuchos::get_dealloc RefCountPtr< T > &  p  ) 
 

Return a non-const reference to the underlying deallocator object.

Preconditions:

  • p.get() != NULL (throws std::logic_error)
  • The deallocator object type used to construct p is same as Dealloc_T (throws std::logic_error)

Definition at line 482 of file Teuchos_RefCountPtr.hpp.

template<class Dealloc_T, class T>
const Dealloc_T & Teuchos::get_dealloc const RefCountPtr< T > &  p  )  [inline]
 

Return a const reference to the underlying deallocator object.

Preconditions:

  • p.get() != NULL (throws std::logic_error)
  • The deallocator object type used to construct p is same as Dealloc_T (throws std::logic_error)

Note that the const version of this function provides only a very ineffective attempt to avoid accidental changes to the deallocation object. A client can always just create a new non-const RefCountPtr<T> object from any const RefCountPtr<T> object and then call the non-const version of this function.

Definition at line 499 of file Teuchos_RefCountPtr.hpp.

template<class Dealloc_T, class T>
REFCOUNTPTR_INLINE Dealloc_T * Teuchos::get_optional_dealloc RefCountPtr< T > &  p  ) 
 

Return a pointer to the underlying non-const deallocator object if it exists.

Preconditions:

  • p.get() != NULL (throws std::logic_error)

Postconditions:

  • If the deallocator object type used to construct p is same as Dealloc_T then return!=NULL, otherwise return==NULL

Definition at line 507 of file Teuchos_RefCountPtr.hpp.

template<class Dealloc_T, class T>
const Dealloc_T * Teuchos::get_optional_dealloc const RefCountPtr< T > &  p  )  [inline]
 

Return a pointer to the underlying const deallocator object if it exists.

Preconditions:

  • p.get() != NULL (throws std::logic_error)

Postconditions:

  • If the deallocator object type used to construct p is same as Dealloc_T then return!=NULL, otherwise return==NULL

Note that the const version of this function provides only a very ineffective attempt to avoid accidental changes to the deallocation object. A client can always just create a new non-const RefCountPtr<T> object from any const RefCountPtr<T> object and then call the non-const version of this function.

Definition at line 520 of file Teuchos_RefCountPtr.hpp.


Generated on Thu Sep 18 12:39:11 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1