15 #ifndef OPENSCENARIO_INTERPRETER__SYNTAX__CUSTOM_COMMAND_ACTION_HPP_
16 #define OPENSCENARIO_INTERPRETER__SYNTAX__CUSTOM_COMMAND_ACTION_HPP_
20 #include <pugixml.hpp>
21 #include <rclcpp/rclcpp.hpp>
23 #include <tier4_simulation_msgs/msg/simulation_events.hpp>
28 inline namespace syntax
36 class SpecialAction<EXIT_FAILURE> :
public std::integral_constant<int, EXIT_FAILURE>,
37 public std::runtime_error
43 template <
typename... Ts>
51 template <
typename Container>
52 struct comma_separated
54 const Container & container;
55 const std::function<void(std::ostream &,
const typename Container::value_type &)> print;
57 template <
typename Pr
inter>
58 explicit comma_separated(
const Container & container, Printer && print)
59 : container{container}, print{std::forward<decltype(print)>(print)}
63 friend auto operator<<(std::ostream & os,
const comma_separated & cs) -> std::ostream &
66 for (
const auto & value : cs.container) {
67 os << std::exchange(separator,
", ");
74 template <
typename Conditions>
75 static auto makeMessage(
77 const Conditions & conditions)
79 std::stringstream what;
80 what <<
"CustomCommandAction typed " << std::quoted(
"exitFailure") <<
" was triggered by the ";
81 const auto anonymous = std::any_of(
82 conditions.begin(), conditions.end(),
83 [](
const auto & condition) { return condition.first.empty(); });
84 switch (conditions.size()) {
86 what << trigger_name <<
" (" << trigger_path <<
")";
90 what <<
"anonymous " << trigger_name <<
" (" << trigger_path <<
"." << trigger_name
91 <<
"[0]): " << conditions[0].second;
93 what << trigger_name <<
" named " << std::quoted(conditions[0].first) <<
": "
94 << conditions[0].second;
99 what <<
"anonymous " << trigger_name <<
"s (" << trigger_path <<
"." << trigger_name
101 << comma_separated(conditions, [i = 0](
auto & os,
const auto & condition)
mutable {
102 os <<
'{' << std::quoted(
std::to_string(i++)) <<
": " << condition.second
106 what <<
"named " << trigger_name <<
"s {"
109 [](
auto & os,
const auto & condition) { os << std::quoted(condition.first); })
110 <<
"}: " << comma_separated(conditions, [](
auto & os,
const auto & condition) {
111 os <<
'{' << std::quoted(condition.first) <<
": " << condition.second <<
'}';
121 :
std::runtime_error{
122 "CustomCommandAction typed \"exitFailure\" was triggered on an unexpected code path. This is "
123 "a simulator bug. Report this to the simulator developer."}
130 :
std::runtime_error{make_message(path)},
131 make_message{make_message},
132 source_name{source_name},
141 const std::vector<std::pair<std::string, std::string>> & conditions = {})
143 [trigger_name, conditions](
const auto & trigger_path) {
144 return makeMessage(trigger_name, trigger_path, conditions);
146 source_name,
concatenate(
'.', element_name,
'[', element_index,
']')}
155 inner.make_message, source_name,
157 '.', element_name,
'[',
158 (inner.source_name.empty() ?
std::
to_string(element_index) :
'"' + inner.source_name +
'"'),
166 inner.make_message,
"",
168 element_name, (inner.source_name.empty() ?
"" :
"." + inner.source_name), inner.path)}
191 virtual auto run() noexcept ->
void {}
214 const std::shared_ptr<CustomCommand> command;
219 auto accomplished() noexcept ->
bool {
return command->accomplished(); }
223 auto run() noexcept ->
void {
return command->run(); }
Definition: scope.hpp:154
auto local() const noexcept -> const Scope &
Definition: scope.cpp:125
SpecialAction()
Definition: custom_command_action.hpp:120
SpecialAction(const std::string &element_name, const SpecialAction &inner)
Definition: custom_command_action.hpp:164
SpecialAction(const std::string &source_name, const std::string &element_name, int element_index, const std::string &trigger_name, const std::vector< std::pair< std::string, std::string >> &conditions={})
Definition: custom_command_action.hpp:138
SpecialAction(const std::string &source_name, const std::string &element_name, int element_index, SpecialAction const &inner)
Definition: custom_command_action.hpp:151
SpecialAction(const std::function< std::string(const std::string &)> &make_message, const std::string &source_name, const std::string &path)
Definition: custom_command_action.hpp:127
auto concatenate
Definition: concatenate.hpp:27
auto operator<<(std::ostream &, const Boolean &) -> std::ostream &
Definition: boolean.cpp:46
std::string String
Definition: string.hpp:24
char const * to_string(const RoutingGraphType &)
Definition: routing_graph_type.cpp:21
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: custom_command_action.hpp:208
auto endsImmediately() const -> bool
Definition: custom_command_action.hpp:221
auto run() noexcept -> void
Definition: custom_command_action.hpp:223
const String content
Definition: custom_command_action.hpp:211
CustomCommandAction(const pugi::xml_node &, const Scope &)
Definition: custom_command_action.cpp:340
auto start() -> void
Definition: custom_command_action.hpp:225
const String type
Definition: custom_command_action.hpp:209
auto accomplished() noexcept -> bool
Definition: custom_command_action.hpp:219
Definition: custom_command_action.hpp:174
virtual auto start(const Scope &) -> void
Definition: custom_command_action.hpp:193
const std::vector< std::string > parameters
Definition: custom_command_action.hpp:175
virtual auto run() noexcept -> void
Definition: custom_command_action.hpp:191
virtual auto accomplished() noexcept -> bool
Definition: custom_command_action.hpp:187
CustomCommand(const std::vector< std::string > ¶meters)
Definition: custom_command_action.hpp:183
virtual auto endsImmediately() const -> bool
Definition: custom_command_action.hpp:189
CustomCommand(CustomCommand &&)=default
virtual ~CustomCommand()=default
CustomCommand(const CustomCommand &)=default
Definition: custom_command_action.hpp:32