Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_RCP.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_RCP_HPP
11#define TEUCHOS_RCP_HPP
12
13
26#include "Teuchos_RCPDecl.hpp"
27#include "Teuchos_Ptr.hpp"
28#include "Teuchos_Assert.hpp"
29#include "Teuchos_Exceptions.hpp"
30#include "Teuchos_dyn_cast.hpp"
31#include "Teuchos_map.hpp"
33
34
35namespace Teuchos {
36
37
38// very bad public functions
39
40
41template<class T>
42inline
43RCPNode* RCP_createNewRCPNodeRawPtrNonowned( T* p )
44{
45 return new RCPNodeTmpl<T,DeallocNull<T> >(p, DeallocNull<T>(), false);
46}
47
48
49template<class T>
50inline
51RCPNode* RCP_createNewRCPNodeRawPtrNonownedUndefined( T* p )
52{
53 return new RCPNodeTmpl<T,DeallocNull<T> >(p, DeallocNull<T>(), false, null);
54}
55
56
57template<class T>
58inline
59RCPNode* RCP_createNewRCPNodeRawPtr( T* p, bool has_ownership_in )
60{
61 return new RCPNodeTmpl<T,DeallocDelete<T> >(p, DeallocDelete<T>(), has_ownership_in);
62}
63
64
65template<class T, class Dealloc_T>
66inline
67RCPNode* RCP_createNewDeallocRCPNodeRawPtr(
68 T* p, Dealloc_T dealloc, bool has_ownership_in
69 )
70{
71 return new RCPNodeTmpl<T,Dealloc_T>(p, dealloc, has_ownership_in);
72}
73
74
75template<class T, class Dealloc_T>
76inline
77RCPNode* RCP_createNewDeallocRCPNodeRawPtrUndefined(
78 T* p, Dealloc_T dealloc, bool has_ownership_in
79 )
80{
81 return new RCPNodeTmpl<T,Dealloc_T>(p, dealloc, has_ownership_in, null);
82}
83
84
85template<class T>
86inline
87RCP<T>::RCP( T* p, const RCPNodeHandle& node)
88 : ptr_(p), node_(node)
89{}
90
91
92template<class T>
93inline
94T* RCP<T>::access_private_ptr() const
95{ return ptr_; }
96
97
98template<class T>
99inline
100RCPNodeHandle& RCP<T>::nonconst_access_private_node()
101{ return node_; }
102
103
104template<class T>
105inline
106const RCPNodeHandle& RCP<T>::access_private_node() const
107{ return node_; }
108
109
110
111
112// Constructors/destructors/initializers
113
114
115template<class T>
116inline
118 : ptr_(NULL)
119{}
120
121
122template<class T>
123inline
124RCP<T>::RCP( T* p, ERCPWeakNoDealloc )
125 : ptr_(p)
127 , node_(RCP_createNewRCPNodeRawPtrNonowned(p))
128#endif // TEUCHOS_DEBUG
129{
130#ifdef TEUCHOS_DEBUG
131 if (p) {
133 if (existing_RCPNode) {
134 // Will not call add_new_RCPNode(...)
135 node_ = RCPNodeHandle(existing_RCPNode, RCP_WEAK, false);
136 }
137 else {
138 // Will call add_new_RCPNode(...)
139 node_ = RCPNodeHandle(
140 RCP_createNewRCPNodeRawPtrNonowned(p),
142 false
143 );
144 }
145 }
146#endif // TEUCHOS_DEBUG
147}
148
149
150template<class T>
151inline
152RCP<T>::RCP( T* p, ERCPUndefinedWeakNoDealloc )
153 : ptr_(p),
154 node_(RCP_createNewRCPNodeRawPtrNonownedUndefined(p))
155{}
156
157
158template<class T>
159inline
161 : ptr_(p)
163 , node_(RCP_createNewRCPNodeRawPtr(p, has_ownership_in))
164#endif // TEUCHOS_DEBUG
165{
166#ifdef TEUCHOS_DEBUG
167 if (p) {
169 if (!has_ownership_in) {
171 }
172 if (existing_RCPNode) {
173 // Will not call add_new_RCPNode(...)
174 node_ = RCPNodeHandle(existing_RCPNode, RCP_WEAK, false);
175 }
176 else {
177 // Will call add_new_RCPNode(...)
178 RCPNodeThrowDeleter nodeDeleter(RCP_createNewRCPNodeRawPtr(p, has_ownership_in));
179 node_ = RCPNodeHandle(
183 );
185 }
186 }
187#endif // TEUCHOS_DEBUG
188}
189
190
191template<class T>
192template<class Dealloc_T>
193inline
195 : ptr_(p)
197 , node_(RCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in))
198#endif // TEUCHOS_DEBUG
199{
200#ifdef TEUCHOS_DEBUG
201 if (p) {
202 // Here we are assuming that if the user passed in a custom deallocator
203 // then they will want to have ownership (otherwise it will throw if it is
204 // the same object).
205 RCPNodeThrowDeleter nodeDeleter(RCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in));
206 node_ = RCPNodeHandle(
210 );
212 }
213#endif // TEUCHOS_DEBUG
214}
215
216
217template<class T>
218template<class Dealloc_T>
219inline
220RCP<T>::RCP( T* p, Dealloc_T dealloc, ERCPUndefinedWithDealloc, bool has_ownership_in )
221 : ptr_(p)
223 , node_(RCP_createNewDeallocRCPNodeRawPtrUndefined(p, dealloc, has_ownership_in))
224#endif // TEUCHOS_DEBUG
225{
226#ifdef TEUCHOS_DEBUG
227 if (p) {
228 // Here we are assuming that if the user passed in a custom deallocator
229 // then they will want to have ownership (otherwise it will throw if it is
230 // the same object).
231 // Use auto_ptr to ensure we don't leak if a throw occurs
232 RCPNodeThrowDeleter nodeDeleter(RCP_createNewDeallocRCPNodeRawPtrUndefined(
234 node_ = RCPNodeHandle(
238 );
240 }
241#endif // TEUCHOS_DEBUG
242}
243
244
245template<class T>
246inline
248 : ptr_(r_ptr.ptr_), node_(r_ptr.node_)
249{}
250
251
252template<class T>
253inline
255 : ptr_(r_ptr.ptr_), node_(std::move(r_ptr.node_))
256{
257 r_ptr.ptr_ = 0;
258}
259
260
261template<class T>
262template<class T2>
263inline
265 : ptr_(r_ptr.get()), // will not compile if T is not base class of T2
267{}
268
269
270template<class T>
271template<class T2>
272inline
274 : ptr_(ptr),
276{}
277
278
279template<class T>
280inline
283
284
285template<class T>
286inline
288{
289#ifdef TEUCHOS_DEBUG
290 if (this == &r_ptr)
291 return *this;
292 reset(); // Force delete first in debug mode!
293#endif
294 RCP<T>(r_ptr).swap(*this);
295 return *this;
296}
297
298
299template<class T>
300inline
302{
303#ifdef TEUCHOS_DEBUG
304 if (this == &r_ptr)
305 return *this;
306 reset(); // Force delete first in debug mode!
307#endif
308 ptr_ = r_ptr.ptr_;
309 node_ = std::move(r_ptr.node_);
310 r_ptr.ptr_ = 0;
311 return *this;
312}
313
314
315template<class T>
316inline
318{
319 reset();
320 return *this;
321}
322
323
324template<class T>
325inline
327{
328 std::swap(r_ptr.ptr_, ptr_);
329 node_.swap(r_ptr.node_);
330}
331
332
333// Object query and access functions
334
335
336template<class T>
337inline
338bool RCP<T>::is_null() const
339{
340 return ptr_ == 0;
341}
342
343
344template<class T>
345inline
347{
350 return ptr_;
351}
352
353
354template<class T>
355inline
357{
360 return *ptr_;
361}
362
363template<class T>
364inline
366{
368 return ptr_;
369}
370
371
372template<class T>
373inline
375{
376 return this->get();
377}
378
379
380template<class T>
381inline
383{
384#ifdef TEUCHOS_DEBUG
385 return Ptr<T>(this->create_weak());
386#else
387 return Ptr<T>(getRawPtr());
388#endif
389}
390
391
392template<class T>
393inline
395{
396 return ptr();
397}
398
399
400template<class T>
401inline
403{
404 return rcp_implicit_cast<const T>(*this);
405}
406
407
408template<class T>
409inline
411{
412 return (get() != 0);
413}
414
415
416// Reference counting
417
418
419template<class T>
420inline
422{
423 return node_.strength();
424}
425
426
427template<class T>
428inline
430{
431 if (ptr_)
432 return node_.is_valid_ptr();
433 return true;
434}
435
436
437template<class T>
438inline
440{
441 return node_.strong_count();
442}
443
444
445template<class T>
446inline
448{
449 return node_.weak_count();
450}
451
452
453template<class T>
454inline
456{
457 return node_.total_count();
458}
459
460
461template<class T>
462inline
464{
465 node_.has_ownership(true);
466}
467
468
469template<class T>
470inline
472{
473 return node_.has_ownership();
474}
475
476
477template<class T>
478inline
480{
482 node_.has_ownership(false);
483 return Ptr<T>(ptr_);
484}
485
486
487template<class T>
488inline
492 return RCP<T>(ptr_, node_.create_weak());
493}
494
495
496template<class T>
497inline
501 return RCP<T>(ptr_, node_.create_strong());
502}
503
504#if defined(HAVE_TEUCHOSCORE_CXX11) && defined(HAVE_TEUCHOS_THREAD_SAFE)
505template<class T>
506inline
508{
509 if (strength() == RCP_STRONG) {
510 return create_strong(); // it's already thread safe
511 }
512 // we don't check for debug_assert_valid_ptr()
513 // probably doesn't hurt anything if we do but using it would be confusing
514 // because ptr could become invalid immediately after
516 return RCP<T>( attemptStrong.is_node_null() ? 0 : ptr_, attemptStrong);
517}
518#endif
519
520
521template<class T>
522template <class T2>
523inline
525{
526 return node_.same_node(r_ptr.access_private_node());
527 // Note: above, r_ptr is *not* the same class type as *this so we can not
528 // access its node_ member directly! This is an interesting detail to the
529 // C++ protected/private protection mechanism!
530}
531
532
533// Assertions
534
535
536template<class T>
537inline
539{
540 if (!ptr_)
541 throw_null_ptr_error(typeName(*this));
542 return *this;
543}
544
545
546template<class T>
547inline
549{
550 if (ptr_)
551 node_.assert_valid_ptr(*this);
552 return *this;
553}
554
555
556// boost::shared_ptr compatiblity funtions
557
558
559template<class T>
560inline
562{
563#ifdef TEUCHOS_DEBUG
564 node_ = RCPNodeHandle();
565#else
566 RCPNodeHandle().swap(node_);
567#endif
568 ptr_ = 0;
569}
570
571
572template<class T>
573template<class T2>
574inline
576{
577 *this = rcp(p, has_ownership_in);
578}
579
580} // end namespace Teuchos
581
582
583// /////////////////////////////////////////////////////////////////////////////////
584// Inline non-member functions for RCP
585
587template<class T>
588inline
590Teuchos::rcp( T* p, bool owns_mem )
591{
592 return RCP<T>(p, owns_mem);
593}
594
595
596template<class T, class Dealloc_T>
597inline
599Teuchos::rcpWithDealloc( T* p, Dealloc_T dealloc, bool owns_mem )
600{
601 return RCP<T>(p, dealloc, owns_mem);
602}
603
604
605template<class T, class Dealloc_T>
606inline
608Teuchos::rcpWithDeallocUndef( T* p, Dealloc_T dealloc, bool owns_mem )
609{
610 return RCP<T>(p, dealloc, RCP_UNDEFINED_WITH_DEALLOC, owns_mem);
611}
612
614template<class T>
616Teuchos::rcpFromRef( T& r )
617{
618 return RCP<T>(&r, RCP_WEAK_NO_DEALLOC);
620
621
622template<class T>
624Teuchos::rcpFromUndefRef( T& r )
626 return RCP<T>(&r, RCP_UNDEFINED_WEAK_NO_DEALLOC);
627}
629
630template<class T, class Embedded>
632Teuchos::rcpWithEmbeddedObjPreDestroy(
633 T* p, const Embedded &embedded, bool owns_mem
635{
636 return rcpWithDealloc(
638 );
639}
640
641
642template<class T, class Embedded>
644Teuchos::rcpWithEmbeddedObjPostDestroy(
645 T* p, const Embedded &embedded, bool owns_mem
646 )
647{
648 return rcpWithDealloc( p, embeddedObjDeallocDelete<T>(embedded,POST_DESTROY), owns_mem );
649}
650
651
652template<class T, class Embedded>
654Teuchos::rcpWithEmbeddedObj( T* p, const Embedded &embedded, bool owns_mem )
655{
657}
658
659
660template<class T, class ParentT>
662Teuchos::rcpWithInvertedObjOwnership(const RCP<T> &child,
663 const RCP<ParentT> &parent)
665 using std::make_pair;
666 return rcpWithEmbeddedObj(child.getRawPtr(), make_pair(child, parent), false);
667}
668
669
670template<class T>
672Teuchos::rcpCloneNode(const RCP<T> &p)
673{
674 if (is_null(p)) {
675 return p;
676 }
677 return rcpWithEmbeddedObj(&*p, p, false);
679
680
681template<class T>
682inline
683bool Teuchos::is_null( const RCP<T> &p )
684{
685 return p.is_null();
686}
687
688
689template<class T>
690inline
691bool Teuchos::nonnull( const RCP<T> &p )
692{
693 return !p.is_null();
694}
695
696
697template<class T>
698inline
699bool Teuchos::operator==( const RCP<T> &p, ENull )
700{
701 return p.get() == NULL;
702}
703
704
705template<class T>
706inline
707bool Teuchos::operator!=( const RCP<T> &p, ENull )
708{
709 return p.get() != NULL;
710}
711
712
713template<class T1, class T2>
714inline
715bool Teuchos::operator==( const RCP<T1> &p1, const RCP<T2> &p2 )
716{
717 return p1.access_private_node().same_node(p2.access_private_node());
718}
719
720
721template<class T1, class T2>
722inline
723bool Teuchos::operator!=( const RCP<T1> &p1, const RCP<T2> &p2 )
724{
725 return !p1.access_private_node().same_node(p2.access_private_node());
726}
727
728
729template<class T2, class T1>
730inline
732Teuchos::rcp_implicit_cast(const RCP<T1>& p1)
733{
734 // Make the compiler check if the conversion is legal
735 T2 *check = p1.get();
736 return RCP<T2>(check, p1.access_private_node());
737}
738
739
740template<class T2, class T1>
741inline
743Teuchos::rcp_static_cast(const RCP<T1>& p1)
744{
745 // Make the compiler check if the conversion is legal
746 T2 *check = static_cast<T2*>(p1.get());
747 return RCP<T2>(check, p1.access_private_node());
748}
749
750
751template<class T2, class T1>
752inline
754Teuchos::rcp_const_cast(const RCP<T1>& p1)
755{
756 // Make the compiler check if the conversion is legal
757 T2 *check = const_cast<T2*>(p1.get());
758 return RCP<T2>(check, p1.access_private_node());
759}
760
761
762template<class T2, class T1>
763inline
765Teuchos::rcp_dynamic_cast(const RCP<T1>& p1, bool throw_on_fail)
766{
767 if (!is_null(p1)) {
768 T2 *p = NULL;
769 if (throw_on_fail) {
770 p = &dyn_cast<T2>(*p1);
771 }
772 else {
773 // Make the compiler check if the conversion is legal
774 p = dynamic_cast<T2*>(p1.get());
775 }
776 if (p) {
777 return RCP<T2>(p, p1.access_private_node());
778 }
779 }
780 return null;
781}
783
784template<class T1, class T2>
785inline
786void Teuchos::set_extra_data( const T1 &extra_data, const std::string& name,
787 const Ptr<RCP<T2> > &p, EPrePostDestruction destroy_when, bool force_unique )
788{
790 p->nonconst_access_private_node().set_extra_data(
791 any(extra_data), name, destroy_when,
792 force_unique );
793}
794
795
796template<class T1, class T2>
797inline
798const T1& Teuchos::get_extra_data( const RCP<T2>& p, const std::string& name )
799{
801 return any_cast<T1>(
802 p.access_private_node().get_extra_data(
804 )
805 );
806}
808
809template<class T1, class T2>
810inline
811T1& Teuchos::get_nonconst_extra_data( RCP<T2>& p, const std::string& name )
812{
814 return any_cast<T1>(
815 p.nonconst_access_private_node().get_extra_data(
817 )
818 );
819}
820
821
822template<class T1, class T2>
823inline
825Teuchos::get_optional_extra_data( const RCP<T2>& p, const std::string& name )
826{
828 const any *extra_data = p.access_private_node().get_optional_extra_data(
830 if (extra_data)
831 return Ptr<const T1>(&any_cast<T1>(*extra_data));
832 return null;
833}
834
835
836template<class T1, class T2>
837inline
839Teuchos::get_optional_nonconst_extra_data( RCP<T2>& p, const std::string& name )
840{
841 p.assert_not_null();
842 any *extra_data = p.nonconst_access_private_node().get_optional_extra_data(
843 TypeNameTraits<T1>::name(), name);
844 if (extra_data)
845 return Ptr<T1>(&any_cast<T1>(*extra_data));
846 return null;
847}
848
849
850template<class Dealloc_T, class T>
851inline
852const Dealloc_T& Teuchos::get_dealloc( const RCP<T>& p )
853{
854 return get_nonconst_dealloc<Dealloc_T>(const_cast<RCP<T>&>(p));
855}
856
858template<class Dealloc_T, class T>
859inline
860Dealloc_T& Teuchos::get_nonconst_dealloc( const RCP<T>& p )
861{
866 p.access_private_node().node_ptr());
869 ,"get_dealloc<" << TypeNameTraits<Dealloc_T>::name()
870 << "," << TypeNameTraits<T>::name() << ">(p): "
871 << "Error, requested type \'" << TypeNameTraits<requested_type>::name()
872 << "\' does not match actual type of the node \'"
873 << typeName(*p.access_private_node().node_ptr()) << "!"
874 );
875 return dnode->get_nonconst_dealloc();
876}
877
878
879template<class Dealloc_T, class T>
880inline
882Teuchos::get_optional_nonconst_dealloc( const RCP<T>& p )
883{
886 RCPNT *dnode = dynamic_cast<RCPNT*>(p.access_private_node().node_ptr());
887 if(dnode)
888 return ptr(&dnode->get_nonconst_dealloc());
889 return null;
890}
891
892
893template<class Dealloc_T, class T>
894inline
896Teuchos::get_optional_dealloc( const RCP<T>& p )
899}
900
901
902template<class TOrig, class Embedded, class T>
903const Embedded& Teuchos::getEmbeddedObj( const RCP<T>& p )
904{
906 return get_dealloc<Dealloc_t>(p).getObj();
907}
908
909
910template<class TOrig, class Embedded, class T>
911Embedded& Teuchos::getNonconstEmbeddedObj( const RCP<T>& p )
912{
914 return get_nonconst_dealloc<Dealloc_t>(p).getNonconstObj();
915}
916
917
918template<class TOrig, class Embedded, class T>
920Teuchos::getOptionalEmbeddedObj( const RCP<T>& p )
921{
922 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocDelete<TOrig> > Dealloc_t;
923 const Ptr<const Dealloc_t> dealloc = get_optional_dealloc<Dealloc_t>(p);
924 if (!is_null(dealloc)) {
925 return ptr(&dealloc->getObj());
926 }
927 return null;
928}
929
930
931template<class TOrig, class Embedded, class T>
933Teuchos::getOptionalNonconstEmbeddedObj( const RCP<T>& p )
934{
935 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocDelete<TOrig> > Dealloc_t;
936 const Ptr<Dealloc_t> dealloc = get_optional_nonconst_dealloc<Dealloc_t>(p);
937 if (!is_null(dealloc)) {
938 return ptr(&dealloc->getNonconstObj());
939 }
940 return null;
941}
942
943
944template<class ParentT, class T>
946Teuchos::getInvertedObjOwnershipParent(const RCP<T> &invertedChild)
947{
948 typedef std::pair<RCP<T>, RCP<ParentT> > Pair_t;
949 Pair_t pair = getEmbeddedObj<T, Pair_t>(invertedChild);
950 return pair.second;
951}
952
953
954template<class T>
955std::ostream& Teuchos::operator<<( std::ostream& out, const RCP<T>& p )
956{
957 out
958 << typeName(p) << "{"
959 << "ptr="<<(const void*)(p.get()) // I can't find any alternative to this C cast :-(
960 <<",node="<<p.access_private_node()
961 <<",strong_count="<<p.strong_count()
962 <<",weak_count="<<p.weak_count()
963 <<"}";
964 return out;
965}
966
967
968#endif // TEUCHOS_RCP_HPP
Reference-counted pointer class and non-member templated function implementations.
Defines basic traits returning the name of a type in a portable and readable way.
Provides std::map class for deficient platforms.
Null reference error exception class.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Handle class that manages the RCPNode's reference counting.
RCPNodeHandle create_strong() const
Return a strong handle.
RCPNodeHandle create_weak() const
Return a weak handle.
int total_count() const
The sum of the weak and string counts.
RCPNodeHandle create_strong_lock() const
Return a strong handle if possible using thread safe atomics.
void assert_valid_ptr(const RCPType &rcp_obj) const
ERCPStrength strength() const
The strength of this handle.
void swap(RCPNodeHandle &node_ref)
Swap the contents of node_ref with *this.
int weak_count() const
The weak count for this RCPNode, or 0 if the node is NULL.
void has_ownership(bool has_ownership_in)
bool is_valid_ptr() const
Whether the underlying pointer is valid.
int strong_count() const
The strong count for this RCPNode, or 0 if the node is NULL.
bool same_node(const RCPNodeHandle &node2) const
Whether the RCPNode for which node2 is a handle is the same RCPNode as this object's RCPNode.
Deletes a (non-owning) RCPNode but not it's underlying object in case of a throw.
static RCPNode * getExistingRCPNode(T *p)
Return a raw pointer to an existing owning RCPNode given the address to the underlying object if it e...
Node class to keep track of address and the reference count for a reference-counted utility class and...
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.
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 shares_resource(const RCP< T2 > &r_ptr) const
Returns true if the smart pointers share the same underlying reference-counted 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(ENull null_arg=null)
Initialize RCP<T> to NULL.
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.
bool is_null() const
Returns true if the underlying pointer is null.
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.
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.
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.
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.
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.
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()).
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
Ptr< T > operator()() const
Shorthand for ptr().
T & operator*() const
Dereference the underlying object.
Default traits class that just returns typeid(T).name().
Modified boost::any class, which is a container for a templated value.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
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.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object.
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.
RCP< ParentT > getInvertedObjOwnershipParent(const RCP< T > &invertedChild)
Get the parent back from an inverted ownership RCP.