10#ifndef TEUCHOS_RCP_DECL_HPP
11#define TEUCHOS_RCP_DECL_HPP
20#include "Teuchos_ENull.hpp"
21#include "Teuchos_NullIteratorTraits.hpp"
24#ifdef REFCOUNTPTR_INLINE_FUNCS
25# define REFCOUNTPTR_INLINE inline
27# define REFCOUNTPTR_INLINE
32# define TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
40template<
class T>
class Ptr;
43enum ERCPWeakNoDealloc { RCP_WEAK_NO_DEALLOC };
44enum ERCPUndefinedWeakNoDealloc { RCP_UNDEFINED_WEAK_NO_DEALLOC };
45enum ERCPUndefinedWithDealloc { RCP_UNDEFINED_WITH_DEALLOC };
470 template<
class Dealloc_T>
619 inline T*
get()
const;
634 inline explicit operator bool()
const;
784#if defined(HAVE_TEUCHOSCORE_CXX11) && defined(HAVE_TEUCHOS_THREAD_SAFE)
823#ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
885 inline explicit RCP(
T*
p, ERCPWeakNoDealloc);
897 inline explicit RCP(
T*
p, ERCPUndefinedWeakNoDealloc);
905 template<
class Dealloc_T>
909#ifndef DOXYGEN_COMPILE
913 inline T* access_private_ptr()
const;
925 template<
class T1,
class T2>
inline
935 template<
class T1,
class T2>
inline
955 static RCP<T> getNull() {
return null; }
988 void free(
T* ptr ) {
if(ptr)
delete ptr; }
1004 void free(
T* ptr ) {
if(ptr)
delete [] ptr; }
1020template<
class T,
class DeleteFunctor>
1026 void free(
T* ptr ) {
if(ptr) deleteFunctor_(ptr); }
1037template<
class T,
class DeleteFunctor>
1058template<
class T,
class DeleteHandleFunctor>
1065 void free(
T* ptr ) {
if(ptr) {
T **
hdl = &ptr; deleteHandleFunctor_(
hdl); } }
1076template<
class T,
class DeleteHandleFunctor>
1092template<
class T,
class Embedded,
class Dealloc>
1096 typedef typename Dealloc::ptr_t ptr_t;
1103 const Embedded& getObj()
const {
return embedded_; }
1104 Embedded& getNonconstObj() {
return embedded_; }
1107 if (prePostDestroy_ == PRE_DESTROY)
1110 if (prePostDestroy_ == POST_DESTROY)
1125template<
class T,
class Embedded >
1138template<
class T,
class Embedded >
1169template<
class T>
inline
1177template <
typename T,
typename ...
Args>
1181 new T(std::forward<Args>(
args)...)
1228template<
class T,
class Dealloc_T>
inline
1233template<
class T,
class Dealloc_T>
inline
1251template<
class T,
class Dealloc_T>
inline
1264template<
class T>
inline
1277template<
class T>
inline
1291template<
class T,
class Embedded>
inline
1306template<
class T,
class Embedded>
inline
1322template<
class T,
class Embedded>
inline
1341template<
class T,
class ParentT>
1366template<
class T>
inline
1374template<
class T>
inline
1382template<
class T>
inline
1390template<
class T>
inline
1399template<
class T1,
class T2>
inline
1408template<
class T1,
class T2>
inline
1421template<
class T2,
class T1>
inline
1435template<
class T2,
class T1>
inline
1445template<
class T2,
class T1>
inline
1472template<
class T2,
class T1>
inline
1536template<
class T1,
class T2>
1560template<
class T1,
class T2>
1583template<
class T1,
class T2>
1611template<
class T1,
class T2>
1639template<
class T1,
class T2>
1654template<
class Dealloc_T,
class T>
1669template<
class Dealloc_T,
class T>
1687template<
class Dealloc_T,
class T>
1705template<
class Dealloc_T,
class T>
1715template<
class TOrig,
class Embedded,
class T>
1725template<
class TOrig,
class Embedded,
class T>
1735template<
class TOrig,
class Embedded,
class T>
1745template<
class TOrig,
class Embedded,
class T>
1754template<
class ParentT,
class T>
Reference-counted pointer node classes.
Deallocator class that uses delete [] to delete memory allocated uisng new []
T ptr_t
Gives the type (required)
void free(T *ptr)
Deallocates a pointer ptr using delete [] ptr (required).
Policy class for deallocator that uses delete to delete a pointer which is used by RCP.
T ptr_t
Gives the type (required)
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
Deallocator subclass that Allows any functor object (including a function pointer) to be used to free...
DeallocFunctorDelete< T, DeleteFunctor > deallocFunctorDelete(DeleteFunctor deleteFunctor)
A simple function used to create a functor deallocator object.
Deallocator subclass that Allows any functor object (including a function pointer) to be used to free...
DeallocFunctorHandleDelete< T, DeleteHandleFunctor > deallocFunctorHandleDelete(DeleteHandleFunctor deleteHandleFunctor)
A simple function used to create a functor deallocator object.
Policy class for deallocator for non-owned RCPs.
T ptr_t
Gives the type (required)
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
A deallocator class that wraps a simple value object and delegates to another deallocator object.
EmbeddedObjDealloc< T, Embedded, DeallocArrayDelete< T > > embeddedObjDeallocArrayDelete(const Embedded &embedded, EPrePostDestruction prePostDestroy)
Create a dealocator with an embedded object using delete [].
EmbeddedObjDealloc< T, Embedded, DeallocDelete< T > > embeddedObjDeallocDelete(const Embedded &embedded, EPrePostDestruction prePostDestroy)
Create a dealocator with an embedded object using delete.
Base traits class for getting a properly initialized null pointer.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Smart reference counting pointer class for automatic garbage collection.
RCP< const T > getConst() const
Return an RCP<const T> version of *this.
RCP< T > rcpWithEmbeddedObjPreDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
RCP< T > create_weak() const
Create a new weak RCP object from another (strong) RCP object.
bool operator==(const RCP< T1 > &p1, const RCP< T2 > &p2)
Return true if two RCP objects point to the same referenced-counted object and have the same node.
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
bool is_null(const RCP< T > &p)
Returns true if p.get()==NULL.
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 > rcp(T *p, bool owns_mem=true)
Create a RCP object properly typed.
RCP< T2 > rcp_static_cast(const RCP< T1 > &p1)
Static cast of underlying RCP type from T1* to T2*.
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 > release()
Release the ownership of the underlying dynamically allocated object.
void reset()
Reset to null.
void set_has_ownership()
Give this and other RCP<> objects ownership of the referenced object this->get().
~RCP()
Removes a reference to a dynamically allocated object and possibly deletes the object if owned.
const RCP< T > & assert_valid_ptr() const
If the object pointer is non-null, assert that it is still valid.
bool operator!=(const RCP< T > &p, ENull)
Returns true if p.get()!=NULL.
Ptr< Dealloc_T > get_optional_nonconst_dealloc(const RCP< T > &p)
Return a pointer to the underlying non-const deallocator object if it exists.
bool shares_resource(const RCP< T2 > &r_ptr) const
Returns true if the smart pointers share the same underlying reference-counted object.
RCP< T > rcpWithEmbeddedObj(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
Embedded & getNonconstEmbeddedObj(const RCP< T > &p)
Get a non-const reference to an embedded object that was set by calling rcpWithEmbeddedObjPreDestroy(...
RCP< T2 > rcp_implicit_cast(const RCP< T1 > &p1)
Implicit cast of underlying RCP type from T1* to T2*.
const Dealloc_T & get_dealloc(const RCP< T > &p)
Return a const reference to the underlying deallocator object.
Dealloc_T & get_nonconst_dealloc(const RCP< T > &p)
Return a non-const reference to the underlying deallocator object.
void swap(RCP< T > &r_ptr)
Swap the contents with some other RCP object.
RCP< T2 > rcp_const_cast(const RCP< T1 > &p1)
Constant cast of underlying RCP type from T1* to T2*.
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.
RCP< T > rcpFromRef(T &r)
Return a non-owning weak RCP object from a raw object reference for a defined type.
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.
bool is_null() const
Returns true if the underlying pointer is null.
RCP< T > rcpFromUndefRef(T &r)
Return a non-owning weak RCP object from a raw object reference for an undefined type.
RCP< T > rcpWithEmbeddedObjPostDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
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 > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
const RCP< T > & debug_assert_valid_ptr() const
Calls assert_valid_ptr() in a debug build.
std::ostream & operator<<(std::ostream &out, const RCP< T > &p)
Output stream inserter.
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.
T * operator->() const
Pointer (->) access to members of underlying object.
bool is_valid_ptr() const
Return if the underlying object pointer is still valid or not.
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.
RCP< T > create_strong() const
Create a new strong RCP object from another (weak) RCP object.
RCP< T > rcpWithInvertedObjOwnership(const RCP< T > &child, const RCP< ParentT > &parent)
Create a new RCP that inverts the ownership of parent and child.
Ptr< const Dealloc_T > get_optional_dealloc(const RCP< T > &p)
Return a pointer to the underlying const deallocator object if it exists.
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to delete it.
bool operator!=(const RCP< T1 > &p1, const RCP< T2 > &p2)
Return true if two RCP objects do not point to the same referenced-counted object and have the same n...
bool nonnull(const RCP< T > &p)
Returns true if p.get()!=NULL.
T * get() const
Get the raw C++ pointer to the underlying object.
ERCPStrength strength() const
Strength of the pointer.
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.
RCP< T > rcpCloneNode(const RCP< T > &p)
Allocate a new RCP object with a new RCPNode with memory pointing to the initial node.
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 weak_count() const
Return the number of active RCP<> objects that have a "weak" reference to the underlying reference-co...
ENull
Used to initialize a RCP object to NULL using an implicit conversion!
const RCP< T > & debug_assert_not_null() const
Calls assert_not_null() in a debug build.
RCP< T > & operator=(const RCP< T > &r_ptr)
Copy the pointer to the referenced object and increment the reference count.
int total_count() const
Total count (strong_count() + weak_count()).
bool operator==(const RCP< T > &p, ENull)
Returns true if p.get()==NULL.
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
const Embedded & getEmbeddedObj(const RCP< T > &p)
Get a const reference to an embedded object that was set by calling rcpWithEmbeddedObjPreDestroy(),...
Ptr< T > operator()() const
Shorthand for ptr().
T & operator*() const
Dereference the underlying object.
Handle class that manages the RCPNode's reference counting.
ERCPStrength
Used to specify if the pointer is weak or strong.
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
auto make_rcp(Args &&... args)
RCP< ParentT > getInvertedObjOwnershipParent(const RCP< T > &invertedChild)
Get the parent back from an inverted ownership RCP.
Struct for comparing two RCPs. Simply compares the raw pointers contained within the RCPs.
bool operator()(const RCP< T1 > p1, const RCP< T2 > p2) const
Struct for comparing two RCPs. Simply compares the raw pointers contained within the RCPs.
bool operator()(const RCP< const T1 > p1, const RCP< const T2 > p2) const