13#ifndef RTCTK_COMPONENTFRAMEWORK_REQUESTDISPATCHER_HPP
14#define RTCTK_COMPONENTFRAMEWORK_REQUESTDISPATCHER_HPP
21#include <initializer_list>
24#include <unordered_map>
30template <
class Adapter,
typename... Args>
34 using LookupTable = std::unordered_map<std::type_index, DispatchFunction>;
43 return this->operator+=(std::move(rhs_copy));
47 for (
auto&& entry : std::forward<TableEntries>(rhs)) {
48 this->emplace_back(std::move(entry));
55 return this->
operator+(std::move(rhs_copy));
61 result += std::forward<TableEntries>(rhs);
68 std::type_index type =
typeid(T);
70 std::invoke(method, adapter, std::any_cast<T&>(request), args...);
72 return {{type, std::move(function)}};
83 for (
const auto& entry_list : table_entries) {
84 for (
const auto& entry : entry_list) {
90 void Dispatch(Adapter* adapter, std::any& request,
Args... args)
const {
91 auto iter = m_lut.find(request.type());
92 if (iter == m_lut.end()) {
95 auto function = iter->second;
96 function(adapter, request, args...);
101 return this->operator+=(std::move(rhs_copy));
105 m_lut.merge(std::forward<LookupTable>(rhs.m_lut));
111 return this->
operator+(std::move(rhs_copy));
Class used to parse default command line arguments.
Definition rtcComponentArgs.hpp:33
Definition requestDispatcher.hpp:37
TableEntries & operator+=(const TableEntries &rhs)
Definition requestDispatcher.hpp:41
TableEntries operator+(const TableEntries &rhs) const
Definition requestDispatcher.hpp:53
TableEntries operator+(TableEntries &&rhs) const
Definition requestDispatcher.hpp:58
TableEntries & operator+=(TableEntries &&rhs)
Definition requestDispatcher.hpp:46
Definition requestDispatcher.hpp:31
void Dispatch(Adapter *adapter, std::any &request, Args... args) const
Definition requestDispatcher.hpp:90
RequestDispatcher(RequestDispatcher &&rhs) noexcept=default
static TableEntries Bind(void(Adapter::*method)(T &, Args...))
Definition requestDispatcher.hpp:67
RequestDispatcher & operator=(const RequestDispatcher &rhs)=default
RequestDispatcher & operator+=(const RequestDispatcher &rhs)
Definition requestDispatcher.hpp:99
RequestDispatcher operator+(const RequestDispatcher &rhs) const
Definition requestDispatcher.hpp:109
std::unordered_map< std::type_index, DispatchFunction > LookupTable
Definition requestDispatcher.hpp:34
typename LookupTable::value_type TableEntry
Definition requestDispatcher.hpp:35
RequestDispatcher & operator=(RequestDispatcher &&rhs) noexcept=default
RequestDispatcher()=default
~RequestDispatcher()=default
RequestDispatcher(std::initializer_list< TableEntries > table_entries)
Definition requestDispatcher.hpp:82
std::function< void(Adapter *, std::any &, Args... args)> DispatchFunction
Definition requestDispatcher.hpp:33
RequestDispatcher operator+(RequestDispatcher &&rhs) const
Definition requestDispatcher.hpp:114
RequestDispatcher & operator+=(RequestDispatcher &&rhs)
Definition requestDispatcher.hpp:104
RequestDispatcher(const RequestDispatcher &rhs)=default
The UnsupportedTypeException is thrown whenever an attempt is made to use an unsupported type in the ...
Definition exceptions.hpp:239
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:33
Provides macros and utilities for exception handling.
Definition commandReplier.cpp:22
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
DataPointPath operator+(DataPointPath lhs, const DataPointPath &rhs)
Definition dataPointPath.hpp:418