/** @file * @author Edouard DUPIN * @copyright 2016, Edouard DUPIN, all right reserved * @license APACHE v2.0 (see license file) */ #pragma once #include #include #include #include #include namespace jus { template ejson::Value executeCallJson(JUS_RETURN (*_func)(JUS_TYPES...), const ejson::Array& _params) { #if defined(__clang__) // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; return convertToJson(_func((convertJsonTo(_params[idParam++]))...)); #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) int32_t idParam = int32_t(sizeof...(JUS_TYPES))-1; return convertToJson(_func(convertJsonTo(_params[idParam--])...)); #else #error Must be implemented ... #endif return ejson::Null(); } template ejson::Value executeCallJson(void (*_func)(JUS_TYPES...), const ejson::Array& _params) { ejson::Object out; #if defined(__clang__) // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; _func((convertJsonTo(_params[idParam++]))...); #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) int32_t idParam = int32_t(sizeof...(JUS_TYPES))-1; _func(convertJsonTo(_params[idParam--])...); #else #error Must be implemented ... #endif return ejson::Null(); } template std::string executeCallString(JUS_RETURN (*_func)(JUS_TYPES...), const std::vector& _params) { #if defined(__clang__) // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; return etk::to_string(_func((convertStringTo(_params[idParam++]))...)); #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) int32_t idParam = int32_t(sizeof...(JUS_TYPES))-1; return etk::to_string(_func(convertStringTo(_params[idParam--])...)); #else #error Must be implemented ... #endif return ""; } template std::string executeCallString(void (*_func)(JUS_TYPES...), const std::vector& _params) { ejson::Object out; #if defined(__clang__) // clang generate a basic warning: // warning: multiple unsequenced modifications to 'idParam' [-Wunsequenced] int32_t idParam = 0; _func((convertStringTo(_params[idParam++]))...); #elif defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER) int32_t idParam = int32_t(sizeof...(JUS_TYPES))-1; _func(convertStringTo(_params[idParam--])...); #else #error Must be implemented ... #endif return ""; } template class AbstractFunctionTypeDirect: public jus::AbstractFunction { protected: static const ParamType m_returnType; static const ParamType m_paramType[sizeof...(JUS_TYPES)]; public: using functionType = JUS_RETURN (*)(JUS_TYPES...); functionType m_function; AbstractFunctionTypeDirect(const std::string& _name, const std::string& _desc, functionType _fptr): AbstractFunction(_name, _desc), m_function(_fptr) { } std::string getPrototype() const override { std::string ret; ret += m_returnType.getName(); ret += " "; ret += m_name; ret += "("; for (size_t iii=0; iii& _params, void* _class) override { std::string out; // check parameter number if (_params.size() != sizeof...(JUS_TYPES)) { JUS_ERROR("Wrong number of Parameters ..."); out += "error:WRONG-PARAMETER-NUMBER;"; out += "error-help:request "; out += etk::to_string(_params.size()); out += " parameters and need "; out += etk::to_string(sizeof...(JUS_TYPES)); out += " parameters. prototype function:"; out += getPrototype(); return out; } // check parameter compatibility for (size_t iii=0; iii const ParamType AbstractFunctionTypeDirect::m_returnType = createType(); template const ParamType AbstractFunctionTypeDirect::m_paramType[sizeof...(JUS_TYPES)] = {createType()...}; template AbstractFunction* createAbstractFunctionDirect(const std::string& _name, const std::string& _desc, JUS_RETURN (*_fffp)(JUS_TYPES...)) { return new AbstractFunctionTypeDirect(_name, _desc, _fffp); } }