Loading...
Searching...
No Matches
refPtr.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_REF_PTR_H
8#define PXR_BASE_TF_REF_PTR_H
9
409
410#include "pxr/pxr.h"
411
413#include "pxr/base/tf/hash.h"
414#include "pxr/base/tf/nullPtr.h"
415#include "pxr/base/tf/refBase.h"
418#include "pxr/base/tf/api.h"
419
420#include "pxr/base/arch/hints.h"
421
422
423#include <typeinfo>
424#include <type_traits>
425#include <cstddef>
426
427PXR_NAMESPACE_OPEN_SCOPE
428
429// Tf_SupportsUniqueChanged is a metafunction that may be specialized to return
430// false for classes (and all derived classes) that *cannot* ever invoke unique
431// changed listeners.
432template <class T>
433struct Tf_SupportsUniqueChanged {
434 static const bool Value = true;
435};
436
437// Remnants are never able to support weak changed listeners.
438class Tf_Remnant;
439template <>
440struct Tf_SupportsUniqueChanged<Tf_Remnant> {
441 static const bool Value = false;
442};
443
444class TfWeakBase;
445
446template <class T> class TfWeakPtr;
447template <template <class> class X, class Y>
448class TfWeakPtrFacade;
449
450// Functions used for tracking. Do not implement these.
451inline void
452Tf_RefPtrTracker_FirstRef(const void*, const TfRefBase *, const void*) { }
453inline void
454Tf_RefPtrTracker_LastRef(const void*, const TfRefBase *, const void*) { }
455inline void
456Tf_RefPtrTracker_New(const void*, const TfRefBase *, const void*) { }
457inline void
458Tf_RefPtrTracker_Delete(const void*, const TfRefBase *, const void*) { }
459inline void
460Tf_RefPtrTracker_Assign(const void*, const TfRefBase *,
461 const TfRefBase *, const void*) { }
462
463// This code is used to increment and decrement ref counts in the common case.
464// It may lock and invoke the unique changed listener, if the reference count
465// becomes unique or non-unique.
466struct Tf_RefPtr_UniqueChangedCounter {
467 static inline void
468 AddRef(TfRefBase const *refBase) {
469 if (ARCH_UNLIKELY(!refBase)) {
470 return;
471 }
472 const auto relaxed = std::memory_order_relaxed;
473 // Read the current count value.
474 std::atomic_int &counter = refBase->_GetRefCount();
475 int prevCount = counter.load(relaxed);
476 if (ARCH_UNLIKELY(prevCount < 0)) {
477 // We need to invoke the unique changed listener if count goes from
478 // -1 -> -2. Try to CAS the value to one more count if it looks
479 // like we won't take it from -1 -> -2. If that works, we're done.
480 // If not, we'll call an out-of-line function that handles the
481 // locking part.
482 if (prevCount != -1 && counter.
483 compare_exchange_weak(prevCount, prevCount-1, relaxed)) {
484 return;
485 }
486 _AddRefMaybeLocked(refBase, prevCount);
487 }
488 else {
489 // Just bump the count.
490 counter.fetch_add(1, relaxed);
491 }
492 }
493
494 static inline bool
495 RemoveRef(TfRefBase const* refBase) {
496 if (ARCH_UNLIKELY(!refBase)) {
497 return false;
498 }
499 const auto relaxed = std::memory_order_relaxed;
500 const auto release = std::memory_order_release;
501 // Read the current count value.
502 std::atomic_int &counter = refBase->_GetRefCount();
503 int prevCount = counter.load(relaxed);
504 if (ARCH_UNLIKELY(prevCount < 0)) {
505 // We need to invoke the unique changed listener if count goes from
506 // -2 -> -1. Try to CAS the value to one less count if it looks
507 // like we won't take it from -2 -> -1. If that works, we're done.
508 // If not, we'll call an out-of-line function that handles the
509 // locking part.
510 if (prevCount != -2 && counter.
511 compare_exchange_weak(prevCount, prevCount+1, release)) {
512 return prevCount == -1;
513 }
514 return _RemoveRefMaybeLocked(refBase, prevCount);
515 }
516 else {
517 // Just drop the count.
518 return counter.fetch_sub(1, release) == 1;
519 }
520 }
521
522 // Increment ptr's count if it is not zero. Return true if done so
523 // successfully, false if its count is zero.
524 TF_API static bool
525 AddRefIfNonzero(TfRefBase const *refBase);
526
527 TF_API static void
528 _AddRefMaybeLocked(TfRefBase const *refBase, int prevCount);
529
530 TF_API static bool
531 _RemoveRefMaybeLocked(TfRefBase const *refBase, int prevCount);
532
533};
534
535// This code is used to increment and decrement ref counts in the case where
536// the object pointed to explicitly does not support unique changed listeners.
537struct Tf_RefPtr_Counter {
538 static inline void
539 AddRef(TfRefBase const *refBase) {
540 if (ARCH_UNLIKELY(!refBase)) {
541 return;
542 }
543 refBase->_GetRefCount().fetch_add(1, std::memory_order_relaxed);
544 }
545
546 static inline bool
547 RemoveRef(TfRefBase const *refBase) {
548 if (ARCH_UNLIKELY(!refBase)) {
549 return false;
550 }
551 return refBase->_GetRefCount()
552 .fetch_sub(1, std::memory_order_release) == 1;
553 }
554
555 // Increment ptr's count if it is not zero. Return true if done so
556 // successfully, false if its count is zero.
557 static inline bool
558 AddRefIfNonzero(TfRefBase const *refBase) {
559 if (ARCH_UNLIKELY(!refBase)) {
560 return false;
561 }
562 auto &counter = refBase->_GetRefCount();
563 int prevCount = counter.load(std::memory_order_relaxed);
564 while (prevCount) {
565 if (counter.compare_exchange_weak(prevCount, prevCount+1)) {
566 return true;
567 }
568 }
569 return false;
570 }
571};
572
573// Helper to post a fatal error when a NULL Tf pointer is dereferenced.
574[[noreturn]]
575TF_API void
576Tf_PostNullSmartPtrDereferenceFatalError(const TfCallContext &, const char *);
577
589template <class T>
590class TfRefPtr {
591 // Select the counter based on whether T supports unique changed listeners.
592 using _Counter = typename std::conditional<
593 Tf_SupportsUniqueChanged<T>::Value &&
594 !std::is_convertible<T*, TfSimpleRefBase*>::value,
595 Tf_RefPtr_UniqueChangedCounter,
596 Tf_RefPtr_Counter>::type;
597
598 static constexpr T *_NullT = nullptr;
599
600public:
602 typedef T DataType;
603
604 template <class U> struct Rebind {
605 typedef TfRefPtr<U> Type;
606 };
607
613 TfRefPtr() : _refBase(nullptr) {
614 Tf_RefPtrTracker_New(this, _refBase, _NullT);
615 }
616
623 TfRefPtr(TfRefPtr<T>&& p) : _refBase(p._refBase) {
624 p._refBase = nullptr;
625 Tf_RefPtrTracker_New(this, _refBase, _NullT);
626 Tf_RefPtrTracker_Assign(&p, p._refBase, _refBase, _NullT);
627 }
628
632 TfRefPtr(const TfRefPtr<T>& p) : _refBase(p._refBase) {
633 _AddRef();
634 Tf_RefPtrTracker_New(this, _refBase, _NullT);
635 }
636
640 template <template <class> class X, class U>
641 inline TfRefPtr(const TfWeakPtrFacade<X, U>& p,
642 typename std::enable_if<
643 std::is_convertible<U*, T*>::value
644 >::type * = 0);
645
678#if defined(doxygen)
679 friend inline TfRefPtr TfCreateRefPtr(T*);
680#else
681 template <class U>
682 friend inline TfRefPtr<U> TfCreateRefPtr(U*);
683#endif
684
691 template <class U>
692 explicit TfRefPtr(
693 U* ptr, typename std::enable_if<
694 std::is_convertible<U*, T*>::value>::type * = nullptr) :
695 _refBase(ptr)
696 {
697 _AddRef();
698 Tf_RefPtrTracker_New(this, _refBase, _NullT);
699 }
700
702 TfRefPtr(TfNullPtrType) : _refBase(nullptr)
703 {
704 Tf_RefPtrTracker_New(this, _refBase, _NullT);
705 }
706
708 TfRefPtr(std::nullptr_t) : _refBase(nullptr)
709 {
710 Tf_RefPtrTracker_New(this, _refBase, _NullT);
711 }
712
732 //
733 // It is quite possible for
734 // ptr = TfNullPtr;
735 // to delete the space that ptr actually lives in (this happens
736 // when you use a circular reference to keep an object alive).
737 // To avoid a crash, we have to ensure that deletion of the object
738 // is the last thing done in the assignment; so we use some
739 // local variables to help us out.
740 //
741
742 Tf_RefPtrTracker_Assign(this, p._refBase, _refBase, _NullT);
743
744 const TfRefBase* tmp = _refBase;
745 _refBase = p._refBase;
746
747 p._AddRef(); // first!
748 _RemoveRef(tmp); // second!
749 return *this;
750 }
751
759 // See comment in assignment operator.
760 Tf_RefPtrTracker_Assign(this, p._refBase, _refBase, _NullT);
761 Tf_RefPtrTracker_Assign(&p, nullptr, p._refBase, _NullT);
762
763 const TfRefBase* tmp = _refBase;
764 _refBase = p._refBase;
765 p._refBase = nullptr;
766
767 _RemoveRef(tmp);
768 return *this;
769 }
770
776 Tf_RefPtrTracker_Delete(this, _refBase, _NullT);
777 _RemoveRef(_refBase);
778 }
779
788#if !defined(doxygen)
789 template <class U>
790#endif
791 TfRefPtr(const TfRefPtr<U>& p) : _refBase(p._refBase) {
792 static_assert(std::is_convertible<U*, T*>::value, "");
793 _AddRef();
794 Tf_RefPtrTracker_New(this, _refBase, _NullT);
795 }
796
807#if !defined(doxygen)
808 template <class U>
809#endif
810 TfRefPtr(TfRefPtr<U>&& p) : _refBase(p._refBase) {
811 static_assert(std::is_convertible<U*, T*>::value, "");
812 p._refBase = nullptr;
813 Tf_RefPtrTracker_New(this, _refBase, _NullT);
814 Tf_RefPtrTracker_Assign(&p, p._refBase, _refBase, _NullT);
815 }
816
827#if !defined(doxygen)
828 template <class U>
829#endif
831 static_assert(std::is_convertible<U*, T*>::value, "");
832
833 Tf_RefPtrTracker_Assign(this, p._refBase, _refBase, _NullT);
834 const TfRefBase* tmp = _refBase;
835 _refBase = p._GetData();
836 p._AddRef(); // first!
837 _RemoveRef(tmp); // second!
838 return *this;
839 }
840
852#if !defined(doxygen)
853 template <class U>
854#endif
856 static_assert(std::is_convertible<U*, T*>::value, "");
857
858 Tf_RefPtrTracker_Assign(this, p._refBase, _refBase, _NullT);
859 Tf_RefPtrTracker_Assign(&p, nullptr, p._refBase, _NullT);
860 const TfRefBase* tmp = _refBase;
861 _refBase = p._GetData();
862 p._refBase = nullptr;
863 _RemoveRef(tmp);
864 return *this;
865 }
866
871#if !defined(doxygen)
872 template <class U>
873#endif
874 auto operator==(const TfRefPtr<U>& p) const
875 -> decltype(std::declval<T *>() == std::declval<U *>(), bool()) {
876 return _refBase == p._refBase;
877 }
878
882#if !defined(doxygen)
883 template <class U>
884#endif
885 auto operator!=(const TfRefPtr<U>& p) const
886 -> decltype(std::declval<T *>() != std::declval<U *>(), bool()) {
887 return _refBase != p._refBase;
888 }
889
894#if !defined(doxygen)
895 template <class U>
896#endif
897 auto operator<(const TfRefPtr<U>& p) const
898 -> decltype(std::declval<T *>() < std::declval<U *>(), bool()) {
899 return _refBase < p._refBase;
900 }
901
902#if !defined(doxygen)
903 template <class U>
904#endif
905 auto operator>(const TfRefPtr<U>& p) const
906 -> decltype(std::declval<T *>() > std::declval<U *>(), bool()) {
907 return _refBase > p._refBase;
908 }
909
910#if !defined(doxygen)
911 template <class U>
912#endif
913 auto operator<=(const TfRefPtr<U>& p) const
914 -> decltype(std::declval<T *>() <= std::declval<U *>(), bool()) {
915 return _refBase <= p._refBase;
916 }
917
918#if !defined(doxygen)
919 template <class U>
920#endif
921 auto operator>=(const TfRefPtr<U>& p) const
922 -> decltype(std::declval<T *>() >= std::declval<U *>(), bool()) {
923 return _refBase >= p._refBase;
924 }
925
927 T* operator->() const {
928 if (_refBase) {
929 return static_cast<T*>(const_cast<TfRefBase*>(_refBase));
930 }
931 Tf_PostNullSmartPtrDereferenceFatalError(
932 TF_CALL_CONTEXT, typeid(TfRefPtr).name());
933 }
934
936 T& operator *() const {
937 return *operator->();
938 }
939
940#if !defined(doxygen)
941 using UnspecifiedBoolType = const TfRefBase * (TfRefPtr::*);
942#endif
943
945 operator UnspecifiedBoolType() const {
946 return _refBase ? &TfRefPtr::_refBase : nullptr;
947 }
948
950 bool operator !() const {
951 return _refBase == nullptr;
952 }
953
958 void swap(TfRefPtr &other) {
959 Tf_RefPtrTracker_Assign(this, other._refBase, _refBase, _NullT);
960 Tf_RefPtrTracker_Assign(&other, _refBase, other._refBase, _NullT);
961 std::swap(_refBase, other._refBase);
962 }
963
966 void Reset() {
967 *this = TfNullPtr;
968 }
969
970private:
971 const TfRefBase* _refBase;
972
973 template <class HashState, class U>
974 friend inline void TfHashAppend(HashState &, const TfRefPtr<U>&);
975 template <class U>
976 friend inline size_t hash_value(const TfRefPtr<U>&);
977
978 friend T *get_pointer(TfRefPtr const &p) {
979 return static_cast<T *>(const_cast<TfRefBase *>(p._refBase));
980 }
981
982 // Used to distinguish construction in TfCreateRefPtr.
983 class _CreateRefPtr { };
984
985 // private constructor, used by TfCreateRefPtr()
986 TfRefPtr(T* ptr, _CreateRefPtr /* unused */)
987 : _refBase(ptr)
988 {
989 /* reference count is NOT bumped */
990 Tf_RefPtrTracker_FirstRef(this, _refBase, _NullT);
991 Tf_RefPtrTracker_New(this, _refBase, _NullT);
992 }
993
994 // Hide confusing internals of actual C++ definition (e.g. DataType)
995 // for doxygen output:
996
1012#if defined(doxygen)
1013 // Sanitized for documentation:
1014 template <class D>
1016#else
1017 template <class D, class B>
1020
1021 template <class D, class B>
1024#endif
1025
1042#if defined(doxygen)
1043 // Sanitized for documentation:
1044 template <class D>
1046#else
1047 template <class D, class B>
1049 TfStatic_cast(const TfRefPtr<B>&);
1050
1051#endif
1052
1064#if defined(doxygen)
1065 // Sanitized for documentation:
1066 template <class D>
1068#else
1069 template <class D>
1072#endif
1073
1074 T* _GetData() const {
1075 return static_cast<T*>(const_cast<TfRefBase*>(_refBase));
1076 }
1077
1084
1085 template <class U>
1086 friend const std::type_info& TfTypeid(const TfRefPtr<U>& ptr);
1087
1088 void _AddRef() const {
1089 _Counter::AddRef(_refBase);
1090 }
1091
1092 void _RemoveRef(const TfRefBase* ptr) const {
1093 if (_Counter::RemoveRef(ptr)) {
1094 // Synchronize with the release decrements of all other owners so
1095 // their prior accesses to *ptr happen-before its destruction.
1096 std::atomic_thread_fence(std::memory_order_acquire);
1097 Tf_RefPtrTracker_LastRef(this, ptr, _NullT);
1098 delete ptr;
1099 }
1100 }
1101
1102#if ! defined(doxygen)
1103 // doxygen is very confused by this. It declares all TfRefPtrs
1104 // to be friends.
1105 template <class U> friend class TfRefPtr;
1106 template <class U> friend class TfWeakPtr;
1107 friend class Tf_Remnant;
1108
1109 template <class U>
1111#endif
1112 friend class TfWeakBase;
1113};
1114
1115#if !defined(doxygen)
1116
1117//
1118// nullptr comparisons
1119//
1120// These are provided to avoid ambiguous overloads due to
1121// TfWeakPtrFacade::Derived comparisons with TfRefPtr.
1122//
1123
1124template <class T>
1125inline bool operator== (const TfRefPtr<T> &p, std::nullptr_t)
1126{
1127 return !p;
1128}
1129template <class T>
1130inline bool operator== (std::nullptr_t, const TfRefPtr<T> &p)
1131{
1132 return !p;
1133}
1134
1135template <class T>
1136inline bool operator!= (const TfRefPtr<T> &p, std::nullptr_t)
1137{
1138 return !(p == nullptr);
1139}
1140template <class T>
1141inline bool operator!= (std::nullptr_t, const TfRefPtr<T> &p)
1142{
1143 return !(nullptr == p);
1144}
1145
1146template <class T>
1147inline bool operator< (const TfRefPtr<T> &p, std::nullptr_t)
1148{
1149 return std::less<const TfRefBase *>()(get_pointer(p), nullptr);
1150}
1151template <class T>
1152inline bool operator< (std::nullptr_t, const TfRefPtr<T> &p)
1153{
1154 return std::less<const TfRefBase *>()(nullptr, get_pointer(p));
1155}
1156
1157template <class T>
1158inline bool operator<= (const TfRefPtr<T> &p, std::nullptr_t)
1159{
1160 return !(nullptr < p);
1161}
1162template <class T>
1163inline bool operator<= (std::nullptr_t, const TfRefPtr<T> &p)
1164{
1165 return !(p < nullptr);
1166}
1167
1168template <class T>
1169inline bool operator> (const TfRefPtr<T> &p, std::nullptr_t)
1170{
1171 return nullptr < p;
1172}
1173template <class T>
1174inline bool operator> (std::nullptr_t, const TfRefPtr<T> &p)
1175{
1176 return p < nullptr;
1177}
1178
1179template <class T>
1180inline bool operator>= (const TfRefPtr<T> &p, std::nullptr_t)
1181{
1182 return !(p < nullptr);
1183}
1184template <class T>
1185inline bool operator>= (std::nullptr_t, const TfRefPtr<T> &p)
1186{
1187 return !(nullptr < p);
1188}
1189
1190
1191template <typename T>
1192inline TfRefPtr<T> TfCreateRefPtr(T* ptr) {
1193 return TfRefPtr<T>(ptr, typename TfRefPtr<T>::_CreateRefPtr());
1194}
1195
1196template <class T>
1197const std::type_info&
1198TfTypeid(const TfRefPtr<T>& ptr)
1199{
1200 if (ARCH_UNLIKELY(!ptr._refBase))
1201 TF_FATAL_ERROR("called TfTypeid on NULL TfRefPtr");
1202
1203 return typeid(*ptr._GetData());
1204}
1205
1206template <class D, class T>
1207inline
1209TfDynamic_cast(const TfRefPtr<T>& ptr)
1210{
1211 typedef TfRefPtr<typename D::DataType> RefPtr;
1212 return RefPtr(dynamic_cast<typename D::DataType*>(ptr._GetData()));
1213}
1214
1215template <class D, class T>
1216inline
1219{
1220 typedef TfRefPtr<typename D::DataType> RefPtr;
1221 return RefPtr(TfSafeDynamic_cast<typename D::DataType*>(ptr._GetData()));
1222}
1223
1224template <class D, class T>
1225inline
1227TfStatic_cast(const TfRefPtr<T>& ptr)
1228{
1229 typedef TfRefPtr<typename D::DataType> RefPtr;
1230 return RefPtr(static_cast<typename D::DataType*>(ptr._GetData()));
1231}
1232
1233template <class T>
1234inline
1236TfConst_cast(const TfRefPtr<const typename T::DataType>& ptr)
1237{
1238 // this ugly cast allows TfConst_cast to work without requiring
1239 // a definition for T.
1240 typedef TfRefPtr<typename T::DataType> NonConstRefPtr;
1241 return *((NonConstRefPtr*)(&ptr));
1242}
1243
1244// Specialization: prevent construction of a TfRefPtr<TfRefBase>.
1245
1246template <>
1247class TfRefPtr<TfRefBase> {
1248private:
1249 TfRefPtr() = delete;
1250};
1251
1252template <>
1253class TfRefPtr<const TfRefBase> {
1254private:
1255 TfRefPtr() = delete;
1256};
1257
1258template <class T>
1259struct TfTypeFunctions<TfRefPtr<T> > {
1260 static T* GetRawPtr(const TfRefPtr<T>& t) {
1261 return t.operator-> ();
1262 }
1263
1264 static TfRefPtr<T> ConstructFromRawPtr(T* ptr) {
1265 return TfRefPtr<T>(ptr);
1266 }
1267
1268 static bool IsNull(const TfRefPtr<T>& t) {
1269 return !t;
1270 }
1271
1272 static void Class_Object_MUST_Be_Passed_By_Address() { }
1273 static void Class_Object_MUST_Not_Be_Const() { }
1274};
1275
1276template <class T>
1277struct TfTypeFunctions<TfRefPtr<const T> > {
1278 static const T* GetRawPtr(const TfRefPtr<const T>& t) {
1279 return t.operator-> ();
1280 }
1281
1282 static TfRefPtr<const T> ConstructFromRawPtr(T* ptr) {
1283 return TfRefPtr<const T>(ptr);
1284 }
1285
1286 static bool IsNull(const TfRefPtr<const T>& t) {
1287 return !t;
1288 }
1289
1290 static void Class_Object_MUST_Be_Passed_By_Address() { }
1291};
1292
1293#endif
1294
1295#if !defined(doxygen)
1296
1297template <class T>
1298inline void
1299swap(TfRefPtr<T>& lhs, TfRefPtr<T>& rhs)
1300{
1301 lhs.swap(rhs);
1302}
1303
1304template <class T>
1305inline size_t
1306hash_value(const TfRefPtr<T>& ptr)
1307{
1308 return TfHash()(ptr);
1309}
1310
1311template <class HashState, class T>
1312inline void
1313TfHashAppend(HashState &h, const TfRefPtr<T> &ptr)
1314{
1315 h.Append(get_pointer(ptr));
1316}
1317
1318#endif // !doxygen
1319
1320#define TF_SUPPORTS_REFPTR(T) std::is_base_of_v<TfRefBase, T>
1321
1322PXR_NAMESPACE_CLOSE_SCOPE
1323
1324#endif // PXR_BASE_TF_REF_PTR_H
A user-extensible hashing mechanism for use with runtime hash tables.
Definition hash.h:472
Enable a concrete base class for use with TfRefPtr.
Definition refBase.h:56
Reference-counted smart pointer utility class.
Definition refPtr.h:590
TfRefPtr< T > & operator=(const TfRefPtr< T > &p)
Assigns pointer to point at p's object, and increments reference count.
Definition refPtr.h:731
T & operator*() const
Dereferences the stored pointer.
Definition refPtr.h:936
T DataType
Convenience type accessor to underlying type T for template code.
Definition refPtr.h:602
TfRefPtr< T > & operator=(TfRefPtr< T > &&p)
Moves the pointer managed by p to *this and leaves p pointing at the NULL object.
Definition refPtr.h:758
auto operator==(const TfRefPtr< U > &p) const -> decltype(std::declval< T * >()==std::declval< U * >(), bool())
Returns true if *this and p point to the same object (or if they both point to NULL).
Definition refPtr.h:874
friend TfRefPtr< D > TfConst_cast(const TfRefPtr< const D > &)
Allows const casting of a TfRefPtr.
TfRefPtr< T > & operator=(const TfRefPtr< U > &p)
Assigns pointer to point at p's object, and increments reference count.
Definition refPtr.h:830
void Reset()
Set this pointer to point to no object.
Definition refPtr.h:966
TfRefPtr(TfRefPtr< T > &&p)
Moves the pointer managed by p to *this.
Definition refPtr.h:623
friend const std::type_info & TfTypeid(const TfRefPtr< U > &ptr)
Call typeid on the object pointed to by a TfRefPtr.
~TfRefPtr()
Decrements reference count of object being pointed to.
Definition refPtr.h:775
bool operator!() const
True if the pointer points to NULL.
Definition refPtr.h:950
void swap(TfRefPtr &other)
Swap this pointer with other.
Definition refPtr.h:958
TfRefPtr(U *ptr, typename std::enable_if< std::is_convertible< U *, T * >::value >::type *=nullptr)
Initializes to point at *ptr.
Definition refPtr.h:692
T * operator->() const
Accessor to T's public members.
Definition refPtr.h:927
friend TfRefPtr TfCreateRefPtr(T *)
Transfer a raw pointer to a reference-counted pointer.
friend TfRefPtr< D > TfStatic_cast(const TfRefPtr< T > &)
Allows static casting of a TfRefPtr.
TfRefPtr(TfNullPtrType)
Implicit conversion from TfNullPtr to TfRefPtr.
Definition refPtr.h:702
TfRefPtr(const TfRefPtr< T > &p)
Initializes *this to point at p's object.
Definition refPtr.h:632
TfRefPtr< T > & operator=(TfRefPtr< U > &&p)
Moves the pointer managed by p to *this and leaves p pointing at the NULL object.
Definition refPtr.h:855
auto operator!=(const TfRefPtr< U > &p) const -> decltype(std::declval< T * >() !=std::declval< U * >(), bool())
Returns true if *this and p do not point to the same object.
Definition refPtr.h:885
friend TfRefPtr< D > TfDynamic_cast(const TfRefPtr< T > &)
Allows dynamic casting of a TfRefPtr.
TfRefPtr()
Initialize pointer to nullptr.
Definition refPtr.h:613
TfRefPtr(TfRefPtr< U > &&p)
Moves the pointer managed by p to *this and leaves p pointing at the NULL object.
Definition refPtr.h:810
TfRefPtr(const TfRefPtr< U > &p)
Initializes to point at p's object, and increments reference count.
Definition refPtr.h:791
auto operator<(const TfRefPtr< U > &p) const -> decltype(std::declval< T * >()< std::declval< U * >(), bool())
Returns true if the address of the object pointed to by *this compares less than the address of the o...
Definition refPtr.h:897
TfRefPtr(std::nullptr_t)
Implicit conversion from nullptr to TfRefPtr.
Definition refPtr.h:708
Enable a concrete base class for use with TfWeakPtr.
Definition weakBase.h:124
Pointer storage with deletion detection.
Definition weakPtr.h:128
Stripped down version of diagnostic.h that doesn't define std::string.
#define TF_FATAL_ERROR(fmt, args)
Issue a fatal error and end the program.
Definition diagnostic.h:92
Compiler hints.
Safely compare C++ RTTI type structures.
TO TfSafeDynamic_cast(FROM *ptr)
Safely perform a dynamic cast.
Implements assorted functions based on compile-time type information.
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition token.h:486
TfRefPtr< T > TfCreateRefPtrFromProtectedWeakPtr(TfWeakPtr< T > const &p)
Thread-safe creation of a Tf ref pointer from a Tf weak pointer.
Definition weakPtr.h:260