/** @file * @author Edouard DUPIN * @copyright 2016, Edouard DUPIN, all right reserved * @license APACHE v2.0 (see license file) */ #include #include namespace jus { template<> bool convertJsonTo(const ejson::Value& _value) { return _value.toBoolean().get(); } template<> std::vector convertJsonTo>(const ejson::Value& _value) { std::vector out; for (const auto it : _value.toArray()) { out.push_back(convertJsonTo(it)); } return out; } template<> float convertJsonTo(const ejson::Value& _value) { return _value.toNumber().get(); } template<> double convertJsonTo(const ejson::Value& _value) { return _value.toNumber().get(); } template<> int64_t convertJsonTo(const ejson::Value& _value) { return int64_t(_value.toNumber().get()); } template<> int32_t convertJsonTo(const ejson::Value& _value) { return int32_t(_value.toNumber().get()); } template<> int16_t convertJsonTo(const ejson::Value& _value) { return int16_t(_value.toNumber().get()); } template<> int8_t convertJsonTo(const ejson::Value& _value) { return int8_t(_value.toNumber().get()); } template<> uint64_t convertJsonTo(const ejson::Value& _value) { return uint64_t(_value.toNumber().get()); } template<> uint32_t convertJsonTo(const ejson::Value& _value) { return uint32_t(_value.toNumber().get()); } template<> uint16_t convertJsonTo(const ejson::Value& _value) { return uint16_t(_value.toNumber().get()); } template<> uint8_t convertJsonTo(const ejson::Value& _value) { return uint8_t(_value.toNumber().get()); } template<> std::string convertJsonTo(const ejson::Value& _value) { return _value.toString().get(); } template<> std::vector convertJsonTo>(const ejson::Value& _value) { std::vector out; for (const auto it : _value.toArray()) { out.push_back(convertJsonTo(it)); } return out; } template<> ejson::Value convertToJson(const bool& _value) { return ejson::Boolean(_value); } template<> ejson::Value convertToJson>(const std::vector& _value) { ejson::Array out; for (const auto &it : _value) { out.add(ejson::Boolean(it)); } return out; } template<> ejson::Value convertToJson(const float& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const double& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const int64_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const int32_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const int16_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const int8_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const uint64_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const uint32_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const uint16_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const uint8_t& _value) { return ejson::Number(_value); } template<> ejson::Value convertToJson(const std::string& _value) { return ejson::String(_value); } template<> ejson::Value convertToJson>(const std::vector& _value) { ejson::Array out; for (auto &it : _value) { out.add(ejson::String(it)); } return out; } template<> ejson::Value convertToJson(const jus::FileServer& _value) { ejson::Array out; /* for (auto &it : _value) { out.add(ejson::String(it)); } */ return out; } template<> bool convertStringTo(const std::string& _value) { return etk::string_to_bool(_value); } template<> float convertStringTo(const std::string& _value) { return etk::string_to_float(_value); } template<> double convertStringTo(const std::string& _value) { return etk::string_to_double(_value); } template<> int64_t convertStringTo(const std::string& _value) { return etk::string_to_int64_t(_value); } template<> int32_t convertStringTo(const std::string& _value) { return etk::string_to_int32_t(_value); } template<> int16_t convertStringTo(const std::string& _value) { return etk::string_to_int16_t(_value); } template<> int8_t convertStringTo(const std::string& _value) { return etk::string_to_int8_t(_value); } template<> uint64_t convertStringTo(const std::string& _value) { return etk::string_to_uint64_t(_value); } template<> uint32_t convertStringTo(const std::string& _value) { return etk::string_to_uint32_t(_value); } template<> uint16_t convertStringTo(const std::string& _value) { return etk::string_to_uint16_t(_value); } template<> uint8_t convertStringTo(const std::string& _value) { return etk::string_to_uint8_t(_value); } template<> std::string convertStringTo(const std::string& _value) { return _value; } template<> std::vector convertStringTo>(const std::string& _value) { std::vector out; JUS_TODO("Convert string to vs"); return out; } template<> jus::FileServer convertStringTo(const std::string& _value) { return jus::FileServer(); } } ejson::Object jus::createCallJson(uint64_t _transactionId, const std::string& _functionName, ejson::Array _params) { ejson::Object callElem = createBaseCall(_transactionId, _functionName); callElem.add("param", _params); return callElem; } ejson::Object jus::createBaseCall(uint64_t _transactionId, const std::string& _functionName, const std::string& _service) { ejson::Object obj; if (_service.size() != 0) { obj.add("service", ejson::String(_service)); } obj.add("call", ejson::String(_functionName)); obj.add("id", ejson::Number(_transactionId)); return obj; } void jus::createParam(ejson::Object& _obj) { // Finish recursive parse ... } enum jus::AbstractFunction::type jus::AbstractFunction::getType() const { return m_type; } void jus::AbstractFunction::setType(enum jus::AbstractFunction::type _type) { m_type = _type; } const std::string& jus::AbstractFunction::getName() const { return m_name; } const std::string& jus::AbstractFunction::getDescription() const { return m_description; } void jus::AbstractFunction::setDescription(const std::string& _desc) { m_description = _desc; } void jus::AbstractFunction::setParam(int32_t _idParam, const std::string& _name, const std::string& _desc) { JUS_TODO("not implemented set param ... '" << _name << "'"); } void jus::AbstractFunction::addParam(const std::string& _name, const std::string& _desc) { m_paramsDescription.push_back(std::make_pair(_name, _desc)); } void jus::AbstractFunction::setReturn(const std::string& _desc) { m_returnDescription = _desc; } std::string jus::AbstractFunction::getPrototypeFull() const { std::string out = getPrototypeReturn(); out += " "; out += m_name; out += "("; std::vector tmp = getPrototypeParam(); for (size_t iii=0; iii() == _type) { return _params.isBoolean(); } if ( createType() == _type || createType() == _type || createType() == _type || createType() == _type || createType() == _type || createType() == _type || createType() == _type || createType() == _type || createType() == _type || createType() == _type) { return _params.isNumber(); } if (createType>() == _type) { return _params.isArray(); } if ( createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type || createType>() == _type) { if (_params.isObject()) { JUS_TODO("Special case of packaging of the data"); return false; } return _params.isArray(); } if (createType() == _type) { return _params.isString(); } return false; } bool jus::AbstractFunction::checkCompatibility(const ParamType& _type, const std::string& _params) { return false; }