43 lines
734 B
C++
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
|
|
|