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
40 template<
class T>
class Ptr;
43 enum ERCPWeakNoDealloc { RCP_WEAK_NO_DEALLOC };
44 enum ERCPUndefinedWeakNoDealloc { RCP_UNDEFINED_WEAK_NO_DEALLOC };
45 enum 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)
786 inline RCP<T> create_strong_thread_safe()
const;
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>
906 inline RCP(T* p, Dealloc_T dealloc, ERCPUndefinedWithDealloc,
909 #ifndef DOXYGEN_COMPILE
913 inline T* access_private_ptr()
const;
925 template<
class T1,
class T2>
inline
927 return p1.
get() < p2.
get();
935 template<
class T1,
class T2>
inline
937 return p1.
get() < p2.
get();
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; }
1020 template<
class T,
class DeleteFunctor>
1026 void free( T* ptr ) {
if(ptr) deleteFunctor_(ptr); }
1028 DeleteFunctor deleteFunctor_;
1037 template<
class T,
class DeleteFunctor>
1058 template<
class T,
class DeleteHandleFunctor>
1063 : deleteHandleFunctor_(deleteHandleFunctor) {}
1065 void free( T* ptr ) {
if(ptr) { T **hdl = &ptr; deleteHandleFunctor_(hdl); } }
1067 DeleteHandleFunctor deleteHandleFunctor_;
1076 template<
class T,
class DeleteHandleFunctor>
1092 template<
class T,
class Embedded,
class Dealloc>
1096 typedef typename Dealloc::ptr_t ptr_t;
1100 ) : embedded_(embedded), prePostDestroy_(prePostDestroy), dealloc_(dealloc)
1102 void setObj(
const Embedded &embedded ) { embedded_ = embedded; }
1103 const Embedded& getObj()
const {
return embedded_; }
1104 Embedded& getNonconstObj() {
return embedded_; }
1107 if (prePostDestroy_ == PRE_DESTROY)
1108 embedded_ = Embedded();
1110 if (prePostDestroy_ == POST_DESTROY)
1111 embedded_ = Embedded();
1125 template<
class T,
class Embedded >
1138 template<
class T,
class Embedded >
1169 template<
class T>
inline
1177 template <
typename T,
typename ... Args>
1181 new T(std::forward<Args>(args)...)
1228 template<
class T,
class Dealloc_T>
inline
1229 RCP<T> rcpWithDealloc(T* p, Dealloc_T dealloc,
bool owns_mem=
true);
1233 template<
class T,
class Dealloc_T>
inline
1234 TEUCHOS_DEPRECATED
RCP<T> rcp( T* p, Dealloc_T dealloc,
bool owns_mem )
1236 return rcpWithDealloc(p, dealloc, owns_mem);
1251 template<
class T,
class Dealloc_T>
inline
1252 RCP<T> rcpWithDeallocUndef(T* p, Dealloc_T dealloc,
bool owns_mem=
true);
1264 template<
class T>
inline
1265 RCP<T> rcpFromRef(T& r);
1277 template<
class T>
inline
1278 RCP<T> rcpFromUndefRef(T& r);
1291 template<
class T,
class Embedded>
inline
1293 rcpWithEmbeddedObjPreDestroy( T* p,
const Embedded &embedded,
bool owns_mem =
true );
1306 template<
class T,
class Embedded>
inline
1308 rcpWithEmbeddedObjPostDestroy( T* p,
const Embedded &embedded,
bool owns_mem =
true );
1322 template<
class T,
class Embedded>
inline
1324 rcpWithEmbeddedObj( T* p,
const Embedded &embedded,
bool owns_mem =
true );
1341 template<
class T,
class ParentT>
1342 RCP<T> rcpWithInvertedObjOwnership(
const RCP<T> &child,
const RCP<ParentT> &parent);
1359 RCP<T> rcpCloneNode(
const RCP<T> &p);
1366 template<
class T>
inline
1367 bool is_null(
const RCP<T> &p );
1374 template<
class T>
inline
1375 bool nonnull(
const RCP<T> &p );
1382 template<
class T>
inline
1383 bool operator==(
const RCP<T> &p, ENull );
1390 template<
class T>
inline
1391 bool operator!=(
const RCP<T> &p, ENull );
1399 template<
class T1,
class T2>
inline
1400 bool operator==(
const RCP<T1> &p1,
const RCP<T2> &p2 );
1408 template<
class T1,
class T2>
inline
1409 bool operator!=(
const RCP<T1> &p1,
const RCP<T2> &p2 );
1421 template<
class T2,
class T1>
inline
1422 RCP<T2> rcp_implicit_cast(
const RCP<T1>& p1);
1435 template<
class T2,
class T1>
inline
1436 RCP<T2> rcp_static_cast(
const RCP<T1>& p1);
1445 template<
class T2,
class T1>
inline
1446 RCP<T2> rcp_const_cast(
const RCP<T1>& p1);
1472 template<
class T2,
class T1>
inline
1473 RCP<T2> rcp_dynamic_cast(
1474 const RCP<T1>& p1,
bool throw_on_fail =
false
1536 template<
class T1,
class T2>
1537 void set_extra_data(
const T1 &extra_data,
const std::string& name,
1539 bool force_unique =
true);
1560 template<
class T1,
class T2>
1561 const T1& get_extra_data(
const RCP<T2>& p,
const std::string& name );
1583 template<
class T1,
class T2>
1584 T1& get_nonconst_extra_data( RCP<T2>& p,
const std::string& name );
1611 template<
class T1,
class T2>
1612 Ptr<const T1> get_optional_extra_data(
const RCP<T2>& p,
const std::string& name );
1639 template<
class T1,
class T2>
1640 Ptr<T1> get_optional_nonconst_extra_data( RCP<T2>& p,
const std::string& name );
1654 template<
class Dealloc_T,
class T>
1655 const Dealloc_T& get_dealloc(
const RCP<T>& p );
1669 template<
class Dealloc_T,
class T>
1670 Dealloc_T& get_nonconst_dealloc(
const RCP<T>& p );
1687 template<
class Dealloc_T,
class T>
1688 Ptr<const Dealloc_T> get_optional_dealloc(
const RCP<T>& p );
1705 template<
class Dealloc_T,
class T>
1706 Ptr<Dealloc_T> get_optional_nonconst_dealloc(
const RCP<T>& p );
1715 template<
class TOrig,
class Embedded,
class T>
1716 const Embedded& getEmbeddedObj(
const RCP<T>& p );
1725 template<
class TOrig,
class Embedded,
class T>
1726 Embedded& getNonconstEmbeddedObj(
const RCP<T>& p );
1735 template<
class TOrig,
class Embedded,
class T>
1736 Ptr<const Embedded> getOptionalEmbeddedObj(
const RCP<T>& p );
1745 template<
class TOrig,
class Embedded,
class T>
1746 Ptr<Embedded> getOptionalNonconstEmbeddedObj(
const RCP<T>& p );
1754 template<
class ParentT,
class T>
1766 std::ostream& operator<<( std::ostream& out, const RCP<T>& p );
1772 #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.
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
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.
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.
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...
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...
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.
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.
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.
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.
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.
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...
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.
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()).
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
auto make_rcp(Args &&...args)
bool is_null() const
Returns true if the underlying pointer is null.