12#ifndef RTCTK_COMPONENTFRAMEWORK_REQUESTDISPATCHER_HPP
13#define RTCTK_COMPONENTFRAMEWORK_REQUESTDISPATCHER_HPP
20#include <initializer_list>
23#include <unordered_map>
29template <
class Adapter,
typename...
Args>
33 using LookupTable = std::unordered_map<std::type_index, DispatchFunction>;
46 for (
auto&& entry : std::forward<TableEntries>(rhs)) {
47 this->emplace_back(std::move(entry));
54 return this->
operator+(std::move(rhs_copy));
60 result += std::forward<TableEntries>(rhs);
66 static TableEntries
Bind(
void (Adapter::*method)(T&,
Args...)) {
67 std::type_index type =
typeid(T);
69 std::invoke(method, adapter, std::any_cast<T&>(request), std::forward<Args>(args)...);
71 return {{type, std::move(function)}};
82 for (
const auto& entry_list : table_entries) {
83 for (
const auto& entry : entry_list) {
89 void Dispatch(Adapter* adapter, std::any& request,
Args... args)
const {
90 auto iter = m_lut.find(request.type());
91 if (iter == m_lut.end()) {
94 auto function = iter->second;
95 function(adapter, request, std::forward<Args>(args)...);
104 m_lut.merge(std::forward<LookupTable>(rhs.m_lut));
110 return this->
operator+(std::move(rhs_copy));
Class used to parse default command line arguments.
Definition rtcComponentArgs.hpp:32
Definition requestDispatcher.hpp:36
TableEntries & operator+=(const TableEntries &rhs)
Definition requestDispatcher.hpp:40
TableEntries operator+(const TableEntries &rhs) const
Definition requestDispatcher.hpp:52
TableEntries operator+(TableEntries &&rhs) const
Definition requestDispatcher.hpp:57
TableEntries & operator+=(TableEntries &&rhs)
Definition requestDispatcher.hpp:45
void Dispatch(Adapter *adapter, std::any &request, Args... args) const
Definition requestDispatcher.hpp:89
RequestDispatcher(RequestDispatcher &&rhs) noexcept=default
static TableEntries Bind(void(Adapter::*method)(T &, Args...))
Definition requestDispatcher.hpp:66
RequestDispatcher & operator=(const RequestDispatcher &rhs)=default
RequestDispatcher & operator+=(const RequestDispatcher &rhs)
Definition requestDispatcher.hpp:98
RequestDispatcher operator+(const RequestDispatcher &rhs) const
Definition requestDispatcher.hpp:108
std::unordered_map< std::type_index, DispatchFunction > LookupTable
Definition requestDispatcher.hpp:33
typename LookupTable::value_type TableEntry
Definition requestDispatcher.hpp:34
RequestDispatcher & operator=(RequestDispatcher &&rhs) noexcept=default
RequestDispatcher()=default
~RequestDispatcher()=default
RequestDispatcher(std::initializer_list< TableEntries > table_entries)
Definition requestDispatcher.hpp:81
std::function< void(Adapter *, std::any &, Args... args)> DispatchFunction
Definition requestDispatcher.hpp:32
RequestDispatcher operator+(RequestDispatcher &&rhs) const
Definition requestDispatcher.hpp:113
RequestDispatcher & operator+=(RequestDispatcher &&rhs)
Definition requestDispatcher.hpp:103
RequestDispatcher(const RequestDispatcher &rhs)=default
The UnsupportedTypeException is thrown whenever an attempt is made to use an unsupported type in the ...
Definition exceptions.hpp:248
Project-wide configuration header.
#define RTCTK_API
Helper to indicate that a class or function must be exported in the public symbol table.
Definition config.hpp:32
Provides macros and utilities for exception handling.
Definition commandReplier.cpp:21