删掉命名空间
This commit is contained in:
parent
348653807e
commit
8d5bf92bc6
@ -1,73 +1,23 @@
|
||||
#include "config/SystemConfig.h"
|
||||
#include "SystemConfig.h"
|
||||
#include "utils/Logger.h"
|
||||
#include <fstream>
|
||||
|
||||
namespace config {
|
||||
|
||||
void SystemConfig::load(const std::string& filename) {
|
||||
try {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Cannot open config file: " + filename);
|
||||
throw std::runtime_error("Failed to open config file: " + filename);
|
||||
}
|
||||
|
||||
|
||||
nlohmann::json j;
|
||||
file >> j;
|
||||
|
||||
// 加载机场信息
|
||||
airport.name = j["airport"]["name"];
|
||||
airport.iata = j["airport"]["iata"];
|
||||
airport.icao = j["airport"]["icao"];
|
||||
airport.reference_point.latitude = j["airport"]["reference_point"]["latitude"];
|
||||
airport.reference_point.longitude = j["airport"]["reference_point"]["longitude"];
|
||||
airport.coordinate_points = j["airport"]["coordinate_points"].get<std::vector<CoordinatePoint>>();
|
||||
|
||||
// 加载数据源配置
|
||||
data_source.host = j["data_source"]["host"];
|
||||
data_source.port = j["data_source"]["port"];
|
||||
data_source.aircraft_path = j["data_source"]["aircraft_path"];
|
||||
data_source.vehicle_path = j["data_source"]["vehicle_path"];
|
||||
data_source.traffic_light_path = j["data_source"]["traffic_light_path"];
|
||||
data_source.refresh_interval_ms = j["data_source"]["refresh_interval_ms"];
|
||||
data_source.timeout_ms = j["data_source"]["timeout_ms"];
|
||||
data_source.read_timeout_ms = j["data_source"]["read_timeout_ms"];
|
||||
|
||||
// 加载 WebSocket 配置
|
||||
websocket.port = j["websocket"]["port"];
|
||||
websocket.max_connections = j["websocket"]["max_connections"];
|
||||
websocket.ping_interval_ms = j["websocket"]["ping_interval_ms"];
|
||||
websocket.position_update.aircraft_interval_ms = j["websocket"]["position_update"]["aircraft_interval_ms"];
|
||||
websocket.position_update.vehicle_interval_ms = j["websocket"]["position_update"]["vehicle_interval_ms"];
|
||||
|
||||
// 加载碰撞检测配置
|
||||
collision_detection.update_interval_ms = j["collision_detection"]["update_interval_ms"];
|
||||
|
||||
// 加载碰撞预测配置
|
||||
collision_detection.prediction.time_window = j["collision_detection"]["prediction"]["time_window"];
|
||||
collision_detection.prediction.vehicle_size = j["collision_detection"]["prediction"]["vehicle_size"];
|
||||
collision_detection.prediction.aircraft_size = j["collision_detection"]["prediction"]["aircraft_size"];
|
||||
collision_detection.prediction.min_unmanned_speed = j["collision_detection"]["prediction"]["min_unmanned_speed"];
|
||||
|
||||
// 加载日志配置
|
||||
logging.level = j["logging"]["level"];
|
||||
logging.file = j["logging"]["file"];
|
||||
logging.max_size_mb = j["logging"]["max_size_mb"];
|
||||
logging.max_files = j["logging"]["max_files"];
|
||||
logging.console_output = j["logging"]["console_output"];
|
||||
|
||||
// 加载调试配置
|
||||
debug.enable_mock_data = j["debug"]["enable_mock_data"];
|
||||
debug.save_raw_data = j["debug"]["save_raw_data"];
|
||||
debug.profile_performance = j["debug"]["profile_performance"];
|
||||
|
||||
// 加载告警配置
|
||||
warning.warning_interval_ms = j["warning"]["warning_interval_ms"];
|
||||
warning.log_interval_ms = j["warning"]["log_interval_ms"];
|
||||
// 使用 nlohmann/json 的自动转换
|
||||
from_json(j, *this);
|
||||
|
||||
Logger::info("Loaded system configuration from ", filename);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Logger::error("Failed to load system config: ", e.what());
|
||||
throw;
|
||||
throw std::runtime_error("Failed to load config: " + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace config
|
||||
}
|
||||
@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class System; // 前向声明
|
||||
|
||||
namespace config {
|
||||
|
||||
struct CoordinatePoint {
|
||||
std::string point;
|
||||
double latitude;
|
||||
@ -15,20 +14,16 @@ struct CoordinatePoint {
|
||||
|
||||
class SystemConfig {
|
||||
public:
|
||||
// 获取单例实例
|
||||
static SystemConfig& instance() {
|
||||
static SystemConfig instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// 加载配置文件
|
||||
|
||||
void load(const std::string& filename);
|
||||
|
||||
// 删除拷贝构造和赋值操作
|
||||
|
||||
SystemConfig(const SystemConfig&) = delete;
|
||||
SystemConfig& operator=(const SystemConfig&) = delete;
|
||||
|
||||
// 允许 System 类访问构造函数
|
||||
|
||||
friend class System;
|
||||
|
||||
struct Airport {
|
||||
@ -39,8 +34,6 @@ public:
|
||||
double latitude;
|
||||
double longitude;
|
||||
} reference_point;
|
||||
|
||||
// 使用前向声明的坐标点结构体
|
||||
std::vector<CoordinatePoint> coordinate_points;
|
||||
} airport;
|
||||
|
||||
@ -72,7 +65,7 @@ public:
|
||||
double time_window;
|
||||
double vehicle_size;
|
||||
double aircraft_size;
|
||||
double min_unmanned_speed; // 无人车最低速度 (m/s)
|
||||
double min_unmanned_speed;
|
||||
} prediction;
|
||||
} collision_detection;
|
||||
|
||||
@ -91,14 +84,13 @@ public:
|
||||
} debug;
|
||||
|
||||
struct Warning {
|
||||
int warning_interval_ms; // 超时告警间隔
|
||||
int log_interval_ms; // 日志记录间隔
|
||||
int warning_interval_ms;
|
||||
int log_interval_ms;
|
||||
} warning;
|
||||
|
||||
private:
|
||||
// 移动构造函数到 private 区域
|
||||
SystemConfig() = default;
|
||||
};
|
||||
};
|
||||
|
||||
// JSON 序列化支持
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CoordinatePoint, point, latitude, longitude);
|
||||
@ -112,9 +104,4 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::CollisionDetection, update_inte
|
||||
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);
|
||||
|
||||
} // namespace config
|
||||
|
||||
using config::SystemConfig;
|
||||
using config::CoordinatePoint;
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig, airport, data_source, websocket, collision_detection, logging, debug, warning);
|
||||
Loading…
Reference in New Issue
Block a user