userver: utils::LazySharedPtr< T > Class Template Reference
Loading...
Searching...
No Matches
utils::LazySharedPtr< T > Class Template Referencefinal

#include <userver/utils/lazy_shared_ptr.hpp>

Detailed Description

template<typename T>
class utils::LazySharedPtr< T >

A lazy wrapper around utils::SharedReadablePtr that fetches the data on first access.

Provides standard thread-safety guarantee: const methods can be called concurrently. Once fetched, the same data is guaranteed to be returned unless the pointer is assigned to.

Definition at line 29 of file lazy_shared_ptr.hpp.

Public Member Functions

 LazySharedPtr () noexcept
 The default constructor, initializes with nullptr.
 
 LazySharedPtr (utils::SharedReadablePtr< T > ptr) noexcept
 The non-lazy constructor.
 
 LazySharedPtr (std::function< utils::SharedReadablePtr< T >()> function) noexcept
 The lazy constructor.
 
 LazySharedPtr (const LazySharedPtr &other)
 The copy constructor.
 
 LazySharedPtr (LazySharedPtr &&other) noexcept
 The move constructor.
 
LazySharedPtroperator= (const LazySharedPtr &other)
 The copy assignment operator.
 
LazySharedPtroperator= (LazySharedPtr &&other) noexcept
 The move assignment operator.
 
const T * Get () const &USERVER_IMPL_LIFETIME_BOUND
 Get a pointer to the data (may be null). Fetches the data on the first access.
 
const utils::SharedReadablePtr< T > & GetShared () const &USERVER_IMPL_LIFETIME_BOUND
 Get a smart pointer to the data (may be null). Fetches the data on the first access.
 
const T & operator* () const &USERVER_IMPL_LIFETIME_BOUND
 
const T * operator-> () const &USERVER_IMPL_LIFETIME_BOUND
 
 operator bool () const &USERVER_IMPL_LIFETIME_BOUND
 
 operator const utils::SharedReadablePtr< T > & () const &USERVER_IMPL_LIFETIME_BOUND
 
 operator std::shared_ptr< const T > () const &USERVER_IMPL_LIFETIME_BOUND
 

Constructor & Destructor Documentation

◆ LazySharedPtr() [1/5]

template<typename T>
utils::LazySharedPtr< T >::LazySharedPtr ( )
inlinenoexcept

The default constructor, initializes with nullptr.

Definition at line 32 of file lazy_shared_ptr.hpp.

◆ LazySharedPtr() [2/5]

template<typename T>
utils::LazySharedPtr< T >::LazySharedPtr ( utils::SharedReadablePtr< T > ptr)
inlinenoexcept

The non-lazy constructor.

Definition at line 35 of file lazy_shared_ptr.hpp.

◆ LazySharedPtr() [3/5]

template<typename T>
utils::LazySharedPtr< T >::LazySharedPtr ( std::function< utils::SharedReadablePtr< T >()> function)
inlinenoexcept

The lazy constructor.

Definition at line 39 of file lazy_shared_ptr.hpp.

◆ LazySharedPtr() [4/5]

template<typename T>
utils::LazySharedPtr< T >::LazySharedPtr ( const LazySharedPtr< T > & other)
inline

The copy constructor.

Note
If other has not been fetched yet, this will not fetch immediately, so this and other may end up pointing to different objects.

Definition at line 45 of file lazy_shared_ptr.hpp.

◆ LazySharedPtr() [5/5]

template<typename T>
utils::LazySharedPtr< T >::LazySharedPtr ( LazySharedPtr< T > && other)
inlinenoexcept

The move constructor.

Definition at line 56 of file lazy_shared_ptr.hpp.

Member Function Documentation

◆ Get()

template<typename T>
const T * utils::LazySharedPtr< T >::Get ( ) const &
inline

Get a pointer to the data (may be null). Fetches the data on the first access.

Definition at line 80 of file lazy_shared_ptr.hpp.

◆ GetShared()

template<typename T>
const utils::SharedReadablePtr< T > & utils::LazySharedPtr< T >::GetShared ( ) const &
inline

Get a smart pointer to the data (may be null). Fetches the data on the first access.

Definition at line 94 of file lazy_shared_ptr.hpp.

◆ operator bool()

template<typename T>
utils::LazySharedPtr< T >::operator bool ( ) const &
inlineexplicit
Returns
Get() != nullptr

Definition at line 124 of file lazy_shared_ptr.hpp.

◆ operator const utils::SharedReadablePtr< T > &()

template<typename T>
utils::LazySharedPtr< T >::operator const utils::SharedReadablePtr< T > & ( ) const &
inline
Returns
GetShared()

Definition at line 127 of file lazy_shared_ptr.hpp.

◆ operator std::shared_ptr< const T >()

template<typename T>
utils::LazySharedPtr< T >::operator std::shared_ptr< const T > ( ) const &
inline
Returns
GetShared()

Definition at line 130 of file lazy_shared_ptr.hpp.

◆ operator*()

template<typename T>
const T & utils::LazySharedPtr< T >::operator* ( ) const &
inline
Returns
*Get()
Note
Get() must not be nullptr.

Definition at line 113 of file lazy_shared_ptr.hpp.

◆ operator->()

template<typename T>
const T * utils::LazySharedPtr< T >::operator-> ( ) const &
inline
Returns
Get()
Note
Get() must not be nullptr.

Definition at line 121 of file lazy_shared_ptr.hpp.

◆ operator=() [1/2]

template<typename T>
LazySharedPtr & utils::LazySharedPtr< T >::operator= ( const LazySharedPtr< T > & other)
inline

The copy assignment operator.

Note
Like copy-constructor, it does not generate pointers if other do not generate them.

Definition at line 65 of file lazy_shared_ptr.hpp.

◆ operator=() [2/2]

template<typename T>
LazySharedPtr & utils::LazySharedPtr< T >::operator= ( LazySharedPtr< T > && other)
inlinenoexcept

The move assignment operator.

Definition at line 71 of file lazy_shared_ptr.hpp.


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