Chromium Embedded Framework (CEF)  117.1.0+ga287baf+chromium-117.0.5938.62
base::WeakPtr< T > Class Template Reference

The WeakPtr class holds a weak reference to |T*|. More...

#include "include/base/cef_weak_ptr.h"

Inheritance diagram for base::WeakPtr< T >:
base::cef_internal::WeakPtrBase

Public Member Functions

 WeakPtr ()=default
 
 WeakPtr (std::nullptr_t)
 
template<typename U >
 WeakPtr (const WeakPtr< U > &other)
 Allow conversion from U to T provided U "is a" T. More...
 
template<typename U >
 WeakPtr (WeakPtr< U > &&other) noexcept
 
T * get () const
 
T & operator* () const
 
T * operator-> () const
 
 operator bool () const
 Allow conditionals to test validity, e.g. More...
 
bool MaybeValid () const
 Returns false if the WeakPtr is confirmed to be invalid. More...
 
bool WasInvalidated () const
 Returns whether the object |this| points to has been invalidated. More...
 
- Public Member Functions inherited from base::cef_internal::WeakPtrBase
 WeakPtrBase ()
 
 ~WeakPtrBase ()
 
 WeakPtrBase (const WeakPtrBase &other)=default
 
 WeakPtrBase (WeakPtrBase &&other) noexcept=default
 
WeakPtrBaseoperator= (const WeakPtrBase &other)=default
 
WeakPtrBaseoperator= (WeakPtrBase &&other) noexcept=default
 
void reset ()
 

Friends

class cef_internal::SupportsWeakPtrBase
 
template<typename U >
class WeakPtr
 
class SupportsWeakPtr< T >
 
class WeakPtrFactory< T >
 

Additional Inherited Members

- Protected Member Functions inherited from base::cef_internal::WeakPtrBase
 WeakPtrBase (const WeakReference &ref, uintptr_t ptr)
 
- Protected Attributes inherited from base::cef_internal::WeakPtrBase
WeakReference ref_
 
uintptr_t ptr_
 

Detailed Description

template<typename T>
class base::WeakPtr< T >

The WeakPtr class holds a weak reference to |T*|.

This class is designed to be used like a normal pointer. You should always null-test an object of this class before using it or invoking a method that may result in the underlying object being destroyed.

EXAMPLE:

  class Foo { ... };
  WeakPtr<Foo> foo;
  if (foo)
    foo->method();

Constructor & Destructor Documentation

◆ WeakPtr() [1/4]

template<typename T >
base::WeakPtr< T >::WeakPtr ( )
default

◆ WeakPtr() [2/4]

template<typename T >
base::WeakPtr< T >::WeakPtr ( std::nullptr_t  )
inline

◆ WeakPtr() [3/4]

template<typename T >
template<typename U >
base::WeakPtr< T >::WeakPtr ( const WeakPtr< U > &  other)
inline

Allow conversion from U to T provided U "is a" T.

Note that this is separate from the (implicit) copy and move constructors.

◆ WeakPtr() [4/4]

template<typename T >
template<typename U >
base::WeakPtr< T >::WeakPtr ( WeakPtr< U > &&  other)
inlinenoexcept

Member Function Documentation

◆ get()

template<typename T >
T* base::WeakPtr< T >::get ( ) const
inline

◆ MaybeValid()

template<typename T >
bool base::WeakPtr< T >::MaybeValid ( ) const
inline

Returns false if the WeakPtr is confirmed to be invalid.

This call is safe to make from any thread, e.g. to optimize away unnecessary work, but operator bool() must always be called, on the correct thread, before actually using the pointer.

Warning: as with any object, this call is only thread-safe if the WeakPtr instance isn't being re-assigned or reset() racily with this call.

◆ operator bool()

template<typename T >
base::WeakPtr< T >::operator bool ( ) const
inlineexplicit

Allow conditionals to test validity, e.g.

if (weak_ptr) {...};

◆ operator*()

template<typename T >
T& base::WeakPtr< T >::operator* ( ) const
inline

◆ operator->()

template<typename T >
T* base::WeakPtr< T >::operator-> ( ) const
inline

◆ WasInvalidated()

template<typename T >
bool base::WeakPtr< T >::WasInvalidated ( ) const
inline

Returns whether the object |this| points to has been invalidated.

This can be used to distinguish a WeakPtr to a destroyed object from one that has been explicitly set to null.

Friends And Related Function Documentation

◆ cef_internal::SupportsWeakPtrBase

template<typename T >
friend class cef_internal::SupportsWeakPtrBase
friend

◆ SupportsWeakPtr< T >

template<typename T >
friend class SupportsWeakPtr< T >
friend

◆ WeakPtr

template<typename T >
template<typename U >
friend class WeakPtr
friend

◆ WeakPtrFactory< T >

template<typename T >
friend class WeakPtrFactory< T >
friend

The documentation for this class was generated from the following file: