Seastar
High performance C++ framework for concurrent servers
Public Types | Public Member Functions | List of all members
seastar::checked_ptr< Ptr, NullDerefAction > Class Template Reference

Detailed Description

template<typename Ptr, typename NullDerefAction = default_null_deref_action>
class seastar::checked_ptr< Ptr, NullDerefAction >

seastar::checked_ptr class is a wrapper class that may be used with any pointer type (smart like std::unique_ptr or raw pointers like int*).

The seastar::checked_ptr object will invoke the NullDerefAction functor if it is dereferenced when the underlying pointer is not engaged.

It may still be assigned, compared to other seastar::checked_ptr objects or moved without limitations.

The default NullDerefAction will throw a seastar::default_null_deref_action exception.

Template Parameters
NullDerefActiona functor that is invoked when a user tries to dereference a not engaged pointer.

#include <seastar/core/checked_ptr.hh>

Public Types

using element_type = typename std::pointer_traits< Ptr >::element_type
 Underlying element type.
 
using pointer = element_type *
 Type of the pointer to the underlying element.
 

Public Member Functions

 checked_ptr (std::nullptr_t) noexcept(std::is_nothrow_default_constructible_v< checked_ptr< Ptr, NullDerefAction >>)
 
 checked_ptr (Ptr &&ptr) noexcept(std::is_nothrow_move_constructible_v< Ptr >)
 
 checked_ptr (const Ptr &p) noexcept(std::is_nothrow_copy_constructible_v< Ptr >)
 
Checked Methods

These methods start with invoking a NullDerefAction functor if the underlying pointer is not engaged.

pointer get () const
 
const Ptr & operator-> () const
 
Ptr & operator-> ()
 
const element_typeoperator* () const
 
element_typeoperator* ()
 
Unchecked methods

These methods may be invoked when the underlying pointer is not engaged.

 operator bool () const
 
bool operator== (const checked_ptr &other) const
 
bool operator!= (const checked_ptr &other) const
 
size_t hash () const
 

Member Function Documentation

◆ get()

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
pointer seastar::checked_ptr< Ptr, NullDerefAction >::get ( ) const
inline

Invokes the get() method of the underlying smart pointer or returns the pointer itself for a raw pointer (const variant).

Returns
The pointer to the underlying object

◆ hash()

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
size_t seastar::checked_ptr< Ptr, NullDerefAction >::hash ( ) const
inline

Gets the hash value for the underlying pointer object.

Returns
The hash value for the underlying pointer object

◆ operator bool()

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
seastar::checked_ptr< Ptr, NullDerefAction >::operator bool ( ) const
inlineexplicit

Checks if the underlying pointer is engaged.

Returns
TRUE if the underlying pointer is engaged

◆ operator*() [1/2]

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
element_type& seastar::checked_ptr< Ptr, NullDerefAction >::operator* ( )
inline

Gets the reference to the underlying object.

Returns
The reference to the underlying object

◆ operator*() [2/2]

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
const element_type& seastar::checked_ptr< Ptr, NullDerefAction >::operator* ( ) const
inline

Gets the reference to the underlying object (const variant).

Returns
The reference to the underlying object

◆ operator->() [1/2]

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
Ptr& seastar::checked_ptr< Ptr, NullDerefAction >::operator-> ( )
inline

Gets a reference to the underlying pointer object (const variant).

Returns
The underlying pointer object

◆ operator->() [2/2]

template<typename Ptr , typename NullDerefAction = default_null_deref_action>
const Ptr& seastar::checked_ptr< Ptr, NullDerefAction >::operator-> ( ) const
inline

Gets a reference to the underlying pointer object.

Returns
The underlying pointer object

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