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