opengenerals/processor/pc/ProcedureManager.h
szdytom f0445542ce
Add procedure call impl
Signed-off-by: szdytom <szdytom@qq.com>
2024-02-04 13:47:53 +08:00

43 lines
734 B
C++

#ifndef OGPC_PMANAGER_H_
#define OGPC_PMANAGER_H_
inline namespace {
template <typename T>
struct FuncArgTraits;
template <typename R, typename T>
struct FuncArgTraits<R(T)> {
using type = T;
};
}
#include <map>
#include <string>
#include <functional>
class ProcedureManager {
public:
ProcedureManager();
template <typename T>
void registerProcedure(const std::string &name, T&& func) {
procedures[name] = [&func](BinraryBuffer &b) -> BinaryBuffer {
using Arg = typename FuncArgTraits<T::operator()>::type;
Arg x;
b >> x;
auto y = func(std::move(x));
BinaryBuffer res;
res << y;
return res;
};
}
private:
std::map<std::string, std::function<BinaryBuffer(BinaryBuffer&)>> procedures;
};
#endif