template <typename T>

class RefPtr

Defined at line 55 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

RefPtr

<T

> holds a reference to an intrusively-refcounted object of type

T that deletes the object when the refcount drops to 0.

T should be a subclass of fbl::RefCounted

<

>, or something that adheres to

the same contract for AddRef() and Release().

Except for initial construction (see below), this generally adheres to a

subset of the interface for std::shared_ptr

<

>. Unlike std::shared_ptr

<

> this

type does not support vending weak pointers, introspecting the reference

count, or any operations that would result in allocating memory (unless

T::AddRef or T::Release allocate memory).

TODO(https://fxbug.dev/42144534): Align RefPtr more closely with standard library smart

pointers.

Construction: To create a RefPtr around a freshly created object, use the

AdoptRef free function at the bottom of this header. To construct a RefPtr

to hold a reference to an object that already exists use the copy or move

constructor or assignment operator.

Public Methods

void RefPtr<T> ()

Constructors

Defined at line 60 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void RefPtr<T> (decltype(nullptr) )

Defined at line 61 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void RefPtr<T> (T * p)

Constructs a RefPtr from a pointer that has already been adopted. See

AdoptRef() below for constructing the very first RefPtr to an object.

Defined at line 64 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void RefPtr<T> (const RefPtr<T> & r)

Copy construction.

Defined at line 70 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

template <typename U, typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
void RefPtr<T> (const RefPtr<U> & r)

Implicit upcast via copy construction.

Defined at line 76 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

RefPtr<T> & operator= (const RefPtr<T> & r)

Assignment

Defined at line 86 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void RefPtr<T> (RefPtr<T> && r)

Move construction

Defined at line 100 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

template <typename U, typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
void RefPtr<T> (RefPtr<U> && r)

Implicit upcast via move construction.

Defined at line 106 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

RefPtr<T> & operator= (RefPtr<T> && r)

Move assignment

Defined at line 118 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

template <typename BaseType>
void RefPtr<T> (T * ptr, RefPtr<BaseType> && base)

Construct via explicit downcast.

ptr must be the same object as base.ptr_.

Defined at line 126 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

template <typename BaseRefPtr>
RefPtr<T> Downcast (BaseRefPtr base)

Downcast via static method invocation. Depending on use case, the syntax

should look something like...

fbl::RefPtr

<MyBase

> foo = MakeBase();

auto bar_copy = fbl::RefPtr

<MyDerived

>::Downcast(foo);

auto bar_move = fbl::RefPtr

<MyDerived

>::Downcast(std::move(foo));

Defined at line 139 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void ~RefPtr<T> ()

Defined at line 150 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void reset (T * ptr)

Defined at line 159 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

void swap (RefPtr<T> & r)

Defined at line 161 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

T * get ()

Defined at line 167 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

T & operator* ()

Defined at line 168 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

T * operator-> ()

Defined at line 169 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

bool operator bool ()

Defined at line 170 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

bool operator== (decltype(nullptr) )

Comparison against nullptr operators (of the form, myptr == nullptr).

Defined at line 173 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

bool operator!= (decltype(nullptr) )

Defined at line 174 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

bool operator== (const RefPtr<T> & other)

Defined at line 176 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

bool operator!= (const RefPtr<T> & other)

Defined at line 177 of file ../../zircon/system/ulib/fbl/include/fbl/ref_ptr.h

Friends

template <typename T>
T * RefPtr (RefPtr<T> * )
template <typename T>
RefPtr RefPtr (T * ptr)
template <typename T>
RefPtr RefPtr (T * )
template <typename T>
RefPtr RefPtr (T * )
template <typename U>
class RefPtr