Skip to content

Commit 8b0acb2

Browse files
committed
engine: Replace boost::optional with std::optional
1 parent 34fcf16 commit 8b0acb2

File tree

7 files changed

+36
-38
lines changed

7 files changed

+36
-38
lines changed

engine/src/main_commands.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
* \see main.cpp
2121
*/
2222

23+
#include <optional>
2324
#include <string>
2425
#include <vector>
2526

26-
#include <boost/optional.hpp> // for optional<>
27-
2827
#include "lua_setup.hpp"
2928
#include "stack_factory.hpp"
3029

engine/src/simulation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class SimulationMachine
150150
try {
151151
// Handle interrupts that have been inserted via push_interrupt.
152152
// Only one interrupt is stored.
153-
boost::optional<StateId> interrupt;
153+
std::optional<StateId> interrupt;
154154
while ((interrupt = pop_interrupt())) {
155155
id = handle_interrupt(id, *interrupt, ctx);
156156
}

engine/src/simulation.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct SimulationResult {
4949
cloe::Json signals; // dump of all signals in DataBroker right before the simulation started
5050
std::vector<std::string>
5151
signals_autocompletion; // pseudo lua file used for vscode autocompletion
52-
boost::optional<boost::filesystem::path> output_dir;
52+
std::optional<boost::filesystem::path> output_dir;
5353

5454
public:
5555
/**

engine/src/stack.hpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include <string> // for string
3030
#include <utility> // for move
3131
#include <vector> // for vector<>
32+
#include <optional> // for optional<>
3233

3334
#include <boost/filesystem/path.hpp> // for path
34-
#include <boost/optional.hpp> // for optional<>
3535
#include <fable/schema/boost_optional.hpp> // for Optional<>
3636
#include <fable/schema/boost_path.hpp> // for Path
3737
#include <fable/schema/custom.hpp> // for CustomDeserializer
@@ -140,8 +140,8 @@ using IncludesSchema = schema::Vector<IncludeConf, IncludeSchema>;
140140
*/
141141
struct LoggingConf : public Confable {
142142
std::string name;
143-
boost::optional<std::string> pattern;
144-
boost::optional<LogLevel> level;
143+
std::optional<std::string> pattern;
144+
std::optional<LogLevel> level;
145145

146146
public: // Special
147147
void apply() const;
@@ -205,28 +205,28 @@ struct PluginConf : public PersistentConfable {
205205
boost::filesystem::path plugin_path{};
206206

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

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

213213
/** Do not fail if path does not exist. */
214-
boost::optional<bool> ignore_missing{};
214+
std::optional<bool> ignore_missing{};
215215

216216
/**
217217
* Do not fail if path exists but plugin cannot be loaded.
218218
* This is especially useful if trying to load from several directories,
219219
* such as /usr/lib/cloe/plugins.
220220
*/
221-
boost::optional<bool> ignore_failure{};
221+
std::optional<bool> ignore_failure{};
222222

223223
/**
224224
* If a plugin with the same name exists, replace it with this one.
225225
*
226226
* This is dependent on the order of plugin loading, which is determined by
227227
* the order of configuration files.
228228
*/
229-
boost::optional<bool> allow_clobber{};
229+
std::optional<bool> allow_clobber{};
230230

231231
public: // Constructors
232232
PluginConf() = default;
@@ -309,14 +309,14 @@ struct EngineConf : public Confable {
309309
bool triggers_ignore_source{false};
310310

311311
// Output:
312-
boost::optional<boost::filesystem::path> registry_path{CLOE_DATA_HOME "/registry"};
313-
boost::optional<boost::filesystem::path> output_path{"${CLOE_SIMULATION_UUID}"};
314-
boost::optional<boost::filesystem::path> output_file_config{"config.json"};
315-
boost::optional<boost::filesystem::path> output_file_result{"result.json"};
316-
boost::optional<boost::filesystem::path> output_file_triggers{"triggers.json"};
317-
boost::optional<boost::filesystem::path> output_file_signals{"signals.json"};
318-
boost::optional<boost::filesystem::path> output_file_signals_autocompletion;
319-
boost::optional<boost::filesystem::path> output_file_data_stream;
312+
std::optional<boost::filesystem::path> registry_path{CLOE_DATA_HOME "/registry"};
313+
std::optional<boost::filesystem::path> output_path{"${CLOE_SIMULATION_UUID}"};
314+
std::optional<boost::filesystem::path> output_file_config{"config.json"};
315+
std::optional<boost::filesystem::path> output_file_result{"result.json"};
316+
std::optional<boost::filesystem::path> output_file_triggers{"triggers.json"};
317+
std::optional<boost::filesystem::path> output_file_signals{"signals.json"};
318+
std::optional<boost::filesystem::path> output_file_signals_autocompletion;
319+
std::optional<boost::filesystem::path> output_file_data_stream;
320320
bool output_clobber_files{true};
321321

322322
/**
@@ -371,7 +371,7 @@ struct EngineConf : public Confable {
371371
* The states with an asterisk are given defaults that are not affected by
372372
* the default timeout as these typically take longer due to I/O operations.
373373
*/
374-
std::map<std::string, boost::optional<std::chrono::milliseconds>> watchdog_state_timeouts{
374+
std::map<std::string, std::optional<std::chrono::milliseconds>> watchdog_state_timeouts{
375375
{"CONNECT", std::chrono::milliseconds{300'000}},
376376
{"ABORT", std::chrono::milliseconds{90'000}},
377377
{"STOP", std::chrono::milliseconds{300'000}},
@@ -453,8 +453,8 @@ using EngineSchema = schema_type<EngineConf>::type;
453453
* good idea!
454454
*/
455455
struct DefaultConf : public Confable {
456-
boost::optional<std::string> name;
457-
boost::optional<std::string> binding;
456+
std::optional<std::string> name;
457+
std::optional<std::string> binding;
458458
Conf args;
459459

460460
public: // Confable Overrides
@@ -495,7 +495,7 @@ class FactoryPlugin : public fable::schema::FactoryPointerless<C> {
495495
*/
496496
struct SimulatorConf : public Confable {
497497
const std::string binding;
498-
boost::optional<std::string> name;
498+
std::optional<std::string> name;
499499
std::shared_ptr<SimulatorFactory> factory;
500500
Conf args;
501501

@@ -529,7 +529,7 @@ class SimulatorSchema : public FactoryPlugin<SimulatorConf, SimulatorFactory> {
529529
*/
530530
struct ControllerConf : public Confable {
531531
const std::string binding;
532-
boost::optional<std::string> name;
532+
std::optional<std::string> name;
533533
std::string vehicle;
534534
std::shared_ptr<ControllerFactory> factory;
535535
Conf args;
@@ -615,7 +615,7 @@ struct FromSimulator : public Confable {
615615

616616
struct ComponentConf : public Confable {
617617
const std::string binding;
618-
boost::optional<std::string> name;
618+
std::optional<std::string> name;
619619
std::vector<std::string> from;
620620
std::shared_ptr<ComponentFactory> factory;
621621
Conf args;
@@ -780,7 +780,7 @@ class VehicleSchema : public fable::schema::Base<VehicleSchema> {
780780
// --------------------------------------------------------------------------------------------- //
781781

782782
struct TriggerConf : public PersistentConfable {
783-
boost::optional<std::string> label{boost::none};
783+
std::optional<std::string> label{};
784784
Source source{Source::FILESYSTEM};
785785
Conf action{};
786786
Conf event{};
@@ -823,7 +823,7 @@ struct SimulationConf : public Confable {
823823
/**
824824
* Optional namespace for simulation events and actions.
825825
*/
826-
boost::optional<std::string> name{boost::none};
826+
std::optional<std::string> name{};
827827

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

892892
public: // Configuration (13)
893893
std::string version;

engine/src/stack_factory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Stack new_stack(const StackOptions& opt) {
106106

107107
// Interpolate known variables, if requested.
108108
if (opt.interpolate_vars) {
109-
auto interpolate_path = [&opt](boost::optional<boost::filesystem::path>& p) {
109+
auto interpolate_path = [&opt](std::optional<boost::filesystem::path>& p) {
110110
p = fable::interpolate_vars(p->native(), opt.environment.get());
111111
};
112112
interpolate_path(s.engine.registry_path);

engine/src/utility/command.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525
#pragma once
2626

27+
#include <optional> // for optional<>
2728
#include <string> // for string
2829
#include <system_error> // for system_error
2930
#include <vector> // for vector<>
3031

31-
#include <boost/optional.hpp> // for optional<>
3232
#include <boost/process/child.hpp> // for child
3333
#include <cloe/core.hpp> // for Logger, Json, Conf, ...
3434
#include <cloe/trigger.hpp> // for Action, ActionFactory, ...
@@ -39,9 +39,9 @@ namespace engine {
3939
struct CommandResult {
4040
std::string name;
4141
std::string command;
42-
boost::optional<boost::process::child> child;
43-
boost::optional<int> exit_code;
44-
boost::optional<std::runtime_error> error;
42+
std::optional<boost::process::child> child;
43+
std::optional<int> exit_code;
44+
std::optional<std::runtime_error> error;
4545
std::vector<std::string> output;
4646
};
4747

engine/src/utility/state_machine.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
#include <map> // for map<>
2727
#include <memory> // for shared_ptr<>
2828
#include <mutex> // for mutex, lock_guard<>
29+
#include <optional> // for optional<>
2930
#include <utility> // for move
3031

31-
#include <boost/optional.hpp> // for optional<>
32-
3332
#include <cloe/core.hpp> // for Json
3433
#include <cloe/utility/statistics.hpp> // for Accumulator
3534
#include <cloe/utility/timer.hpp> // for DurationTimer<>
@@ -195,10 +194,10 @@ class StateMachine {
195194
interrupt_ = id;
196195
}
197196

198-
boost::optional<StateId> pop_interrupt() {
197+
std::optional<StateId> pop_interrupt() {
199198
std::lock_guard<std::mutex> guard(interrupt_mtx_);
200199
if (interrupt_ == nullptr) {
201-
return boost::none;
200+
return std::nullopt;
202201
} else {
203202
auto tmp = interrupt_;
204203
interrupt_ = nullptr;

0 commit comments

Comments
 (0)