#include <Teuchos_PtrDecl.hpp>
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. | |
Related Functions | |
| (Note that these are not member functions.) | |
| Ptr< T > | outArg (T &arg) |
| create a non-persisting (required or optional) output argument for a function call. | |
| Ptr< T > | inOutArg (T &arg) |
| create a non-persisting (required or optional) input/output argument for a function call. | |
| Ptr< const T > | ptrInArg (T &arg) |
create a general Ptr input argument for a function call from a reference. | |
| Ptr< T > | optInArg (T &arg) |
| create a non-persisting non-const optional input argument for a function call. | |
| Ptr< const T > | constOptInArg (T &arg) |
| create a non-persisting const optional input argument for a function call. | |
| Ptr< T > | ptrFromRef (T &arg) |
| Create a pointer to a object from an object reference. | |
| Ptr< T > | ptr (T *p) |
| Create a pointer to an object from a raw pointer. | |
| Ptr< const T > | constPtr (T &arg) |
| Create a pointer from a const object given a non-const object reference. | |
| bool | is_null (const Ptr< T > &p) |
| Returns if is null or not. | |
| bool | operator== (const Ptr< T > &p, ENull) |
Returns true if p.get()==NULL. | |
| bool | operator!= (const Ptr< T > &p, ENull) |
Returns true if p.get()!=NULL. | |
| bool | operator== (const Ptr< T1 > &p1, const Ptr< T2 > &p2) |
Return true if two Ptr objects point to the same object. | |
| bool | operator!= (const Ptr< T1 > &p1, const Ptr< T2 > &p2) |
Return true if two Ptr objects do not point to the same object. | |
| Ptr< T2 > | ptr_implicit_cast (const Ptr< T1 > &p1) |
Implicit cast of underlying Ptr type from T1* to T2*. | |
| Ptr< T2 > | ptr_static_cast (const Ptr< T1 > &p1) |
Static cast of underlying Ptr type from T1* to T2*. | |
| Ptr< T2 > | ptr_const_cast (const Ptr< T1 > &p1) |
Constant cast of underlying Ptr type from T1* to T2*. | |
| Ptr< T2 > | ptr_dynamic_cast (const Ptr< T1 > &p1, bool throw_on_fail=false) |
Dynamic cast of underlying Ptr type from T1* to T2*. | |
| std::ostream & | operator<< (std::ostream &out, const Ptr< T > &p) |
| Output stream inserter. | |
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:
Ptr objects always default construct to null
Ptr objects will throw exceptions on attempts to dereference the underlying null pointer when debugging support is compiled in.
Ptr does not allow array-like operations like ptr[i], ++ptr or ptr+i that can only result in disaster when the a pointer points to only a single object that can not be assumed to be part of an array of objects.
Ptr is part of a system of types defined in Teuchos that keeps your code away from raw pointers which are the cause of most defects in C++ code.
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.
|
||||||||||
|
Default construct to NULL. Postconditons:
|
|
||||||||||
|
Construct given a raw pointer. Postconditons:
Note: This constructor is declared |
|
||||||||||
|
Copy construct from same type. Postconditons:
|
|
||||||||||||||
|
Copy construct from another type. Postconditons:
|
|
||||||||||
|
Shallow copy of the underlying pointer. Postconditons:
|
|
|||||||||
|
Pointer ( Preconditions:
|
|
|||||||||
|
Dereference the underlying object. Preconditions:
|
|
|||||||||
|
Get the raw C++ pointer to the underlying object.
|
|
|||||||||
|
Get the raw C++ pointer to the underlying object.
|
|
|||||||||
|
Throws
|
|
||||||||||
|
create a non-persisting (required or optional) output argument for a function call.
|
|
||||||||||
|
create a non-persisting (required or optional) input/output argument for a function call.
|
|
||||||||||
|
create a general
|
|
||||||||||
|
create a non-persisting non-const optional input argument for a function call.
|
|
||||||||||
|
create a non-persisting const optional input argument for a function call.
|
|
||||||||||
|
Create a pointer to a object from an object reference.
|
|
||||||||||
|
Create a pointer to an object from a raw pointer.
|
|
||||||||||
|
Create a pointer from a const object given a non-const object reference.
Warning! Do not call this function if |
|
||||||||||
|
Returns if is null or not.
|
|
||||||||||||||||
|
Returns true if
|
|
||||||||||||||||
|
Returns true if
|
|
||||||||||||||||
|
Return true if two
|
|
||||||||||||||||
|
Return true if two
|
|
||||||||||
|
Implicit cast of underlying
The function will compile only if ( 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++. |
|
||||||||||
|
Static cast of underlying
The function will compile only if (
This can safely be used for conversion down an inheritance hierarchy with polymorphic types only if |
|
||||||||||
|
Constant cast of underlying
This function will compile only if ( |
|
||||||||||||||||
|
Dynamic cast of underlying
|
|
||||||||||||||||
|
Output stream inserter. The implementation of this function just print pointer addresses and therefore puts no restrictions on the data types involved. |
1.3.9.1