diff --git a/include/MantleAPI/Execution/scenario_info.h b/include/MantleAPI/Execution/scenario_info.h index 13a1038f6ece740d8e70ad8eb33ea2dbc7125767..92e9aafd557510eb64d633129261c28f68861308 100644 --- a/include/MantleAPI/Execution/scenario_info.h +++ b/include/MantleAPI/Execution/scenario_info.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021-2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021-2024, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -18,6 +18,7 @@ #include <MantleAPI/Common/time_utils.h> #include <map> +#include <memory> #include <string> namespace mantle_api @@ -25,6 +26,47 @@ namespace mantle_api /// Information about the scenario struct ScenarioInfo { + /// Default constructor to avoid nullptr for map details + ScenarioInfo() = default; + + /// Copy constructor + /// @param other scenario info to copy + ScenarioInfo(const ScenarioInfo& other) + : scenario_timeout_duration{other.scenario_timeout_duration}, + description{other.description}, + full_map_path{other.full_map_path}, + map_details{other.map_details->Clone()}, + additional_information{other.additional_information} + { + } + + /// Move constructor + /// @param other scenario info to move + ScenarioInfo(ScenarioInfo&& other) noexcept = default; + + /// Copy assignment operator + /// @param other scenario info to copy assign + /// @return copied ScenarioInfo + ScenarioInfo& operator=(const ScenarioInfo& other) + { + if (this != &other) + { + scenario_timeout_duration = other.scenario_timeout_duration; + description = other.description; + full_map_path = other.full_map_path; + map_details = other.map_details->Clone(); + additional_information = other.additional_information; + } + return *this; + } + + /// Move assignment operator + /// @param other scenario info to move assign + /// @return moved ScenarioInfo + ScenarioInfo& operator=(ScenarioInfo&& other) noexcept = default; + + ~ScenarioInfo() = default; + /// Duration of the scenario timeout Time scenario_timeout_duration; /// Specific description of the scenario @@ -32,7 +74,7 @@ struct ScenarioInfo /// Absolute path to the map std::string full_map_path; /// Definition of the map area - MapDetails map_details; + std::unique_ptr<MapDetails> map_details{std::make_unique<MapDetails>()}; /// Additional custom information about the scenario std::map<std::string, std::string> additional_information; }; diff --git a/include/MantleAPI/Map/map_details.h b/include/MantleAPI/Map/map_details.h index afb5235ef69e75059a5f866a02f83b04b9f5654c..0d7ad9696b6583292b60978b534f1c4f07e375b8 100644 --- a/include/MantleAPI/Map/map_details.h +++ b/include/MantleAPI/Map/map_details.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021-2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021-2024, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -17,6 +17,7 @@ #include <MantleAPI/Common/position.h> +#include <memory> #include <vector> namespace mantle_api @@ -26,6 +27,13 @@ struct MapDetails { virtual ~MapDetails() = default; + /// Cloning MapDetails for usage as unique ptr in ScenarioInfo. Can be overwritten in derived classes. + /// @return Copy of MapDetails + virtual std::unique_ptr<MapDetails> Clone() const + { + return std::make_unique<MapDetails>(*this); + } + /// Area of the map (e.g. GPS latitude, GPS longitude) std::vector<Position> map_region; };