template <typename T>

class WeakPtrFactory

Defined at line 79 of file ../../third_party/perfetto/include/perfetto/ext/base/weak_ptr.h

A simple WeakPtr for single-threaded cases.

Generally keep the WeakPtrFactory as last fields in classes: it makes the

WeakPtr(s) invalidate as first thing in the class dtor.

Usage:

class MyClass {

MyClass() : weak_factory_(this) {}

WeakPtr

<MyClass

> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }

private:

WeakPtrFactory

<MyClass

> weak_factory_;

}

int main() {

std::unique_ptr

<MyClass

> foo(new MyClass);

auto wptr = foo.GetWeakPtr();

ASSERT_TRUE(wptr);

ASSERT_EQ(foo.get(), wptr->get());

foo.reset();

ASSERT_FALSE(wptr);

ASSERT_EQ(nullptr, wptr->get());

}

Public Methods

void WeakPtrFactory<T> (T * owner)

Defined at line 81 of file ../../third_party/perfetto/include/perfetto/ext/base/weak_ptr.h

void ~WeakPtrFactory<T> ()

Defined at line 85 of file ../../third_party/perfetto/include/perfetto/ext/base/weak_ptr.h

WeakPtr<T> GetWeakPtr ()

Can be safely called on any thread, since it simply copies |weak_ptr_|.

Note that any accesses to the returned pointer need to be made on the

thread that created/reset the factory.

Defined at line 93 of file ../../third_party/perfetto/include/perfetto/ext/base/weak_ptr.h

void Reset (T * owner)

Reset the factory to a new owner

&

thread. May only be called before any

weak pointers were passed out. Future weak pointers will be valid on the

calling thread.

Defined at line 98 of file ../../third_party/perfetto/include/perfetto/ext/base/weak_ptr.h