修改编译错误

This commit is contained in:
Tian jianyong 2024-12-20 16:01:09 +08:00
parent 6d697bcc2c
commit b65eb3e833
2 changed files with 29 additions and 20 deletions

View File

@ -6,35 +6,27 @@
class System; // 前向声明
// 1. 首先定义所有基础结构体
struct CoordinatePoint {
std::string point;
double latitude;
double longitude;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CoordinatePoint, point, latitude, longitude)
// 2. 定义 SystemConfig 类及其所有嵌套结构体
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;
friend class System;
// 嵌套结构体定义
struct Airport {
std::string name;
std::string iata;
std::string icao;
struct ReferencePoint {
double latitude;
double longitude;
} reference_point;
std::vector<CoordinatePoint> coordinate_points;
} airport;
@ -50,24 +42,26 @@ public:
} data_source;
struct WebSocket {
uint16_t port;
int max_connections;
int ping_interval_ms;
struct PositionUpdate {
int aircraft_interval_ms;
int vehicle_interval_ms;
int traffic_light_interval_ms;
} position_update;
uint16_t port;
int max_connections;
int ping_interval_ms;
} websocket;
struct CollisionDetection {
int update_interval_ms;
struct Prediction {
double time_window;
double vehicle_size;
double aircraft_size;
double min_unmanned_speed;
} prediction;
int update_interval_ms;
} collision_detection;
struct Logging {
@ -89,15 +83,31 @@ public:
int log_interval_ms;
} warning;
// 公共方法
static SystemConfig& instance() {
static SystemConfig instance;
return instance;
}
void load(const std::string& filename);
SystemConfig(const SystemConfig&) = delete;
SystemConfig& operator=(const SystemConfig&) = delete;
friend class System;
private:
SystemConfig() = default;
};
// 3. 最后定义所有 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE 宏
// 从最内层的结构开始定义
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CoordinatePoint, point, latitude, longitude)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport::ReferencePoint, latitude, longitude)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport, name, iata, icao, reference_point, coordinate_points)
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::Airport, name, iata, icao, reference_point, coordinate_points)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::WebSocket, port, max_connections, ping_interval_ms, position_update)
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)

View File

@ -3,7 +3,6 @@
#include "utils/Logger.h"
#include "config/SystemConfig.h"
#include <cmath>
#include <format>
#include <unordered_set>
CollisionDetector::CollisionDetector(const AirportBounds& bounds, const ControllableVehicles& controllableVehicles)