template class ugcs::vsm::Callback_proxy

Overview

Helper class for proxying callback invocation. More…

#include <callback.h>

template <class Result, typename... Args>
class Callback_proxy
{
public:
    // typedefs

    typedef Callback_base<Result> Callback_type;
    typedef typename Callback_type::template Ptr<> Callback_ptr;
    typedef typename std::tuple_element<arg_idx, Args_ref_tuple>::type Arg_ref_type;
    typedef typename std::tuple_element<arg_idx, Args_ptr_tuple>::type Arg_ptr_type;

    // classes

    class Hasher;

    // construction

    Callback_proxy();

    template <class Callback_ptr>
    Callback_proxy(Callback_ptr cbk);

    // methods

    template <typename... Invoke_args>
    void Set_args(Invoke_args&&... invoke_args) const;

    template <typename... Invoke_args>
    Result operator () (Invoke_args&&... invoke_args) const;

    Result Invoke() const;
    Callback_ptr Get_callback();
    operator bool () const;
    operator Callback_ptr ();

    template <size_t arg_idx>
    Arg_ref_type<arg_idx> Get_arg();

    template <size_t arg_idx, typename Arg_type>
    void Set_arg(Arg_type&& arg);

    bool operator == (const Callback_proxy& other) const;
    bool operator != (const Callback_proxy& other) const;
};

Detailed Documentation

Helper class for proxying callback invocation.

It is aware of specified number of first arguments to the target callback.

Parameters:

Result

Type of the callback invocation result.

Args

Type of the first arguments.

Typedefs

typedef Callback_base<Result> Callback_type

Base type of the underlying callback object.

typedef typename Callback_type::template Ptr<> Callback_ptr

Pointer to the underlying callback object.

typedef typename std::tuple_element<arg_idx, Args_ref_tuple>::type Arg_ref_type

Creates reference type to the argument with index arg_idx.

typedef typename std::tuple_element<arg_idx, Args_ptr_tuple>::type Arg_ptr_type

Creates pointer type to the argument with index arg_idx.

Construction

Callback_proxy()

Default constructor creates unbound instance.

template <class Callback_ptr>
Callback_proxy(Callback_ptr cbk)

Constructs instance bound to the provided callback object.

Methods

template <typename... Invoke_args>
void Set_args(Invoke_args&&... invoke_args) const

Set arguments values for callback invocation.

template <typename... Invoke_args>
Result operator () (Invoke_args&&... invoke_args) const

Invoke the callback with the specified first arguments.

Result Invoke() const

Invoke the callback with the previously set argument values.

Callback_ptr Get_callback()

Get the associated callback.

operator bool () const

Check if the proxy object is bound to some callback object.

operator Callback_ptr ()

Support implicit cast to callback base class.

template <size_t arg_idx>
Arg_ref_type<arg_idx> Get_arg()

Get reference to an argument at the specified position.

Template parameters:

  • arg_idx Index of the argument to get.

Returns:

Reference to the stored argument.

template <size_t arg_idx, typename Arg_type>
void Set_arg(Arg_type&& arg)

Set argument value at the specified position.

Template parameters:

  • arg_idx Argument position.

Parameters:

arg

Argument value.

bool operator == (const Callback_proxy& other) const

Equality operator.

Proxies pointing to the same callback are considered the same.

bool operator != (const Callback_proxy& other) const

Non-equality operator.

Proxies pointing to the different callbacks are considered different.