From a7166a5da3a2b57b7f5972743df57c6ef3e6dcf1 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 20 May 2016 21:55:10 +0200 Subject: [PATCH] [DEV] remove vector of class ==> faster --- jus/Service.h | 100 ++++++++++++++++++++++++++++++++------------------ lutin_jus.py | 2 + 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/jus/Service.h b/jus/Service.h index b194039..9ef93e8 100644 --- a/jus/Service.h +++ b/jus/Service.h @@ -51,39 +51,18 @@ class CmdBase { const std::string& getDescription() const { return m_description; } - protected: - ParamType m_returnType; - std::vector m_listParamType; protected: CmdBase(const std::string& _name, - const std::string& _desc, - const ParamType& _retType, - const std::vector& _params): + const std::string& _desc): m_name(_name), - m_description(_desc), - m_returnType(_retType), - m_listParamType(_params) { + m_description(_desc) { } public: virtual ~CmdBase() {}; //virtual bool checkArguments(const std::vector& _params) = 0; public: - std::string getPrototype() const { - std::string ret; - ret += m_returnType.getName(); - ret += " "; - ret += m_name; - ret += "("; - for (size_t iii=0; iii class TypeList: public CmdBase { + protected: + static const ParamType m_returnType; + static const ParamType m_paramType[sizeof...(JUS_TYPES)]; + static const int32_t m_paramCount; public: using functionType = JUS_RETURN (*)(JUS_TYPES...); functionType m_function; TypeList(const std::string& _name, const std::string& _desc, functionType _fptr): - CmdBase(_name, _desc, createType(), {createType()...}), - //m_sizeParam(sizeof...(JUS_TYPES)), + CmdBase(_name, _desc), m_function(_fptr) { - } - ejson::Value execute(const ejson::Array& _params) { + std::string getPrototype() const override { + std::string ret; + ret += m_returnType.getName(); + ret += " "; + ret += m_name; + ret += "("; + for (size_t iii=0; iii(_params[idParam++])...)); #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) - int32_t idParam = m_listParamType.size()-1; + int32_t idParam = m_paramCount-1; ejson::Value retVal = convertToJson(m_function(convertJsonTo(_params[idParam--])...)); #else #error Must be implemented ... @@ -135,27 +131,54 @@ class TypeList: public CmdBase { return out; } }; + +template +const ParamType TypeList::m_returnType = createType(); + +template +const ParamType TypeList::m_paramType[sizeof...(JUS_TYPES)] = {createType()...}; + +template +const int32_t TypeList::m_paramCount = sizeof...(JUS_TYPES); + // Void special case: template class TypeListVoid: public CmdBase { + protected: + static const ParamType m_paramType[sizeof...(JUS_TYPES)]; + static const int32_t m_paramCount; public: using functionType = void (*)(JUS_TYPES...); functionType m_function; TypeListVoid(const std::string& _name, const std::string& _desc, functionType _fptr): - CmdBase(_name, _desc, createType(), {createType()...}), - //m_sizeParam(sizeof...(JUS_TYPES)), + CmdBase(_name, _desc), m_function(_fptr) { } + std::string getPrototype() const override { + std::string ret; + ret += createType().getName(); + ret += " "; + ret += m_name; + ret += "("; + for (size_t iii=0; iii +const ParamType TypeListVoid::m_paramType[sizeof...(JUS_TYPES)] = {createType()...}; + +template +const int32_t TypeListVoid::m_paramCount = sizeof...(JUS_TYPES); + + template CmdBase* createCmd(const std::string& _name, const std::string& _desc, JUS_RETURN (*_fffp)(JUS_TYPES...)) { diff --git a/lutin_jus.py b/lutin_jus.py index b8ca27a..66ed00b 100644 --- a/lutin_jus.py +++ b/lutin_jus.py @@ -48,6 +48,8 @@ def create(target, module_name): 'jus/Service.h', 'jus/TcpString.h', ]) + if target.config["compilator"] == "clang": + my_module.add_export_flag('c++', "-Wno-unsequenced") # build in C++ mode my_module.compile_version("c++", 2011) return my_module