From 8b0acb2f4375e9ce9405a6a14008801ce96e0092 Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Thu, 26 Oct 2023 16:41:36 +0200 Subject: [PATCH] engine: Replace boost::optional with std::optional --- engine/src/main_commands.hpp | 3 +- engine/src/simulation.cpp | 2 +- engine/src/simulation.hpp | 2 +- engine/src/stack.hpp | 50 ++++++++++++++-------------- engine/src/stack_factory.cpp | 2 +- engine/src/utility/command.hpp | 8 ++--- engine/src/utility/state_machine.hpp | 7 ++-- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/engine/src/main_commands.hpp b/engine/src/main_commands.hpp index e701055b4..f984eed6b 100644 --- a/engine/src/main_commands.hpp +++ b/engine/src/main_commands.hpp @@ -20,11 +20,10 @@ * \see main.cpp */ +#include #include #include -#include // for optional<> - #include "lua_setup.hpp" #include "stack_factory.hpp" diff --git a/engine/src/simulation.cpp b/engine/src/simulation.cpp index c82e00501..a8511026f 100644 --- a/engine/src/simulation.cpp +++ b/engine/src/simulation.cpp @@ -150,7 +150,7 @@ class SimulationMachine try { // Handle interrupts that have been inserted via push_interrupt. // Only one interrupt is stored. - boost::optional interrupt; + std::optional interrupt; while ((interrupt = pop_interrupt())) { id = handle_interrupt(id, *interrupt, ctx); } diff --git a/engine/src/simulation.hpp b/engine/src/simulation.hpp index 595304ef9..1399bb6f0 100644 --- a/engine/src/simulation.hpp +++ b/engine/src/simulation.hpp @@ -49,7 +49,7 @@ struct SimulationResult { cloe::Json signals; // dump of all signals in DataBroker right before the simulation started std::vector signals_autocompletion; // pseudo lua file used for vscode autocompletion - boost::optional output_dir; + std::optional output_dir; public: /** diff --git a/engine/src/stack.hpp b/engine/src/stack.hpp index fc73182bb..b8e918aa3 100644 --- a/engine/src/stack.hpp +++ b/engine/src/stack.hpp @@ -29,9 +29,9 @@ #include // for string #include // for move #include // for vector<> +#include // for optional<> #include // for path -#include // for optional<> #include // for Optional<> #include // for Path #include // for CustomDeserializer @@ -140,8 +140,8 @@ using IncludesSchema = schema::Vector; */ struct LoggingConf : public Confable { std::string name; - boost::optional pattern; - boost::optional level; + std::optional pattern; + std::optional level; public: // Special void apply() const; @@ -205,20 +205,20 @@ struct PluginConf : public PersistentConfable { boost::filesystem::path plugin_path{}; /** Name to give plugin if path is to a single file. */ - boost::optional plugin_name{}; + std::optional plugin_name{}; /** Prefix for plugin name(s). */ - boost::optional plugin_prefix{}; + std::optional plugin_prefix{}; /** Do not fail if path does not exist. */ - boost::optional ignore_missing{}; + std::optional ignore_missing{}; /** * Do not fail if path exists but plugin cannot be loaded. * This is especially useful if trying to load from several directories, * such as /usr/lib/cloe/plugins. */ - boost::optional ignore_failure{}; + std::optional ignore_failure{}; /** * If a plugin with the same name exists, replace it with this one. @@ -226,7 +226,7 @@ struct PluginConf : public PersistentConfable { * This is dependent on the order of plugin loading, which is determined by * the order of configuration files. */ - boost::optional allow_clobber{}; + std::optional allow_clobber{}; public: // Constructors PluginConf() = default; @@ -309,14 +309,14 @@ struct EngineConf : public Confable { bool triggers_ignore_source{false}; // Output: - boost::optional registry_path{CLOE_DATA_HOME "/registry"}; - boost::optional output_path{"${CLOE_SIMULATION_UUID}"}; - boost::optional output_file_config{"config.json"}; - boost::optional output_file_result{"result.json"}; - boost::optional output_file_triggers{"triggers.json"}; - boost::optional output_file_signals{"signals.json"}; - boost::optional output_file_signals_autocompletion; - boost::optional output_file_data_stream; + std::optional registry_path{CLOE_DATA_HOME "/registry"}; + std::optional output_path{"${CLOE_SIMULATION_UUID}"}; + std::optional output_file_config{"config.json"}; + std::optional output_file_result{"result.json"}; + std::optional output_file_triggers{"triggers.json"}; + std::optional output_file_signals{"signals.json"}; + std::optional output_file_signals_autocompletion; + std::optional output_file_data_stream; bool output_clobber_files{true}; /** @@ -371,7 +371,7 @@ struct EngineConf : public Confable { * The states with an asterisk are given defaults that are not affected by * the default timeout as these typically take longer due to I/O operations. */ - std::map> watchdog_state_timeouts{ + std::map> watchdog_state_timeouts{ {"CONNECT", std::chrono::milliseconds{300'000}}, {"ABORT", std::chrono::milliseconds{90'000}}, {"STOP", std::chrono::milliseconds{300'000}}, @@ -453,8 +453,8 @@ using EngineSchema = schema_type::type; * good idea! */ struct DefaultConf : public Confable { - boost::optional name; - boost::optional binding; + std::optional name; + std::optional binding; Conf args; public: // Confable Overrides @@ -495,7 +495,7 @@ class FactoryPlugin : public fable::schema::FactoryPointerless { */ struct SimulatorConf : public Confable { const std::string binding; - boost::optional name; + std::optional name; std::shared_ptr factory; Conf args; @@ -529,7 +529,7 @@ class SimulatorSchema : public FactoryPlugin { */ struct ControllerConf : public Confable { const std::string binding; - boost::optional name; + std::optional name; std::string vehicle; std::shared_ptr factory; Conf args; @@ -615,7 +615,7 @@ struct FromSimulator : public Confable { struct ComponentConf : public Confable { const std::string binding; - boost::optional name; + std::optional name; std::vector from; std::shared_ptr factory; Conf args; @@ -780,7 +780,7 @@ class VehicleSchema : public fable::schema::Base { // --------------------------------------------------------------------------------------------- // struct TriggerConf : public PersistentConfable { - boost::optional label{boost::none}; + std::optional label{}; Source source{Source::FILESYSTEM}; Conf action{}; Conf event{}; @@ -823,7 +823,7 @@ struct SimulationConf : public Confable { /** * Optional namespace for simulation events and actions. */ - boost::optional name{boost::none}; + std::optional name{}; /** * Nominal model time step. @@ -887,7 +887,7 @@ using ConfReader = std::function; class Stack : public Confable { private: // Constants (1) std::vector reserved_ids_; - boost::optional schema_ref_; + std::optional schema_ref_; public: // Configuration (13) std::string version; diff --git a/engine/src/stack_factory.cpp b/engine/src/stack_factory.cpp index 6d5af1c39..a13ee1c31 100644 --- a/engine/src/stack_factory.cpp +++ b/engine/src/stack_factory.cpp @@ -106,7 +106,7 @@ Stack new_stack(const StackOptions& opt) { // Interpolate known variables, if requested. if (opt.interpolate_vars) { - auto interpolate_path = [&opt](boost::optional& p) { + auto interpolate_path = [&opt](std::optional& p) { p = fable::interpolate_vars(p->native(), opt.environment.get()); }; interpolate_path(s.engine.registry_path); diff --git a/engine/src/utility/command.hpp b/engine/src/utility/command.hpp index 41789aca4..dde4bddbd 100644 --- a/engine/src/utility/command.hpp +++ b/engine/src/utility/command.hpp @@ -24,11 +24,11 @@ #pragma once +#include // for optional<> #include // for string #include // for system_error #include // for vector<> -#include // for optional<> #include // for child #include // for Logger, Json, Conf, ... #include // for Action, ActionFactory, ... @@ -39,9 +39,9 @@ namespace engine { struct CommandResult { std::string name; std::string command; - boost::optional child; - boost::optional exit_code; - boost::optional error; + std::optional child; + std::optional exit_code; + std::optional error; std::vector output; }; diff --git a/engine/src/utility/state_machine.hpp b/engine/src/utility/state_machine.hpp index c33b45fab..c59c68159 100644 --- a/engine/src/utility/state_machine.hpp +++ b/engine/src/utility/state_machine.hpp @@ -26,10 +26,9 @@ #include // for map<> #include // for shared_ptr<> #include // for mutex, lock_guard<> +#include // for optional<> #include // for move -#include // for optional<> - #include // for Json #include // for Accumulator #include // for DurationTimer<> @@ -195,10 +194,10 @@ class StateMachine { interrupt_ = id; } - boost::optional pop_interrupt() { + std::optional pop_interrupt() { std::lock_guard guard(interrupt_mtx_); if (interrupt_ == nullptr) { - return boost::none; + return std::nullopt; } else { auto tmp = interrupt_; interrupt_ = nullptr;