diff --git a/src/config/SystemConfig.cpp b/src/config/SystemConfig.cpp index b6151a1..3a2e951 100644 --- a/src/config/SystemConfig.cpp +++ b/src/config/SystemConfig.cpp @@ -11,9 +11,7 @@ void SystemConfig::load(const std::string& filename) { nlohmann::json j; file >> j; - - // 使用 nlohmann/json 的自动转换 - from_json(j, *this); + nlohmann::from_json(j, *this); Logger::info("Loaded system configuration from ", filename); } diff --git a/src/config/SystemConfig.h b/src/config/SystemConfig.h index 78e48fe..ce5bdd9 100644 --- a/src/config/SystemConfig.h +++ b/src/config/SystemConfig.h @@ -6,17 +6,11 @@ class System; // 前向声明 -// 前向声明所有结构体 -struct CoordinatePoint; -class SystemConfig; - -// 定义结构体 struct CoordinatePoint { std::string point; double latitude; double longitude; }; -// 为 CoordinatePoint 定义序列化 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CoordinatePoint, point, latitude, longitude) class SystemConfig { @@ -99,19 +93,14 @@ private: SystemConfig() = default; }; -// 为嵌套结构体定义序列化 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport::ReferencePoint, latitude, longitude) -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::WebSocket::PositionUpdate, aircraft_interval_ms, vehicle_interval_ms, traffic_light_interval_ms) -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::CollisionDetection::Prediction, time_window, vehicle_size, aircraft_size, min_unmanned_speed) - -// 为主要结构体定义序列化 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport, name, iata, icao, reference_point, coordinate_points) -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::DataSource, host, port, aircraft_path, vehicle_path, traffic_light_path, refresh_interval_ms, timeout_ms, read_timeout_ms) +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::WebSocket::PositionUpdate, aircraft_interval_ms, vehicle_interval_ms, traffic_light_interval_ms) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::WebSocket, port, max_connections, ping_interval_ms, position_update) +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::CollisionDetection::Prediction, time_window, vehicle_size, aircraft_size, min_unmanned_speed) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::CollisionDetection, update_interval_ms, prediction) +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::DataSource, host, port, aircraft_path, vehicle_path, traffic_light_path, refresh_interval_ms, timeout_ms, read_timeout_ms) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Logging, level, file, max_size_mb, max_files, console_output) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Debug, enable_mock_data, save_raw_data, profile_performance) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Warning, warning_interval_ms, log_interval_ms) - -// 最后定义主类的序列化 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig, airport, data_source, websocket, collision_detection, logging, debug, warning) \ No newline at end of file