Skip to content

Commit

Permalink
engine: Replace boost::optional with std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Jul 5, 2024
1 parent 34fcf16 commit 8b0acb2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 38 deletions.
3 changes: 1 addition & 2 deletions engine/src/main_commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
* \see main.cpp
*/

#include <optional>
#include <string>
#include <vector>

#include <boost/optional.hpp> // for optional<>

#include "lua_setup.hpp"
#include "stack_factory.hpp"

Expand Down
2 changes: 1 addition & 1 deletion engine/src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SimulationMachine
try {
// Handle interrupts that have been inserted via push_interrupt.
// Only one interrupt is stored.
boost::optional<StateId> interrupt;
std::optional<StateId> interrupt;
while ((interrupt = pop_interrupt())) {
id = handle_interrupt(id, *interrupt, ctx);
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct SimulationResult {
cloe::Json signals; // dump of all signals in DataBroker right before the simulation started
std::vector<std::string>
signals_autocompletion; // pseudo lua file used for vscode autocompletion
boost::optional<boost::filesystem::path> output_dir;
std::optional<boost::filesystem::path> output_dir;

public:
/**
Expand Down
50 changes: 25 additions & 25 deletions engine/src/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include <string> // for string
#include <utility> // for move
#include <vector> // for vector<>
#include <optional> // for optional<>

#include <boost/filesystem/path.hpp> // for path
#include <boost/optional.hpp> // for optional<>
#include <fable/schema/boost_optional.hpp> // for Optional<>
#include <fable/schema/boost_path.hpp> // for Path
#include <fable/schema/custom.hpp> // for CustomDeserializer
Expand Down Expand Up @@ -140,8 +140,8 @@ using IncludesSchema = schema::Vector<IncludeConf, IncludeSchema>;
*/
struct LoggingConf : public Confable {
std::string name;
boost::optional<std::string> pattern;
boost::optional<LogLevel> level;
std::optional<std::string> pattern;
std::optional<LogLevel> level;

public: // Special
void apply() const;
Expand Down Expand Up @@ -205,28 +205,28 @@ struct PluginConf : public PersistentConfable {
boost::filesystem::path plugin_path{};

/** Name to give plugin if path is to a single file. */
boost::optional<std::string> plugin_name{};
std::optional<std::string> plugin_name{};

/** Prefix for plugin name(s). */
boost::optional<std::string> plugin_prefix{};
std::optional<std::string> plugin_prefix{};

/** Do not fail if path does not exist. */
boost::optional<bool> ignore_missing{};
std::optional<bool> 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<bool> ignore_failure{};
std::optional<bool> ignore_failure{};

/**
* If a plugin with the same name exists, replace it with this one.
*
* This is dependent on the order of plugin loading, which is determined by
* the order of configuration files.
*/
boost::optional<bool> allow_clobber{};
std::optional<bool> allow_clobber{};

public: // Constructors
PluginConf() = default;
Expand Down Expand Up @@ -309,14 +309,14 @@ struct EngineConf : public Confable {
bool triggers_ignore_source{false};

// Output:
boost::optional<boost::filesystem::path> registry_path{CLOE_DATA_HOME "/registry"};
boost::optional<boost::filesystem::path> output_path{"${CLOE_SIMULATION_UUID}"};
boost::optional<boost::filesystem::path> output_file_config{"config.json"};
boost::optional<boost::filesystem::path> output_file_result{"result.json"};
boost::optional<boost::filesystem::path> output_file_triggers{"triggers.json"};
boost::optional<boost::filesystem::path> output_file_signals{"signals.json"};
boost::optional<boost::filesystem::path> output_file_signals_autocompletion;
boost::optional<boost::filesystem::path> output_file_data_stream;
std::optional<boost::filesystem::path> registry_path{CLOE_DATA_HOME "/registry"};
std::optional<boost::filesystem::path> output_path{"${CLOE_SIMULATION_UUID}"};
std::optional<boost::filesystem::path> output_file_config{"config.json"};
std::optional<boost::filesystem::path> output_file_result{"result.json"};
std::optional<boost::filesystem::path> output_file_triggers{"triggers.json"};
std::optional<boost::filesystem::path> output_file_signals{"signals.json"};
std::optional<boost::filesystem::path> output_file_signals_autocompletion;
std::optional<boost::filesystem::path> output_file_data_stream;
bool output_clobber_files{true};

/**
Expand Down Expand Up @@ -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<std::string, boost::optional<std::chrono::milliseconds>> watchdog_state_timeouts{
std::map<std::string, std::optional<std::chrono::milliseconds>> watchdog_state_timeouts{
{"CONNECT", std::chrono::milliseconds{300'000}},
{"ABORT", std::chrono::milliseconds{90'000}},
{"STOP", std::chrono::milliseconds{300'000}},
Expand Down Expand Up @@ -453,8 +453,8 @@ using EngineSchema = schema_type<EngineConf>::type;
* good idea!
*/
struct DefaultConf : public Confable {
boost::optional<std::string> name;
boost::optional<std::string> binding;
std::optional<std::string> name;
std::optional<std::string> binding;
Conf args;

public: // Confable Overrides
Expand Down Expand Up @@ -495,7 +495,7 @@ class FactoryPlugin : public fable::schema::FactoryPointerless<C> {
*/
struct SimulatorConf : public Confable {
const std::string binding;
boost::optional<std::string> name;
std::optional<std::string> name;
std::shared_ptr<SimulatorFactory> factory;
Conf args;

Expand Down Expand Up @@ -529,7 +529,7 @@ class SimulatorSchema : public FactoryPlugin<SimulatorConf, SimulatorFactory> {
*/
struct ControllerConf : public Confable {
const std::string binding;
boost::optional<std::string> name;
std::optional<std::string> name;
std::string vehicle;
std::shared_ptr<ControllerFactory> factory;
Conf args;
Expand Down Expand Up @@ -615,7 +615,7 @@ struct FromSimulator : public Confable {

struct ComponentConf : public Confable {
const std::string binding;
boost::optional<std::string> name;
std::optional<std::string> name;
std::vector<std::string> from;
std::shared_ptr<ComponentFactory> factory;
Conf args;
Expand Down Expand Up @@ -780,7 +780,7 @@ class VehicleSchema : public fable::schema::Base<VehicleSchema> {
// --------------------------------------------------------------------------------------------- //

struct TriggerConf : public PersistentConfable {
boost::optional<std::string> label{boost::none};
std::optional<std::string> label{};
Source source{Source::FILESYSTEM};
Conf action{};
Conf event{};
Expand Down Expand Up @@ -823,7 +823,7 @@ struct SimulationConf : public Confable {
/**
* Optional namespace for simulation events and actions.
*/
boost::optional<std::string> name{boost::none};
std::optional<std::string> name{};

/**
* Nominal model time step.
Expand Down Expand Up @@ -887,7 +887,7 @@ using ConfReader = std::function<Conf(const std::string&)>;
class Stack : public Confable {
private: // Constants (1)
std::vector<std::string> reserved_ids_;
boost::optional<std::string> schema_ref_;
std::optional<std::string> schema_ref_;

public: // Configuration (13)
std::string version;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/stack_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<boost::filesystem::path>& p) {
auto interpolate_path = [&opt](std::optional<boost::filesystem::path>& p) {
p = fable::interpolate_vars(p->native(), opt.environment.get());
};
interpolate_path(s.engine.registry_path);
Expand Down
8 changes: 4 additions & 4 deletions engine/src/utility/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

#pragma once

#include <optional> // for optional<>
#include <string> // for string
#include <system_error> // for system_error
#include <vector> // for vector<>

#include <boost/optional.hpp> // for optional<>
#include <boost/process/child.hpp> // for child
#include <cloe/core.hpp> // for Logger, Json, Conf, ...
#include <cloe/trigger.hpp> // for Action, ActionFactory, ...
Expand All @@ -39,9 +39,9 @@ namespace engine {
struct CommandResult {
std::string name;
std::string command;
boost::optional<boost::process::child> child;
boost::optional<int> exit_code;
boost::optional<std::runtime_error> error;
std::optional<boost::process::child> child;
std::optional<int> exit_code;
std::optional<std::runtime_error> error;
std::vector<std::string> output;
};

Expand Down
7 changes: 3 additions & 4 deletions engine/src/utility/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
#include <map> // for map<>
#include <memory> // for shared_ptr<>
#include <mutex> // for mutex, lock_guard<>
#include <optional> // for optional<>
#include <utility> // for move

#include <boost/optional.hpp> // for optional<>

#include <cloe/core.hpp> // for Json
#include <cloe/utility/statistics.hpp> // for Accumulator
#include <cloe/utility/timer.hpp> // for DurationTimer<>
Expand Down Expand Up @@ -195,10 +194,10 @@ class StateMachine {
interrupt_ = id;
}

boost::optional<StateId> pop_interrupt() {
std::optional<StateId> pop_interrupt() {
std::lock_guard<std::mutex> guard(interrupt_mtx_);
if (interrupt_ == nullptr) {
return boost::none;
return std::nullopt;
} else {
auto tmp = interrupt_;
interrupt_ = nullptr;
Expand Down

0 comments on commit 8b0acb2

Please sign in to comment.