48#ifdef HAVE_TEUCHOS_BOOST
51#ifdef HAVE_TEUCHOSCORE_CXX11
156 RCP<A> b_rcp(std::move(a_rcp));
212 b_rcp = std::move(a_rcp);
315 if (RCPNodeTracer::isTracingActiveRCPNodes())
385 ECHO(RCP <int> rcp4 = rcp1);
425 ECHO(
A *a_ptr = c_ptr);
427#if defined(TEUCHOS_DEBUG) && defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR)
447 ECHO(
A *a_ptr2 = a_ptr1);
449#if defined(TEUCHOS_DEBUG)
469 ECHO(
E *d_ptr = e_ptr);
471#if defined(TEUCHOS_DEBUG)
479 ECHO(d_rcp.release());
499 ECHO(
A &a_ref = *c_rcp);
502#if defined(TEUCHOS_DEBUG) && defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR)
503 TEST_THROW(a_rcp->A_g(), DanglingReferenceError);
514 ECHO(
A &a_ref = *a_rcp1);
517#if defined(TEUCHOS_DEBUG)
518 TEST_THROW(a_rcp2->A_g(), DanglingReferenceError);
529 ECHO(
D &d_ref = *e_rcp);
532#if defined(TEUCHOS_DEBUG)
533 TEST_THROW(d_rcp->D_g(), DanglingReferenceError);
547 ECHO(
A &a_ref = *c_rcp);
550#if defined(TEUCHOS_DEBUG) && defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR)
551 TEST_THROW(a_rcp->A_g(), DanglingReferenceError);
562 ECHO(
A &a_ref = *a_rcp1);
565#if defined(TEUCHOS_DEBUG)
566 TEST_THROW(a_rcp2->A_g(), DanglingReferenceError);
577 ECHO(
D &d_ref = *e_rcp);
580#if defined(TEUCHOS_DEBUG)
581 TEST_THROW(d_rcp->D_g(), DanglingReferenceError);
595 ECHO(
A &a_ref = *a_rcp1);
618 const Ptr<const RCP<C> > c_ptr_rcp_1 =
619 getOptionalEmbeddedObj<A, RCP<C> >(a_rcp);
621 const Ptr<RCP<C> > c_ptr_rcp_2 =
622 getOptionalNonconstEmbeddedObj<A, RCP<C> >(a_rcp);
633 Ptr<const RCP<C> > c_ptr_rcp_1 =
634 getOptionalEmbeddedObj<A, RCP<C> >(a_rcp);
636 TEST_EQUALITY( (*c_ptr_rcp_1).getRawPtr(), c_rcp.getRawPtr() );
639 Ptr<RCP<C> > c_ptr_rcp_2 =
640 getOptionalNonconstEmbeddedObj<A, RCP<C> >(a_rcp);
642 TEST_EQUALITY( (*c_ptr_rcp_2).getRawPtr(), c_rcp.getRawPtr() );
705 TEST_EQUALITY( rcp_weak1.getRawPtr(), rcp_strong.getRawPtr() );
725 TEST_EQUALITY( rcp_weak2.getRawPtr(), rcp_strong.getRawPtr() );
727 ECHO(rcp_strong = null);
756 ECHO(rcp_weak1.assert_not_null());
757 ECHO(rcp_weak2.assert_not_null());
759 TEST_THROW( rcp_weak1.assert_valid_ptr(), DanglingReferenceError );
761 TEST_THROW( rcp_weak1.operator->(), DanglingReferenceError );
762 TEST_THROW( *rcp_weak1, DanglingReferenceError );
763 TEST_THROW( rcp_weak1.create_weak(), DanglingReferenceError );
764 TEST_THROW( rcp_weak1.get(), DanglingReferenceError );
765 TEST_THROW( rcp_weak1.getRawPtr(), DanglingReferenceError );
766 TEST_THROW( rcp_weak1(), DanglingReferenceError );
767 TEST_THROW( rcp_weak1.release(), DanglingReferenceError );
770 ECHO(rcp_weak1 = null);
789 TEST_THROW( rcp_weak2.assert_valid_ptr(), DanglingReferenceError );
791 TEST_THROW( rcp_weak2.operator->(), DanglingReferenceError );
792 TEST_THROW( *rcp_weak2, DanglingReferenceError );
793 TEST_THROW( rcp_weak2.create_weak(), DanglingReferenceError );
794 TEST_THROW( rcp_weak2.get(), DanglingReferenceError );
795 TEST_THROW( rcp_weak2.getRawPtr(), DanglingReferenceError );
796 TEST_THROW( rcp_weak2(), DanglingReferenceError );
797 TEST_THROW( rcp_weak2.release(), DanglingReferenceError );
849 ECHO(c->set_A(a.create_weak()));
862 TEST_THROW(c->call_A_g(), DanglingReferenceError);
881 ECHO(c->set_A(a.create_weak()));
912 ECHO(c->set_A(c.create_weak()));
922 ECHO(Ptr<A> a_ptr = a_rcp());
960 ECHO(Ptr<A> a_ptr2(a_rcp.
ptr()));
961 ECHO(Ptr<A> a_ptr3(a_ptr2));
962 ECHO(a_ptr = a_ptr3);
980 ECHO(badPtr = c_rcp.getRawPtr());
981 ECHO(Ptr<A> a_ptr2(c_rcp.ptr()));
982 ECHO(a_ptr = a_ptr2);
1031 c->set_A(
rcp(
new A));
1038 RCP<C> c = createCAFactory();
1051 RCP<A> a = createACFactory();
1052 RCP<C> c = extractCFromA(a);
1066 RCP<A> a = createACFactory();
1067 extractCFromA(a)->set_A(null);
1068 RCP<C> c = extractCFromA(a);
1081RCP<A> createRCPWithBadDealloc()
1083 return rcp(
new A[1]);
1088class DeallocArrayDeleteExtraData {
1090 static RCP<DeallocArrayDeleteExtraData<T> > create(T *ptr)
1091 {
return rcp(
new DeallocArrayDeleteExtraData(ptr)); }
1092 ~DeallocArrayDeleteExtraData() {
delete [] ptr_; }
1095 DeallocArrayDeleteExtraData(T *ptr) : ptr_(
ptr) {}
1097 DeallocArrayDeleteExtraData();
1098 DeallocArrayDeleteExtraData(
const DeallocArrayDeleteExtraData&);
1099 DeallocArrayDeleteExtraData& operator=(
const DeallocArrayDeleteExtraData&);
1110 RCP<A> a = createRCPWithBadDealloc();
1141#ifdef HAVE_TEUCHOS_BOOST
1146 using boost::shared_ptr;
1147 ECHO(shared_ptr<A> a_sptr(
new A));
1150 ECHO(a_sptr = shared_ptr<A>());
1164#ifdef HAVE_TEUCHOSCORE_CXX11
1169 using std::shared_ptr;
1170 ECHO(shared_ptr<A> a_sptr(
new A));
1173 ECHO(a_sptr = shared_ptr<A>());
1181 const std::shared_ptr<A> a_sptr1;
1194 const std::shared_ptr<A> a_sptr1(
new C());
1244 const RCP<C> c_rcp1 =
rcp(std::dynamic_pointer_cast<C>(a_sptr1));
1266# define DEBUG_UNIT_TEST_GROUP( T ) \
1270# define DEBUG_UNIT_TEST_GROUP( T )
1275#define UNIT_TEST_GROUP( T ) \
1276 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCP, weakDelete, T ) \
1277 DEBUG_UNIT_TEST_GROUP(T)
#define UNIT_TEST_GROUP(T)
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_INEQUALITY_CONST(v1, v2)
Assert the inequality of v1 and constant v2.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails).
#define ECHO(statement)
Echo the given statement before it is executed.
#define SET_RCPNODE_TRACING()
Reference-counted pointer class and non-member templated function implementations.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
void set_C(const Teuchos::RCP< C > &c)
Smart reference counting pointer class for automatic garbage collection.
RCP< const T > getConst() const
Return an RCP<const T> version of *this.
RCP< T > create_weak() const
Create a new weak RCP object from another (strong) RCP object.
Ptr< T > release()
Release the ownership of the underlying dynamically allocated object.
void reset()
Reset to null.
bool shares_resource(const RCP< T2 > &r_ptr) const
Returns true if the smart pointers share the same underlying reference-counted 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.
RCP< T > create_strong() const
Create a new strong RCP object from another (weak) RCP object.
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to delete it.
T * get() const
Get the raw C++ pointer to the underlying object.
ERCPStrength strength() const
Strength of the pointer.
int weak_count() const
Return the number of active RCP<> objects that have a "weak" reference to the underlying reference-co...
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object.
const Embedded & getEmbeddedObj(const ArrayRCP< T > &p)
Get a const reference to an embedded object that was set by calling arcpWithEmbeddedObjPreDestroy(),...
Dangling reference error exception class.
Policy class for deallocator for non-owned RCPs.
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
Thrown if a duplicate owning RCP is creatd the the same object.
Null reference error exception class.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
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< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
Debug-mode RCPNode tracing class.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
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.
std::shared_ptr< T > get_shared_ptr(const RCP< T > &rcp)
Conversion function that takes in a Teuchos::RCP object and spits out a std::shared_ptr object.
RCP< T > rcpWithEmbeddedObj(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
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.
RCP< T > rcpFromUndefRef(T &r)
Return a non-owning weak RCP object from a raw object reference for an undefined type.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
RCP< T > rcpWithInvertedObjOwnership(const RCP< T > &child, const RCP< ParentT > &parent)
Create a new RCP that inverts the ownership of parent and child.
T * get() const
Get the raw C++ pointer to the underlying 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(...
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const boost::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
auto make_rcp(Args &&... args)
RCP< ParentT > getInvertedObjOwnershipParent(const RCP< T > &invertedChild)
Get the parent back from an inverted ownership RCP.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.