Support Software for Vector Reduction/Transformation Operators Version of the Day
Public Member Functions | Related Functions
RTOpPack::Teuchos::Ptr< T > Class Template Reference

Simple wrapper class for raw pointers to single objects where no persisting relationship exists. More...

#include <RTOpPack_SPMD_apply_op_def.hpp>

List of all members.

Public Member Functions

 Ptr (ENull null_in=null)
 Default construct to NULL.
 Ptr (T *ptr)
 Construct given a raw pointer.
 Ptr (const Ptr< T > &ptr)
 Copy construct from same type.
template<class T2 >
 Ptr (const Ptr< T2 > &ptr)
 Copy construct from another type.
Ptr< T > & operator= (const Ptr< T > &ptr)
 Shallow copy of the underlying pointer.
T * operator-> () const
 Pointer (->) access to members of underlying object.
T & operator* () const
 Dereference the underlying object.
T * get () const
 Get the raw C++ pointer to the underlying object.
T * getRawPtr () const
 Get the raw C++ pointer to the underlying object.
const Ptr< T > & assert_not_null () const
 Throws std::logic_error if this->get()==NULL, otherwise returns reference to *this.
const Ptr< T > ptr () const
 Return a copy of *this.
Ptr< const T > getConst () const
 Return a Ptr<const T> version of *this.
 Ptr (ENull null_in=null)
 Default construct to NULL.
 Ptr (T *ptr)
 Construct given a raw pointer.
 Ptr (const Ptr< T > &ptr)
 Copy construct from same type.
template<class T2 >
 Ptr (const Ptr< T2 > &ptr)
 Copy construct from another type.
Ptr< T > & operator= (const Ptr< T > &ptr)
 Shallow copy of the underlying pointer.
T * operator-> () const
 Pointer (->) access to members of underlying object.
T & operator* () const
 Dereference the underlying object.
T * get () const
 Get the raw C++ pointer to the underlying object.
T * getRawPtr () const
 Get the raw C++ pointer to the underlying object.
const Ptr< T > & assert_not_null () const
 Throws std::logic_error if this->get()==NULL, otherwise returns reference to *this.
const Ptr< T > ptr () const
 Return a copy of *this.
Ptr< const T > getConst () const
 Return a Ptr<const T> version of *this.

Related Functions

(Note that these are not member functions.)

template<class T >
bool is_null (const Ptr< T > &p)
 Returns true if p.get()==NULL.
template<class T >
bool nonnull (const Ptr< T > &p)
 Returns true if p.get()!=NULL
template<class T >
bool operator== (const Ptr< T > &p, ENull)
 Returns true if p.get()==NULL.
template<class T >
bool operator!= (const Ptr< T > &p, ENull)
 Returns true if p.get()!=NULL.
template<class T1 , class T2 >
bool operator== (const Ptr< T1 > &p1, const Ptr< T2 > &p2)
 Return true if two Ptr objects point to the same object.
template<class T1 , class T2 >
bool operator!= (const Ptr< T1 > &p1, const Ptr< T2 > &p2)
 Return true if two Ptr objects do not point to the same object.
template<class T2 , class T1 >
Ptr< T2 > ptr_implicit_cast (const Ptr< T1 > &p1)
 Implicit cast of underlying Ptr type from T1* to T2*.
template<class T2 , class T1 >
Ptr< T2 > ptr_static_cast (const Ptr< T1 > &p1)
 Static cast of underlying Ptr type from T1* to T2*.
template<class T2 , class T1 >
Ptr< T2 > ptr_const_cast (const Ptr< T1 > &p1)
 Constant cast of underlying Ptr type from T1* to T2*.
template<class T2 , class T1 >
Ptr< T2 > ptr_dynamic_cast (const Ptr< T1 > &p1, bool throw_on_fail=false)
 Dynamic cast of underlying Ptr type from T1* to T2*.
template<class T >
std::ostream & operator<< (std::ostream &out, const Ptr< T > &p)
 Output stream inserter.

Detailed Description

template<class T>
class RTOpPack::Teuchos::Ptr< T >

Simple wrapper class for raw pointers to single objects where no persisting relationship exists.

