|
|
@ -98,48 +98,32 @@ class FrontMsgProcesser { |
|
|
|
}; |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
string getTypeName(const T& val) { |
|
|
|
string getTypeName(const string& className, const string fnName) { |
|
|
|
if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { |
|
|
|
return typeInfoMap[type_index(typeid(T))].typeName; |
|
|
|
} |
|
|
|
throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name())); |
|
|
|
}; |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
string getTypeName(const shared_ptr<T>& val) { |
|
|
|
if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { |
|
|
|
return typeInfoMap[type_index(typeid(T))].typeName; |
|
|
|
} |
|
|
|
throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name())); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
string getTypeName() { |
|
|
|
if (typeInfoMap.find(type_index(typeid(T))) != typeInfoMap.end()) { |
|
|
|
return typeInfoMap[type_index(typeid(T))].typeName; |
|
|
|
} |
|
|
|
throw std::runtime_error(fmt::format("getTypeName error:{}", typeid(T).name())); |
|
|
|
return typeid(T).name(); |
|
|
|
// throw std::runtime_error(fmt::format("reg {}:{} fail,getTypeName error:{}", className, fnName, typeid(T).name()));
|
|
|
|
}; |
|
|
|
|
|
|
|
//
|
|
|
|
// ref https://blog.csdn.net/Veritaz/article/details/113820764
|
|
|
|
//
|
|
|
|
template <typename R, typename... Args> |
|
|
|
void regProcesser(const string& className, const string fnName, vector<string> params, MsgProcesserFn_t fn) { |
|
|
|
vector<string> paramsTypeInfo; |
|
|
|
string ret = getTypeName<R>(); |
|
|
|
(paramsTypeInfo.push_back(getTypeName<Args>()), ...); |
|
|
|
string ret = getTypeName<R>(className, fnName); |
|
|
|
(paramsTypeInfo.push_back(getTypeName<Args>(className, fnName)), ...); |
|
|
|
|
|
|
|
string key = className + "." + fnName; |
|
|
|
shared_ptr<MsgProcesser> processer = nullptr; |
|
|
|
if (m_msgProcesserMap.find(key) != m_msgProcesserMap.end()) { |
|
|
|
processer = m_msgProcesserMap[key]; |
|
|
|
} |
|
|
|
ZASSERT(processer); |
|
|
|
processer->className = className; |
|
|
|
processer->fnName = fnName; |
|
|
|
processer->paramsTypeInfo = paramsTypeInfo; |
|
|
|
processer->params = params; |
|
|
|
processer->retTypeInfo = ret; |
|
|
|
processer->fn = fn; |
|
|
|
m_msgProcesserMap[key] = processer; |
|
|
|
shared_ptr<MsgProcesser> processer = make_shared<MsgProcesser>(); |
|
|
|
processer->className = className; |
|
|
|
processer->fnName = fnName; |
|
|
|
processer->paramsTypeInfo = paramsTypeInfo; |
|
|
|
processer->params = params; |
|
|
|
processer->retTypeInfo = ret; |
|
|
|
processer->fn = fn; |
|
|
|
m_msgProcesserMap[key] = processer; |
|
|
|
m_msgProcesserList.push_back(processer); |
|
|
|
} |
|
|
|
}; |
|
|
@ -183,37 +167,3 @@ static inline T jsonGet(json j) { |
|
|
|
fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ |
|
|
|
}); |
|
|
|
#define REG_EXTFN_VOID(fn, type) FrontMsgProcesser::ins().regProcesser<type>(thisClass.className, #fn, {}, [this](shared_ptr<MsgProcessContext> cxt) { fn(cxt); });
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define REG_FN(fn, type, ...) \
|
|
|
|
{ \ |
|
|
|
type __fn_type; \ |
|
|
|
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, /**/ \ |
|
|
|
{MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, /**/ \ |
|
|
|
__fn_type, /**/ \ |
|
|
|
[this](shared_ptr<MsgProcessContext> cxt) { \ |
|
|
|
json& params = cxt->params; \ |
|
|
|
cxt->content = fn(MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ |
|
|
|
}); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define REG_FN_VOID(fn, type) \
|
|
|
|
{ \ |
|
|
|
type __fn_type; \ |
|
|
|
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, __fn_type, [this](shared_ptr<MsgProcessContext> cxt) { cxt->content = fn(); }); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define REG_EXTFN(fn, type, ...) \
|
|
|
|
{ \ |
|
|
|
type __fn_type; \ |
|
|
|
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, __fn_type, [this](shared_ptr<MsgProcessContext> cxt) { \ |
|
|
|
json& params = cxt->params; \ |
|
|
|
fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ |
|
|
|
}); \ |
|
|
|
} |
|
|
|
#define REG_EXTFN_VOID(fn, type) \
|
|
|
|
{ \ |
|
|
|
type __fn_type; \ |
|
|
|
FrontMsgProcesser::ins().regProcesser(thisClass.className, #fn, {}, __fn_type, [this](shared_ptr<MsgProcessContext> cxt) { fn(cxt); }); \ |
|
|
|
} |
|
|
|
#endif
|