|
| TfRefPtr () |
| Initialize pointer to nullptr.
|
|
| TfRefPtr (TfRefPtr< T > &&p) |
| Moves the pointer managed by p to *this .
|
|
| TfRefPtr (const TfRefPtr< T > &p) |
| Initializes *this to point at p's object.
|
|
template<template< class > class X, class U > |
| TfRefPtr (const TfWeakPtrFacade< X, U > &p, typename std::enable_if< std::is_convertible< U *, T * >::value >::type *=0) |
| Initializes *this to point at gp's object.
|
|
template<class U > |
| TfRefPtr (U *ptr, typename std::enable_if< std::is_convertible< U *, T * >::value >::type *=nullptr) |
| Initializes to point at *ptr .
|
|
| TfRefPtr (TfNullPtrType) |
| Implicit conversion from TfNullPtr to TfRefPtr.
|
|
| TfRefPtr (std::nullptr_t) |
| Implicit conversion from nullptr to TfRefPtr.
|
|
TfRefPtr< T > & | operator= (const TfRefPtr< T > &p) |
| Assigns pointer to point at p's object, and increments reference count.
|
|
TfRefPtr< T > & | operator= (TfRefPtr< T > &&p) |
| Moves the pointer managed by p to *this and leaves p pointing at the NULL object.
|
|
| ~TfRefPtr () |
| Decrements reference count of object being pointed to.
|
|
| TfRefPtr (const TfRefPtr< U > &p) |
| Initializes to point at p's object, and increments reference count.
|
|
| TfRefPtr (TfRefPtr< U > &&p) |
| Moves the pointer managed by p to *this and leaves p pointing at the NULL object.
|
|
TfRefPtr< T > & | operator= (const TfRefPtr< U > &p) |
| Assigns pointer to point at p's object, and increments reference count.
|
|
TfRefPtr< T > & | operator= (TfRefPtr< U > &&p) |
| Moves the pointer managed by p to *this and leaves p pointing at the NULL object.
|
|
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).
|
|
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.
|
|
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 object pointed to by p .
|
|
auto | operator> (const TfRefPtr< U > &p) const -> decltype(std::declval< T * >() > std::declval< U * >(), bool()) |
|
auto | operator<= (const TfRefPtr< U > &p) const -> decltype(std::declval< T * >()<=std::declval< U * >(), bool()) |
|
auto | operator>= (const TfRefPtr< U > &p) const -> decltype(std::declval< T * >() >=std::declval< U * >(), bool()) |
|
T * | operator-> () const |
| Accessor to T's public members.
|
|
T & | operator* () const |
| Dereferences the stored pointer.
|
|
| operator UnspecifiedBoolType () const |
| True if the pointer points to an object.
|
|
bool | operator! () const |
| True if the pointer points to NULL .
|
|
void | swap (TfRefPtr &other) |
| Swap this pointer with other.
|
|
void | Reset () |
| Set this pointer to point to no object.
|
|
template<class T>
class TfRefPtr< T >
Reference-counted smart pointer utility class.
The TfRefPtr
class implements a reference counting on objects that inherit from TfRefBase
.
For more information, see either the Quick Start example or read the detailed discussion.
Definition at line 576 of file refPtr.h.
Assigns pointer to point at p's
object, and increments reference count.
The object (if any) pointed at before the assignment has its reference count decremented, while the object newly pointed at has its reference count incremented. If the object previously pointed to now has nobody left to point at it, the object will typically be destroyed at this point.
An assignment
can be used to make ptr
"forget" where it is pointing; note however that this has an important side effect, since it decrements the reference count of the object previously pointed to by ptr
, possibly triggering destruction of that object.
Definition at line 717 of file refPtr.h.
Transfer a raw pointer to a reference-counted pointer.
The TfCreateRefPtr()
function should only be used from within a static New()
function (or similarly, a Clone()
function) of a reference-counted class. Reference-counted objects have their reference count initially set to one to account for the fact that a newly created object must always persist at least until its New()
function returns. Therefore, the transfer of the pointer returned by new
into a reference pointer must not increase the reference count. The transfer of the raw pointer returned by new
into the object returned by New()
is a "transfer of ownership" and does not represent an additional reference to the object.
In summary, this code is wrong, and will return an object that can never be destroyed:
SimpleRefPtr Simple::New() {
return SimpleRefPtr(new Simple);
}
The correct form is
SimpleRefPtr Simple::New() {
}
friend TfRefPtr TfCreateRefPtr(T *)
Transfer a raw pointer to a reference-counted pointer.
Note also that a function which is essentially like New()
, for example Clone()
, would also want to use TfCreateRefPtr()
.
Allows static casting of a TfRefPtr
.
If it is legal to statically cast a T*
to a D*
, then the following is also legal:
dPtr = TfStatic_cast< TfRefPtr<D> >(tPtr);
The runtime performance of this function is exactly the same as a regular TfRefPtr
initialization, since the cost of the underlying static_cast
is zero. Of course, a TfDynamic_cast
is preferred, assuming the underlying types are polymorphic (i.e. have virtual functions).