This class is meant to replace all but the lowest-level use of raw pointers that point to single objects where the use of RCP is not justified for performance or semantic reasons. When built in optimized mode, this class should impart little time overhead and should be exactly equivalent in the memory footprint to a raw C++ pointer and the only extra runtime overhead will be the default initalization to NULL.

The main advantages of using this class over a raw pointer however are:

Debugging support is compiled in when the macro TEUCHOS_DEBUG is defined which happens automatically when --enable-teuchos-debug is specified on the configure line. When debugging support is not compiled in, the only overhead imparted by this class is it's default initialization to null. Therefore, this class can provide for very high performance on optimized builds of the code.

An implicit conversion from a raw pointer to a Ptr object is okay since we don't assume any ownership of the object, hense the constructor taking a raw pointer is not declared explicit. However, this class does not support an implicit conversion to a raw pointer since we want to limit the exposure of raw pointers in our software. If we have to convert back to a raw pointer, then we want to make that explicit by calling get().

This class should be used to replace most raw uses of C++ pointers to single objects where using the RCP class is not appropriate, unless the runtime cost of null-initialization it too expensive.

Definition at line 104 of file RTOpPack_SPMD_apply_op_def.hpp.


Constructor & Destructor Documentation

template<class T >
RTOpPack::Teuchos::Ptr< T >::Ptr ( ENull  null_in = null) [inline]

Default construct to NULL.

Postconditons:

Definition at line 60 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
RTOpPack::Teuchos::Ptr< T >::Ptr ( T *  ptr) [inline, explicit]

Construct given a raw pointer.

Postconditons:

Note: This constructor is declared explicit so there is no implicit conversion from a raw C++ pointer to a Ptr object. This is meant to avoid cases where an uninitialized pointer is used to implicitly initialize one of these objects.

Definition at line 66 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
RTOpPack::Teuchos::Ptr< T >::Ptr ( const Ptr< T > &  ptr) [inline]

Copy construct from same type.

Postconditons:

  • this->get() == ptr.get()

Definition at line 72 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
template<class T2 >
RTOpPack::Teuchos::Ptr< T >::Ptr ( const Ptr< T2 > &  ptr) [inline]

Copy construct from another type.

Postconditons:

  • this->get() == ptr.get() (unless virtual base classes are involved)

Definition at line 79 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
RTOpPack::Teuchos::Ptr< T >::Ptr ( ENull  null_in = null) [inline]

Default construct to NULL.

Postconditons:

template<class T >
RTOpPack::Teuchos::Ptr< T >::Ptr ( T *  ptr) [inline, explicit]

Construct given a raw pointer.

Postconditons:

Note: This constructor is declared explicit so there is no implicit conversion from a raw C++ pointer to a Ptr object. This is meant to avoid cases where an uninitialized pointer is used to implicitly initialize one of these objects.

template<class T >
RTOpPack::Teuchos::Ptr< T >::Ptr ( const Ptr< T > &  ptr) [inline]

Copy construct from same type.

Postconditons:

  • this->get() == ptr.get()
template<class T >
template<class T2 >
RTOpPack::Teuchos::Ptr< T >::Ptr ( const Ptr< T2 > &  ptr) [inline]

Copy construct from another type.

Postconditons:

  • this->get() == ptr.get() (unless virtual base classes are involved)

Member Function Documentation

template<class T >
Ptr< T > & RTOpPack::Teuchos::Ptr< T >::operator= ( const Ptr< T > &  ptr) [inline]

Shallow copy of the underlying pointer.

Postconditons:

  • this->get() == ptr.get()

Definition at line 85 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
T * RTOpPack::Teuchos::Ptr< T >::operator-> ( ) const [inline]

Pointer (->) access to members of underlying object.

Preconditions:

  • this->get() != NULL (throws std::logic_error)

Definition at line 93 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
T & RTOpPack::Teuchos::Ptr< T >::operator* ( ) const [inline]

Dereference the underlying object.

Preconditions:

  • this->get() != NULL (throws std::logic_error)

Definition at line 102 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
T * RTOpPack::Teuchos::Ptr< T >::get ( ) const [inline]

Get the raw C++ pointer to the underlying object.

