ゴミ箱
Classes | Public Types | Public Member Functions | List of all members
boost::beast::handler_ptr< T, Handler > Class Template Reference

#include <handler_ptr.hpp>

Public Types

using element_type = T
 The type of element this object stores. More...
 
using handler_type = Handler
 The type of handler this object stores. More...
 

Public Member Functions

handler_ptroperator= (handler_ptr const &)=delete
 Copy assignment (disallowed). More...
 
 ~handler_ptr ()
 
 handler_ptr (handler_ptr &&other)
 
 handler_ptr (handler_ptr const &other)
 Copy constructor. More...
 
template<class... Args>
 handler_ptr (Handler &&handler, Args &&...args)
 
template<class... Args>
 handler_ptr (Handler const &handler, Args &&...args)
 
handler_typehandler () const
 Returns a reference to the handler. More...
 
 operator bool () const
 Returns true if *this owns an object. More...
 
T * get () const
 
T & operator* () const
 Return a reference to the owned object. More...
 
T * operator-> () const
 Return a pointer to the owned object. More...
 
handler_type release_handler ()
 
template<class... Args>
void invoke (Args &&...args)
 

Detailed Description

template<class T, class Handler>
class boost::beast::handler_ptr< T, Handler >

A smart pointer container with associated completion handler.

This is a smart pointer that retains shared ownership of an object through a pointer. Memory is managed using the allocation and deallocation functions associated with a completion handler, which is also stored in the object. The managed object is destroyed and its memory deallocated when one of the following happens:

Objects of this type are used in the implementation of composed operations. Typically the composed operation's shared state is managed by the handler_ptr and an allocator associated with the final handler is used to create the managed object.

Note
The reference count is stored using a 16 bit unsigned integer. Making more than 2^16 copies of one object results in undefined behavior.
Template Parameters
TThe type of the owned object.
HandlerThe type of the completion handler.

Member Typedef Documentation

template<class T, class Handler>
using boost::beast::handler_ptr< T, Handler >::element_type = T

The type of element this object stores.

template<class T, class Handler>
using boost::beast::handler_ptr< T, Handler >::handler_type = Handler

The type of handler this object stores.

Constructor & Destructor Documentation

template<class T , class Handler >
boost::beast::handler_ptr< T, Handler >::~handler_ptr ( )

Destructs the owned object if no more handler_ptr link to it.

If *this owns an object and it is the last handler_ptr owning it, the object is destroyed and the memory deallocated using the associated deallocator.

template<class T , class Handler >
boost::beast::handler_ptr< T, Handler >::handler_ptr ( handler_ptr< T, Handler > &&  other)

Move constructor.

When this call returns, the moved-from container will have no owned object.

template<class T , class Handler >
boost::beast::handler_ptr< T, Handler >::handler_ptr ( handler_ptr< T, Handler > const &  other)

Copy constructor.

template<class T , class Handler>
template<class... Args>
boost::beast::handler_ptr< T, Handler >::handler_ptr ( Handler &&  handler,
Args &&...  args 
)

Construct a new handler_ptr

This creates a new handler_ptr with an owned object of type T. The allocator associated with the handler will be used to allocate memory for the owned object. The constructor for the owned object will be called thusly:

T(handler, std::forward<Args>(args)...)
Parameters
handlerThe handler to associate with the owned object. The argument will be moved.
argsOptional arguments forwarded to the owned object's constructor.
template<class T , class Handler>
template<class... Args>
boost::beast::handler_ptr< T, Handler >::handler_ptr ( Handler const &  handler,
Args &&...  args 
)

Construct a new handler_ptr

This creates a new handler_ptr with an owned object of type T. The allocator associated with the handler will be used to allocate memory for the owned object. The constructor for the owned object will be called thusly:

T(handler, std::forward<Args>(args)...)
Parameters
handlerThe handler to associate with the owned object. The argument will be copied.
argsOptional arguments forwarded to the owned object's constructor.

Member Function Documentation

template<class T, class Handler>
T* boost::beast::handler_ptr< T, Handler >::get ( ) const
inline

Returns a pointer to the owned object.

If *this owns an object, a pointer to the object is returned, else nullptr is returned.

template<class T, class Handler>
handler_type& boost::beast::handler_ptr< T, Handler >::handler ( ) const
inline

Returns a reference to the handler.

template<class T , class Handler >
template<class... Args>
void boost::beast::handler_ptr< T, Handler >::invoke ( Args &&...  args)

Invoke the handler in the owned object.

This function invokes the handler in the owned object with a forwarded argument list. Before the invocation, the owned object is destroyed, satisfying the deallocation-before-invocation Asio guarantee. All instances of handler_ptr which refer to the same owned object will be reset, including this instance.

Note
Care must be taken when the arguments are themselves stored in the owned object. Such arguments must first be moved to the stack or elsewhere, and then passed, or else undefined behavior will result.
template<class T, class Handler>
boost::beast::handler_ptr< T, Handler >::operator bool ( ) const
inlineexplicit

Returns true if *this owns an object.

template<class T, class Handler>
T& boost::beast::handler_ptr< T, Handler >::operator* ( ) const
inline

Return a reference to the owned object.

template<class T, class Handler>
T* boost::beast::handler_ptr< T, Handler >::operator-> ( ) const
inline

Return a pointer to the owned object.

template<class T, class Handler>
handler_ptr& boost::beast::handler_ptr< T, Handler >::operator= ( handler_ptr< T, Handler > const &  )
delete

Copy assignment (disallowed).

template<class T , class Handler >
auto boost::beast::handler_ptr< T, Handler >::release_handler ( )

Release ownership of the handler

If *this owns an object, it is first destroyed.

Returns
The released handler.

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