42 #ifndef TEUCHOS_RCP_DECL_HPP 43 #define TEUCHOS_RCP_DECL_HPP 52 #include "Teuchos_ENull.hpp" 53 #include "Teuchos_NullIteratorTraits.hpp" 56 #ifdef REFCOUNTPTR_INLINE_FUNCS 57 # define REFCOUNTPTR_INLINE inline 59 # define REFCOUNTPTR_INLINE 64 # define TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL 72 template<
class T>
class Ptr;
75 enum ERCPWeakNoDealloc { RCP_WEAK_NO_DEALLOC };
76 enum ERCPUndefinedWeakNoDealloc { RCP_UNDEFINED_WEAK_NO_DEALLOC };
77 enum ERCPUndefinedWithDealloc { RCP_UNDEFINED_WITH_DEALLOC };
502 template<
class Dealloc_T>
619 inline T*
get()
const;
817 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL 854 TEUCHOS_DEPRECATED
inline int count()
const;
882 inline explicit RCP(T* p, ERCPWeakNoDealloc);
894 inline explicit RCP(T* p, ERCPUndefinedWeakNoDealloc);
902 template<
class Dealloc_T>
903 inline RCP(T* p, Dealloc_T dealloc, ERCPUndefinedWithDealloc,
906 #ifndef DOXYGEN_COMPILE 910 inline T* access_private_ptr()
const;
922 template<
class T1,
class T2>
inline 924 return p1.
get() < p2.
get();
932 template<
class T1,
class T2>
inline 934 return p1.
get() < p2.
get();
952 static RCP<T> getNull() {
return null; }
1017 template<
class T,
class DeleteFunctor>
1023 void free( T*
ptr ) {
if(ptr) deleteFunctor_(ptr); }
1025 DeleteFunctor deleteFunctor_;
1034 template<
class T,
class DeleteFunctor>
1055 template<
class T,
class DeleteHandleFunctor>
1060 : deleteHandleFunctor_(deleteHandleFunctor) {}
1062 void free( T*
ptr ) {
if(ptr) { T **hdl = &
ptr; deleteHandleFunctor_(hdl); } }
1064 DeleteHandleFunctor deleteHandleFunctor_;
1073 template<
class T,
class DeleteHandleFunctor>
1089 template<
class T,
class Embedded,
class Dealloc>
1093 typedef typename Dealloc::ptr_t ptr_t;
1097 ) : embedded_(embedded), prePostDestroy_(prePostDestroy), dealloc_(dealloc)
1099 void setObj(
const Embedded &embedded ) { embedded_ = embedded; }
1100 const Embedded& getObj()
const {
return embedded_; }
1101 Embedded& getNonconstObj() {
return embedded_; }
1104 if (prePostDestroy_ == PRE_DESTROY)
1105 embedded_ = Embedded();
1107 if (prePostDestroy_ == POST_DESTROY)
1108 embedded_ = Embedded();
1122 template<
class T,
class Embedded >
1135 template<
class T,
class Embedded >
1166 template<
class T>
inline 1213 template<
class T,
class Dealloc_T>
inline 1218 template<
class T,
class Dealloc_T>
inline 1219 TEUCHOS_DEPRECATED
RCP<T> rcp( T* p, Dealloc_T dealloc,
bool owns_mem )
1236 template<
class T,
class Dealloc_T>
inline 1249 template<
class T>
inline 1262 template<
class T>
inline 1276 template<
class T,
class Embedded>
inline 1291 template<
class T,
class Embedded>
inline 1307 template<
class T,
class Embedded>
inline 1326 template<
class T,
class ParentT>
1351 template<
class T>
inline 1359 template<
class T>
inline 1367 template<
class T>
inline 1375 template<
class T>
inline 1384 template<
class T1,
class T2>
inline 1393 template<
class T1,
class T2>
inline 1406 template<
class T2,
class T1>
inline 1420 template<
class T2,
class T1>
inline 1430 template<
class T2,
class T1>
inline 1457 template<
class T2,
class T1>
inline 1459 const RCP<T1>& p1,
bool throw_on_fail =
false 1521 template<
class T1,
class T2>
1522 void set_extra_data(
const T1 &extra_data,
const std::string& name,
1524 bool force_unique =
true);
1545 template<
class T1,
class T2>
1568 template<
class T1,
class T2>
1596 template<
class T1,
class T2>
1624 template<
class T1,
class T2>
1639 template<
class Dealloc_T,
class T>
1654 template<
class Dealloc_T,
class T>
1672 template<
class Dealloc_T,
class T>
1690 template<
class Dealloc_T,
class T>
1700 template<
class TOrig,
class Embedded,
class T>
1710 template<
class TOrig,
class Embedded,
class T>
1720 template<
class TOrig,
class Embedded,
class T>
1730 template<
class TOrig,
class Embedded,
class T>
1739 template<
class ParentT,
class T>
1751 std::ostream& operator<<( std::ostream& out, const RCP<T>& p );
1757 #endif // TEUCHOS_RCP_DECL_HPP RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
~RCP()
Removes a reference to a dynamically allocated object and possibly deletes the object if owned...
RCP< const T > getConst() const
Return an RCP<const T> version of *this.
RCP< T > rcpWithInvertedObjOwnership(const RCP< T > &child, const RCP< ParentT > &parent)
Create a new RCP that inverts the ownership of parent and child.
RCP< T2 > rcp_static_cast(const RCP< T1 > &p1)
Static cast of underlying RCP type from T1* to T2*.
RCP(ENull null_arg=null)
Initialize RCP<T> to NULL.
DeallocFunctorHandleDelete< T, DeleteHandleFunctor > deallocFunctorHandleDelete(DeleteHandleFunctor deleteHandleFunctor)
A simple function used to create a functor deallocator object.
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
T1 & get_nonconst_extra_data(RCP< T2 > &p, const std::string &name)
Get a non-const reference to extra data associated with a RCP object.
const RCP< T > & debug_assert_not_null() const
Calls assert_not_null() in a debug build.
Ptr< T1 > get_optional_nonconst_extra_data(RCP< T2 > &p, const std::string &name)
Get a pointer to non-const extra data (if it exists) associated with a RCP object.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
RCP< T > create_weak() const
Create a new weak RCP object from another (strong) RCP object.
T ptr_t
Gives the type (required)
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to delete it...
Deallocator subclass that Allows any functor object (including a function pointer) to be used to free...
Ptr< const T1 > get_optional_extra_data(const RCP< T2 > &p, const std::string &name)
Get a pointer to const extra data (if it exists) associated with a RCP object.
void swap(RCP< T > &r_ptr)
Swap the contents with some other RCP object.
Dealloc_T & get_nonconst_dealloc(const RCP< T > &p)
Return a non-const reference to the underlying deallocator object.
RCP< T > create_strong() const
Create a new strong RCP object from another (weak) RCP object.
T * get() const
Get the raw C++ pointer to the underlying object.
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< RCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a RCP object.
ENull
Used to initialize a RCP object to NULL using an implicit conversion!
ERCPStrength strength() const
Strength of the pointer.
A deallocator class that wraps a simple value object and delegates to another deallocator object...
T * operator->() const
Pointer (->) access to members of underlying object.
RCP< T > rcpWithEmbeddedObj(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
Struct for comparing two RCPs. Simply compares the raw pointers contained within the RCPs...
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
Embedded & getNonconstEmbeddedObj(const RCP< T > &p)
Get a non-const reference to an embedded object that was set by calling rcpWithEmbeddedObjPreDestroy(...
Ptr< Dealloc_T > get_optional_nonconst_dealloc(const RCP< T > &p)
Return a pointer to the underlying non-const deallocator object if it exists.
Struct for comparing two RCPs. Simply compares the raw pointers contained within the RCPs...
Policy class for deallocator that uses delete to delete a pointer which is used by RCP...
EmbeddedObjDealloc< T, Embedded, DeallocArrayDelete< T > > embeddedObjDeallocArrayDelete(const Embedded &embedded, EPrePostDestruction prePostDestroy)
Create a dealocator with an embedded object using delete [].
RCP< T2 > rcp_implicit_cast(const RCP< T1 > &p1)
Implicit cast of underlying RCP type from T1* to T2*.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
bool operator==(const RCP< T > &p, ENull)
Returns true if p.get()==NULL.
RCP< T > rcpCloneNode(const RCP< T > &p)
Allocate a new RCP object with a new RCPNode with memory pointing to the initial node.
RCP< T > rcpWithEmbeddedObjPostDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
TEUCHOS_DEPRECATED int count() const
Returns strong_count() [deprecated].
Deallocator class that uses delete [] to delete memory allocated uisng new []
const RCP< T > & assert_valid_ptr() const
If the object pointer is non-null, assert that it is still valid.
RCP< T > rcpWithEmbeddedObjPreDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
void set_has_ownership()
Give this and other RCP<> objects ownership of the referenced object this->get(). ...
void reset()
Reset to null.
const RCP< T > & debug_assert_valid_ptr() const
Calls assert_valid_ptr() in a debug build.
Ptr< Embedded > getOptionalNonconstEmbeddedObj(const RCP< T > &p)
Get an optional Ptr to a non-const embedded object if it was set by calling rcpWithEmbeddedObjPreDest...
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
RCP< T > rcpWithDeallocUndef(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy for an undefined type.
Ptr< T > operator()() const
Shorthand for ptr().
bool shares_resource(const RCP< T2 > &r_ptr) const
Returns true if the smart pointers share the same underlying reference-counted object.
T ptr_t
Gives the type (required)
T & operator*() const
Dereference the underlying object.
const Dealloc_T & get_dealloc(const RCP< T > &p)
Return a const reference to the underlying deallocator object.
ERCPStrength
Used to specify if the pointer is weak or strong.
RCP< T > & operator=(const RCP< T > &r_ptr)
Copy the pointer to the referenced object and increment the reference count.
Base traits class for getting a properly initialized null pointer.
bool nonnull(const RCP< T > &p)
Returns true if p.get()!=NULL.
bool operator!=(const RCP< T > &p, ENull)
Returns true if p.get()!=NULL.
const RCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
Ptr< T > release()
Release the ownership of the underlying dynamically allocated object.
T ptr_t
Gives the type (required)
EmbeddedObjDealloc< T, Embedded, DeallocDelete< T > > embeddedObjDeallocDelete(const Embedded &embedded, EPrePostDestruction prePostDestroy)
Create a dealocator with an embedded object using delete.
bool is_valid_ptr() const
Return if the underlying object pointer is still valid or not.
RCP< T > rcpFromUndefRef(T &r)
Return a non-owning weak RCP object from a raw object reference for an undefined type.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Handle class that manages the RCPNode's reference counting.
RCP< ParentT > getInvertedObjOwnershipParent(const RCP< T > &invertedChild)
Get the parent back from an inverted ownership RCP.
RCP< T > rcpFromRef(T &r)
Return a non-owning weak RCP object from a raw object reference for a defined type.
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
Policy class for deallocator for non-owned RCPs.
Deallocator subclass that Allows any functor object (including a function pointer) to be used to free...
const T1 & get_extra_data(const RCP< T2 > &p, const std::string &name)
Get a const reference to extra data associated with a RCP object.
DeallocFunctorDelete< T, DeleteFunctor > deallocFunctorDelete(DeleteFunctor deleteFunctor)
A simple function used to create a functor deallocator object.
Smart reference counting pointer class for automatic garbage collection.
RCP< T2 > rcp_const_cast(const RCP< T1 > &p1)
Constant cast of underlying RCP type from T1* to T2*.
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
Reference-counted pointer node classes.
void free(T *ptr)
Deallocates a pointer ptr using delete [] ptr (required).
Ptr< const Embedded > getOptionalEmbeddedObj(const RCP< T > &p)
Get an optional Ptr to a const embedded object if it was set by calling rcpWithEmbeddedObjPreDestroy(...
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
int weak_count() const
Return the number of active RCP<> objects that have a "weak" reference to the underlying reference-co...
int total_count() const
Total count (strong_count() + weak_count()).
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
const Embedded & getEmbeddedObj(const RCP< T > &p)
Get a const reference to an embedded object that was set by calling rcpWithEmbeddedObjPreDestroy(), rcpWithEmbeddedObjPostDestory(), or rcpWithEmbeddedObj().
Ptr< const Dealloc_T > get_optional_dealloc(const RCP< T > &p)
Return a pointer to the underlying const deallocator object if it exists.
bool is_null() const
Returns true if the underlying pointer is null.