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 28 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 &
 Get a pointer to the data (may be null). Fetches the data on the first access.
 
const utils::SharedReadablePtr< T > & GetShared () const &
 Get a smart pointer to the data (may be null). Fetches the data on the first access.
 
const T & operator* () const &
 
const T * operator-> () const &
 
 operator bool () const &
 
 operator const utils::SharedReadablePtr< T > & () const &
 
 operator std::shared_ptr< const T > () const &
 

Constructor & Destructor Documentation

◆ LazySharedPtr() [1/5]

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

The default constructor, initializes with nullptr.

Definition at line 31 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 46 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 55 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 95 of file lazy_shared_ptr.hpp.

◆ operator bool()

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

Definition at line 126 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 129 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 132 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 115 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 123 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 64 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 70 of file lazy_shared_ptr.hpp.


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