42 #ifndef TEUCHOS_RCP_DECL_HPP
43 #define TEUCHOS_RCP_DECL_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;
502 template<
class Dealloc_T>
651 inline T*
get()
const;
666 inline explicit operator bool()
const;
816 #if defined(HAVE_TEUCHOSCORE_CXX11) && defined(HAVE_TEUCHOS_THREAD_SAFE)
818 inline RCP<T> create_strong_thread_safe()
const;
855 #ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
937 template<
class Dealloc_T>
941 #ifndef DOXYGEN_COMPILE
945 inline T* access_private_ptr()
const;
957 template<
class T1,
class T2>
inline
959 return p1.
get() < p2.
get();
967 template<
class T1,
class T2>
inline
969 return p1.
get() < p2.
get();
1020 void free( T* ptr ) {
if(ptr)
delete ptr; }
1036 void free( T* ptr ) {
if(ptr)
delete [] ptr; }
1052 template<
class T,
class DeleteFunctor>
1069 template<
class T,
class DeleteFunctor>
1090 template<
class T,
class DeleteHandleFunctor>
1108 template<
class T,
class DeleteHandleFunctor>
1124 template<
class T,
class Embedded,
class Dealloc>
1157 template<
class T,
class Embedded >
1170 template<
class T,
class Embedded >
1201 template<
class T>
inline
1209 template <
typename T,
typename ... Args>
1213 new T(std::forward<Args>(args)...)
1260 template<
class T,
class Dealloc_T>
inline
1261 RCP<T> rcpWithDealloc(T* p, Dealloc_T dealloc,
bool owns_mem=
true);
1265 template<
class T,
class Dealloc_T>
inline
1266 TEUCHOS_DEPRECATED
RCP<T> rcp( T* p, Dealloc_T dealloc,
bool owns_mem )
1268 return rcpWithDealloc(p, dealloc, owns_mem);
1283 template<
class T,
class Dealloc_T>
inline
1284 RCP<T> rcpWithDeallocUndef(T* p, Dealloc_T dealloc,
bool owns_mem=
true);
1296 template<
class T>
inline
1297 RCP<T> rcpFromRef(T& r);
1309 template<
class T>
inline
1310 RCP<T> rcpFromUndefRef(T& r);
1323 template<
class T,
class Embedded>
inline
1325 rcpWithEmbeddedObjPreDestroy( T* p,
const Embedded &embedded,
bool owns_mem =
true );
1338 template<
class T,
class Embedded>
inline
1340 rcpWithEmbeddedObjPostDestroy( T* p,
const Embedded &embedded,
bool owns_mem =
true );
1354 template<
class T,
class Embedded>
inline
1356 rcpWithEmbeddedObj( T* p,
const Embedded &embedded,
bool owns_mem =
true );
1373 template<
class T,
class ParentT>
1374 RCP<T> rcpWithInvertedObjOwnership(
const RCP<T> &child,
const RCP<ParentT> &parent);
1391 RCP<T> rcpCloneNode(
const RCP<T> &p);
1398 template<
class T>
inline
1399 bool is_null(
const RCP<T> &p );
1406 template<
class T>
inline
1407 bool nonnull(
const RCP<T> &p );
1414 template<
class T>
inline
1422 template<
class T>
inline
1431 template<
class T1,
class T2>
inline
1432 bool operator==(
const RCP<T1> &p1,
const RCP<T2> &p2 );
1440 template<
class T1,
class T2>
inline
1441 bool operator!=(
const RCP<T1> &p1,
const RCP<T2> &p2 );
1453 template<
class T2,
class T1>
inline
1454 RCP<T2> rcp_implicit_cast(
const RCP<T1>& p1);
1467 template<
class T2,
class T1>
inline
1468 RCP<T2> rcp_static_cast(
const RCP<T1>& p1);
1477 template<
class T2,
class T1>
inline
1478 RCP<T2> rcp_const_cast(
const RCP<T1>& p1);
1504 template<
class T2,
class T1>
inline
1505 RCP<T2> rcp_dynamic_cast(
1506 const RCP<T1>& p1,
bool throw_on_fail =
false
1568 template<
class T1,
class T2>
1569 void set_extra_data(
const T1 &extra_data,
const std::string& name,
1571 bool force_unique =
true);
1592 template<
class T1,
class T2>
1593 const T1& get_extra_data(
const RCP<T2>& p,
const std::string& name );
1615 template<
class T1,
class T2>
1616 T1& get_nonconst_extra_data( RCP<T2>& p,
const std::string& name );
1643 template<
class T1,
class T2>
1644 Ptr<const T1> get_optional_extra_data(
const RCP<T2>& p,
const std::string& name );
1671 template<
class T1,
class T2>
1672 Ptr<T1> get_optional_nonconst_extra_data( RCP<T2>& p,
const std::string& name );
1686 template<
class Dealloc_T,
class T>
1687 const Dealloc_T& get_dealloc(
const RCP<T>& p );
1701 template<
class Dealloc_T,
class T>
1702 Dealloc_T& get_nonconst_dealloc(
const RCP<T>& p );
1719 template<
class Dealloc_T,
class T>
1720 Ptr<const Dealloc_T> get_optional_dealloc(
const RCP<T>& p );
1737 template<
class Dealloc_T,
class T>
1738 Ptr<Dealloc_T> get_optional_nonconst_dealloc(
const RCP<T>& p );
1747 template<
class TOrig,
class Embedded,
class T>
1748 const Embedded& getEmbeddedObj(
const RCP<T>& p );
1757 template<
class TOrig,
class Embedded,
class T>
1758 Embedded& getNonconstEmbeddedObj(
const RCP<T>& p );
1767 template<
class TOrig,
class Embedded,
class T>
1768 Ptr<const Embedded> getOptionalEmbeddedObj(
const RCP<T>& p );
1777 template<
class TOrig,
class Embedded,
class T>
1778 Ptr<Embedded> getOptionalNonconstEmbeddedObj(
const RCP<T>& p );
1786 template<
class ParentT,
class T>
1798 std::ostream& operator<<( std::ostream& out, const RCP<T>& p );
1804 #endif // TEUCHOS_RCP_DECL_HPP
~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.
ERCPStrength
Used to specify if the pointer is weak or strong.
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).
bool operator()(const RCP< T1 > p1, const RCP< T2 > p2) const
EPrePostDestruction prePostDestroy_
const RCP< T > & debug_assert_not_null() const
Calls assert_not_null() in a debug build.
RCP< T > create_weak() const
Create a new weak RCP object from another (strong) RCP object.
T ptr_t
Gives the type (required)
bool operator()(const RCP< const T1 > p1, const RCP< const T2 > p2) const
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to delete it...
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
Deallocator subclass that Allows any functor object (including a function pointer) to be used to free...
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
DeleteFunctor deleteFunctor_
DeallocFunctorDelete(DeleteFunctor deleteFunctor)
void swap(RCP< T > &r_ptr)
Swap the contents with some other RCP 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.
ENull
Used to initialize a RCP object to NULL using an implicit conversion!
ERCPStrength strength() const
Strength of the pointer.
ERCPUndefinedWeakNoDealloc
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.
Struct for comparing two RCPs. Simply compares the raw pointers contained within the RCPs...
DeleteHandleFunctor deleteHandleFunctor_
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
Struct for comparing two RCPs. Simply compares the raw pointers contained within the RCPs...
bool operator!=(const Allocator< T > &a_t, const Allocator< U > &a_u)
Return ! (a_t == a_u) (see above).
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 [].
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
EmbeddedObjDealloc(const Embedded &embedded, EPrePostDestruction prePostDestroy, Dealloc dealloc)
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< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
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.
RCP< T > & operator=(const RCP< T > &r_ptr)
Copy the pointer to the referenced object and increment the reference count.
const Embedded & getObj() const
Base traits class for getting a properly initialized null pointer.
Embedded & getNonconstObj()
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.
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
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.
Policy class for deallocator for non-owned RCPs.
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.
Smart reference counting pointer class for automatic garbage collection.
static RCP< T > getNull()
bool operator==(BigUInt< n > const &a, BigUInt< n > const &b)
void setObj(const Embedded &embedded)
Reference-counted pointer node classes.
void free(T *ptr)
Deallocates a pointer ptr using delete [] ptr (required).
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()).
DeallocFunctorHandleDelete(DeleteHandleFunctor deleteHandleFunctor)
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
auto make_rcp(Args &&...args)
DeallocFunctorHandleDelete()
bool is_null() const
Returns true if the underlying pointer is null.