Definition at line 111 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
T * RTOpPack::Teuchos::Ptr< T >::getRawPtr ( ) const [inline]

Get the raw C++ pointer to the underlying object.

Definition at line 119 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
const Ptr< T > & RTOpPack::Teuchos::Ptr< T >::assert_not_null ( ) const [inline]

Throws std::logic_error if this->get()==NULL, otherwise returns reference to *this.

Definition at line 126 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
const Ptr< T > RTOpPack::Teuchos::Ptr< T >::ptr ( ) const [inline]

Return a copy of *this.

Definition at line 135 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
Ptr< const T > RTOpPack::Teuchos::Ptr< T >::getConst ( ) const [inline]

Return a Ptr<const T> version of *this.

Definition at line 142 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
Ptr<T>& RTOpPack::Teuchos::Ptr< T >::operator= ( const Ptr< T > &  ptr)

Shallow copy of the underlying pointer.

Postconditons:

  • this->get() == ptr.get()
template<class T >
T* RTOpPack::Teuchos::Ptr< T >::operator-> ( ) const [inline]

Pointer (->) access to members of underlying object.

Preconditions:

  • this->get() != NULL (throws std::logic_error)
template<class T >
T& RTOpPack::Teuchos::Ptr< T >::operator* ( ) const [inline]

Dereference the underlying object.

Preconditions:

  • this->get() != NULL (throws std::logic_error)
template<class T >
T* RTOpPack::Teuchos::Ptr< T >::get ( ) const [inline]

Get the raw C++ pointer to the underlying object.

template<class T >
T* RTOpPack::Teuchos::Ptr< T >::getRawPtr ( ) const [inline]

Get the raw C++ pointer to the underlying object.

template<class T >
const Ptr<T>& RTOpPack::Teuchos::Ptr< T >::assert_not_null ( ) const [inline]

Throws std::logic_error if this->get()==NULL, otherwise returns reference to *this.

template<class T >
const Ptr<T> RTOpPack::Teuchos::Ptr< T >::ptr ( ) const [inline]

Return a copy of *this.

template<class T >
Ptr<const T> RTOpPack::Teuchos::Ptr< T >::getConst ( ) const [inline]

Return a Ptr<const T> version of *this.


Friends And Related Function Documentation

template<class T >
bool is_null ( const Ptr< T > &  p) [related]

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

Definition at line 340 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
bool nonnull ( const Ptr< T > &  p) [related]

Returns true if p.get()!=NULL

Definition at line 351 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
bool operator== ( const Ptr< T > &  p,
ENull   
) [related]

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

Definition at line 362 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
bool operator!= ( const Ptr< T > &  p,
ENull   
) [related]

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

Definition at line 373 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T1 , class T2 >
bool operator== ( const Ptr< T1 > &  p1,
const Ptr< T2 > &  p2 
) [related]

Return true if two Ptr objects point to the same object.

Definition at line 384 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T1 , class T2 >
bool operator!= ( const Ptr< T1 > &  p1,
const Ptr< T2 > &  p2 
) [related]

Return true if two Ptr objects do not point to the same object.

Definition at line 396 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T2 , class T1 >
Ptr< T2 > ptr_implicit_cast ( const Ptr< T1 > &  p1) [related]

Implicit cast of underlying Ptr 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 414 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T2 , class T1 >
Ptr< T2 > ptr_static_cast ( const Ptr< T1 > &  p1) [related]

Static cast of underlying Ptr 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 ptr_dynamic_cast<T2>(p1).

Definition at line 434 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T2 , class T1 >
Ptr< T2 > ptr_const_cast ( const Ptr< T1 > &  p1) [related]

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

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

Definition at line 449 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T2 , class T1 >
Ptr< T2 > ptr_dynamic_cast ( const Ptr< T1 > &  p1,
bool  throw_on_fail = false 
) [related]

Dynamic cast of underlying Ptr 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 std::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 std::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 481 of file RTOpPack_SPMD_apply_op_def.hpp.

template<class T >
std::ostream & operator<< ( std::ostream &  out,
const Ptr< T > &  p 
) [related]

Output stream inserter.

The implementation of this function just print pointer addresses and therefore puts no restrictions on the data types involved.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends