100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
#ifndef SMART_JSON_WRAPPER_H
|
|
#define SMART_JSON_WRAPPER_H
|
|
|
|
#include "function_metadata.h"
|
|
#include "math_utils.h"
|
|
#include <string>
|
|
#include <map>
|
|
#include <any>
|
|
#include <chrono>
|
|
#include <sstream>
|
|
#include <regex>
|
|
#include <cstring>
|
|
|
|
// JSON 响应结构
|
|
struct SmartResponse
|
|
{
|
|
bool success = true;
|
|
int code = 0;
|
|
std::string msg;
|
|
std::string req_code;
|
|
std::string req_cmd;
|
|
std::any res_data;
|
|
double execution_time = 0.0;
|
|
std::map<std::string, std::string> execution_info;
|
|
|
|
// 转换为 JSON 字符串
|
|
std::string toJson() const;
|
|
|
|
// 创建成功响应
|
|
static SmartResponse createSuccess(const std::string &req_code,
|
|
const std::string &req_cmd,
|
|
const std::any &data = {});
|
|
|
|
// 创建错误响应
|
|
static SmartResponse createError(const std::string &req_code,
|
|
const std::string &req_cmd,
|
|
int code,
|
|
const std::string &msg);
|
|
};
|
|
|
|
// 智能 JSON 处理器
|
|
class SmartJsonProcessor
|
|
{
|
|
private:
|
|
// 注册所有数学函数
|
|
void registerMathFunctions();
|
|
|
|
// 智能类型推断
|
|
std::any inferJsonValue(const std::string &key, const std::string &value_str);
|
|
|
|
// 解析数组
|
|
std::vector<int> parseIntArray(const std::string &array_str);
|
|
std::vector<float> parseFloatArray(const std::string &array_str);
|
|
|
|
// 字符串处理
|
|
static std::string trim(const std::string &str);
|
|
static std::vector<std::string> split(const std::string &str, char delimiter);
|
|
|
|
public:
|
|
SmartJsonProcessor();
|
|
~SmartJsonProcessor();
|
|
|
|
// JSON 解析
|
|
std::map<std::string, std::any> parseJsonParams(const std::string &json_str);
|
|
// 处理 JSON 请求
|
|
SmartResponse processRequest(const std::string &json_request);
|
|
|
|
// 获取函数列表
|
|
std::map<std::string, std::shared_ptr<FunctionInfo>> getAvailableFunctions() const;
|
|
|
|
// 获取函数信息
|
|
std::string getFunctionInfo(const std::string &func_name) const;
|
|
};
|
|
|
|
// WASM 导出函数
|
|
extern "C"
|
|
{
|
|
const char *init_func();
|
|
// 智能处理 JSON 请求
|
|
const char *func(const char *json_request);
|
|
// 智能处理 JSON 请求
|
|
const char *smart_process_json(const char *json_request);
|
|
|
|
// 获取可用函数列表
|
|
const char *smart_get_function_list();
|
|
|
|
// 获取函数详情
|
|
const char *smart_get_function_info(const char *func_name);
|
|
|
|
// 测试智能匹配
|
|
const char *smart_test_match(const char *json_request);
|
|
|
|
// 释放字符串
|
|
void smart_free_string(const char *str);
|
|
|
|
// 获取版本信息
|
|
const char *smart_get_version();
|
|
}
|
|
|
|
#endif // SMART_JSON_WRAPPER_H
|