From f9a953bde65ea26579643bcc9e7898b6172fc758 Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Tue, 17 Sep 2024 18:15:17 +0900 Subject: [PATCH 01/10] Utilize extern template to make build faster --- .../openscenario_interpreter/reader/attribute.hpp | 11 ++++++++++- .../src/reader/attribute.cpp | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 openscenario/openscenario_interpreter/src/reader/attribute.cpp diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp index 945e1a346a3..dc3a724e7d7 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ namespace openscenario_interpreter { +struct Scope; + inline namespace reader { template @@ -157,7 +160,7 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc } template -auto readAttribute(const std::string & name, const Node & node, const Scope & scope, T && value) +auto readAttribute(const std::string & name, const Node & node, const Scope & scope, T && value) -> T { if (node.attribute(name.c_str())) { return readAttribute(name, node, scope); @@ -175,6 +178,12 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc return std::optional(); } } + +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Double; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> String; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; } // namespace reader } // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/src/reader/attribute.cpp b/openscenario/openscenario_interpreter/src/reader/attribute.cpp new file mode 100644 index 00000000000..6393edd76d7 --- /dev/null +++ b/openscenario/openscenario_interpreter/src/reader/attribute.cpp @@ -0,0 +1,13 @@ +#include + +namespace openscenario_interpreter +{ +inline namespace reader +{ +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Double; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> String; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; +} +} From d4600c37e53e6e36b4e4b8194f0bd36de6ea0cff Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Tue, 17 Sep 2024 18:16:08 +0900 Subject: [PATCH 02/10] Add new sources to CMakeLists.txt --- openscenario/openscenario_interpreter/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openscenario/openscenario_interpreter/CMakeLists.txt b/openscenario/openscenario_interpreter/CMakeLists.txt index a68a5360e5f..a3b1e4e53fa 100644 --- a/openscenario/openscenario_interpreter/CMakeLists.txt +++ b/openscenario/openscenario_interpreter/CMakeLists.txt @@ -21,11 +21,13 @@ ament_auto_find_build_dependencies() file(GLOB ${PROJECT_NAME}_POSIX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/posix/*.cpp) file(GLOB ${PROJECT_NAME}_SYNTAX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/syntax/*.cpp) file(GLOB ${PROJECT_NAME}_UTILITY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/utility/*.cpp) +file(GLOB ${PROJECT_NAME}_READER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/reader/*.cpp) ament_auto_add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_POSIX_SOURCES} ${${PROJECT_NAME}_SYNTAX_SOURCES} ${${PROJECT_NAME}_UTILITY_SOURCES} + ${${PROJECT_NAME}_READER_SOURCES} src/object.cpp src/evaluate.cpp src/openscenario_interpreter.cpp From e136f892c3095f916eecc9c19d97c9297c127b6d Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Tue, 17 Sep 2024 18:17:36 +0900 Subject: [PATCH 03/10] Remove unneccessary template specialization declaration --- .../syntax/distance_condition.hpp | 20 ------------------- .../syntax/relative_distance_condition.hpp | 20 ------------------- .../src/syntax/distance_condition.cpp | 14 ++++++------- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/distance_condition.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/distance_condition.hpp index d7f297bf54f..e2c4de4f76b 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/distance_condition.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/distance_condition.hpp @@ -126,26 +126,6 @@ struct DistanceCondition : private Scope, private SimulatorCore::ConditionEvalua auto evaluate() -> Object; }; - -// Ignore spell miss due to OpenSCENARIO standard. -// cspell: ignore euclidian - -// clang-format off -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -template <> auto DistanceCondition::distance(const EntityRef &) const -> double; -// clang-format on } // namespace syntax } // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/relative_distance_condition.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/relative_distance_condition.hpp index 80265549339..31f7eff7f9d 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/relative_distance_condition.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/syntax/relative_distance_condition.hpp @@ -110,26 +110,6 @@ struct RelativeDistanceCondition : private Scope, private SimulatorCore::Conditi auto evaluate() -> Object; }; - -// Ignore spell miss due to OpenSCENARIO standard. -// cspell: ignore euclidian - -// clang-format off -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -template <> auto RelativeDistanceCondition::distance(const EntityRef &) -> double; -// clang-format on } // namespace syntax } // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp b/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp index fd90d905e38..b99ae798eab 100644 --- a/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/distance_condition.cpp @@ -127,13 +127,6 @@ auto DistanceCondition::description() const -> std::string #define DISTANCE(...) distance<__VA_ARGS__>(triggering_entity) -auto DistanceCondition::distance(const EntityRef & triggering_entity) const -> double -{ - SWITCH_COORDINATE_SYSTEM( - SWITCH_RELATIVE_DISTANCE_TYPE, SWITCH_ROUTING_ALGORITHM, SWITCH_FREESPACE, DISTANCE); - return Double::nan(); -} - // @todo: after checking all the scenario work well with consider_z = true, remove this function and use std::hypot(x,y,z) static double hypot(const double x, const double y, const double z, const bool consider_z) { @@ -744,6 +737,13 @@ auto DistanceCondition::distance< position); } +auto DistanceCondition::distance(const EntityRef & triggering_entity) const -> double +{ + SWITCH_COORDINATE_SYSTEM( + SWITCH_RELATIVE_DISTANCE_TYPE, SWITCH_ROUTING_ALGORITHM, SWITCH_FREESPACE, DISTANCE); + return Double::nan(); +} + auto DistanceCondition::evaluate() -> Object { results.clear(); From cc83724ea7de7877359588e3a4a7b28efe4414cc Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Tue, 17 Sep 2024 18:18:23 +0900 Subject: [PATCH 04/10] Change `choice()` to be non-templated function --- .../reader/element.hpp | 57 +----------------- .../src/reader/element.cpp | 60 +++++++++++++++++++ .../src/syntax/action.cpp | 9 +-- .../src/syntax/assign_controller_action.cpp | 7 ++- .../src/syntax/assign_route_action.cpp | 7 ++- .../src/syntax/by_value_condition.cpp | 17 +++--- .../src/syntax/collision_condition.cpp | 7 ++- .../src/syntax/condition.cpp | 7 ++- .../deterministic_parameter_distribution.cpp | 7 ++- ...tic_single_parameter_distribution_type.cpp | 9 +-- .../src/syntax/distribution_definition.cpp | 7 ++- .../src/syntax/entity_action.cpp | 7 ++- .../src/syntax/entity_condition.cpp | 36 +++++------ .../src/syntax/entity_object.cpp | 11 ++-- .../src/syntax/environment_action.cpp | 7 ++- .../src/syntax/global_action.cpp | 13 ++-- .../src/syntax/lane_change_target.cpp | 7 ++- .../src/syntax/lateral_action.cpp | 9 +-- .../src/syntax/longitudinal_action.cpp | 9 +-- .../src/syntax/modify_rule.cpp | 7 ++- .../src/syntax/object_controller.cpp | 7 ++- .../src/syntax/open_scenario_category.cpp | 11 ++-- .../src/syntax/parameter_action.cpp | 7 ++- .../src/syntax/position.cpp | 23 +++---- .../src/syntax/private_action.cpp | 19 +++--- .../src/syntax/routing_action.cpp | 9 +-- .../src/syntax/selected_entities.cpp | 7 ++- .../src/syntax/shape.cpp | 9 +-- .../src/syntax/speed_action_target.cpp | 7 ++- .../syntax/stochastic_distribution_type.cpp | 15 ++--- .../src/syntax/time_reference.cpp | 7 ++- .../src/syntax/traffic_signal_action.cpp | 7 ++- .../src/syntax/trajectory_ref.cpp | 7 ++- 33 files changed, 235 insertions(+), 200 deletions(-) create mode 100644 openscenario/openscenario_interpreter/src/reader/element.cpp diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp index 7ff746d4981..6f9d6363ab4 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp @@ -153,62 +153,7 @@ auto readGroups(const pugi::xml_node & node, Ts &&... xs) return groups; } -template -auto choice(const pugi::xml_node & node, Ts &&... xs) -> decltype(auto) -{ - const std::unordered_map> callees{ - std::forward(xs)...}; - - std::unordered_map specs{}; - - for (const auto & each : callees) { - if (const auto child = node.child(std::get<0>(each).c_str())) { - specs.emplace(std::get<0>(each), child); - } - } - - auto print_keys_to = [&](auto & os, const auto & xs) -> decltype(auto) { - if (not xs.empty()) { - for (auto iter = std::begin(xs); iter != std::end(xs); ++iter) { - os << std::get<0>(*iter); - - switch (std::distance(iter, std::end(xs))) { - case 1: - return os; - - case 2: - os << " and "; - break; - - default: - os << ", "; - break; - } - } - } - - return os; - }; - - if (specs.empty()) { - std::stringstream what; - what << "Class " << node.name() << " requires one of following elements: "; - print_keys_to(what, callees); - what << ". But no element specified"; - throw SyntaxError(what.str()); - } else if (1 < specs.size()) { - std::stringstream what; - what << "Class " << node.name() << " requires just one of following elements: "; - print_keys_to(what, callees); - what << ". But " << specs.size() << " element" << (1 < specs.size() ? "s" : "") << " ("; - print_keys_to(what, specs); - what << ") specified"; - throw SyntaxError(what.str()); - } else { - const auto iter = std::cbegin(specs); - return callees.at(std::get<0>(*iter))(std::get<1>(*iter)); - } -} +auto choice(const pugi::xml_node & node, std::unordered_map> callees) -> Object; } // namespace reader } // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/src/reader/element.cpp b/openscenario/openscenario_interpreter/src/reader/element.cpp new file mode 100644 index 00000000000..47dc74cff40 --- /dev/null +++ b/openscenario/openscenario_interpreter/src/reader/element.cpp @@ -0,0 +1,60 @@ +#include + +namespace openscenario_interpreter +{ +inline namespace reader +{ +auto choice(const pugi::xml_node & node, std::unordered_map> callees) -> Object +{ + std::unordered_map specs{}; + + for (const auto & each : callees) { + if (const auto child = node.child(std::get<0>(each).c_str())) { + specs.emplace(std::get<0>(each), child); + } + } + + auto print_keys_to = [&](auto & os, const auto & xs) -> decltype(auto) { + if (not xs.empty()) { + for (auto iter = std::begin(xs); iter != std::end(xs); ++iter) { + os << std::get<0>(*iter); + + switch (std::distance(iter, std::end(xs))) { + case 1: + return os; + + case 2: + os << " and "; + break; + + default: + os << ", "; + break; + } + } + } + + return os; + }; + + if (specs.empty()) { + std::stringstream what; + what << "Class " << node.name() << " requires one of following elements: "; + print_keys_to(what, callees); + what << ". But no element specified"; + throw SyntaxError(what.str()); + } else if (1 < specs.size()) { + std::stringstream what; + what << "Class " << node.name() << " requires just one of following elements: "; + print_keys_to(what, callees); + what << ". But " << specs.size() << " element" << (1 < specs.size() ? "s" : "") << " ("; + print_keys_to(what, specs); + what << ") specified"; + throw SyntaxError(what.str()); + } else { + const auto iter = std::cbegin(specs); + return callees.at(std::get<0>(*iter))(std::get<1>(*iter)); + } +} +} // namespace reader +} // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/src/syntax/action.cpp b/openscenario/openscenario_interpreter/src/syntax/action.cpp index b7a20c21f15..6636f254a99 100644 --- a/openscenario/openscenario_interpreter/src/syntax/action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/action.cpp @@ -24,10 +24,11 @@ Action::Action(const pugi::xml_node & node, Scope & scope) // clang-format off : Scope(readAttribute("name", node, scope), scope), ComplexType( - choice(node, - std::make_pair( "GlobalAction", [this](auto && node) { return make< GlobalAction>(node, local()); }), - std::make_pair("UserDefinedAction", [this](auto && node) { return make(node, local()); }), - std::make_pair( "PrivateAction", [this](auto && node) { return make< PrivateAction>(node, local()); }))) + choice(node, { + { "GlobalAction", [this](auto && node) { return make< GlobalAction>(node, local()); } }, + { "UserDefinedAction", [this](auto && node) { return make(node, local()); } }, + { "PrivateAction", [this](auto && node) { return make< PrivateAction>(node, local()); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/assign_controller_action.cpp b/openscenario/openscenario_interpreter/src/syntax/assign_controller_action.cpp index f973e4d67d0..e2ecae46121 100644 --- a/openscenario/openscenario_interpreter/src/syntax/assign_controller_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/assign_controller_action.cpp @@ -34,9 +34,10 @@ AssignControllerAction::AssignControllerAction(const ComplexType & controller) AssignControllerAction::AssignControllerAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("Controller", [&](const auto & node) { return make(node, scope); }), - std::make_pair("CatalogReference", [&](const auto & node) { return CatalogReference(node, scope).make(); }))) + choice(node, { + { "Controller", [&](const auto & node) { return make(node, scope); } }, + { "CatalogReference", [&](const auto & node) { return CatalogReference(node, scope).make(); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/assign_route_action.cpp b/openscenario/openscenario_interpreter/src/syntax/assign_route_action.cpp index 376e5f270dd..775b0ec4af4 100644 --- a/openscenario/openscenario_interpreter/src/syntax/assign_route_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/assign_route_action.cpp @@ -28,9 +28,10 @@ AssignRouteAction::AssignRouteAction(const pugi::xml_node & node, Scope & scope) // clang-format off : Scope(scope), route( - choice(node, - std::make_pair("Route", [&](auto && node) { return make (node, local()); }), - std::make_pair("CatalogReference", [&](auto && node) { return CatalogReference(node, local()).make(); }))) + choice(node, { + { "Route", [&](auto && node) { return make (node, local()); } }, + { "CatalogReference", [&](auto && node) { return CatalogReference(node, local()).make(); } }, + })) // clang-format on { // OpenSCENARIO 1.2 Table 11 diff --git a/openscenario/openscenario_interpreter/src/syntax/by_value_condition.cpp b/openscenario/openscenario_interpreter/src/syntax/by_value_condition.cpp index 3bf96bd655e..5a2f109ea0c 100644 --- a/openscenario/openscenario_interpreter/src/syntax/by_value_condition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/by_value_condition.cpp @@ -28,14 +28,15 @@ inline namespace syntax ByValueCondition::ByValueCondition(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "ParameterCondition", [&](const auto & node) { return make< ParameterCondition>(node, scope); }), - std::make_pair( "TimeOfDayCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "SimulationTimeCondition", [&](const auto & node) { return make< SimulationTimeCondition>(node, scope); }), - std::make_pair( "StoryboardElementStateCondition", [&](const auto & node) { return make< StoryboardElementStateCondition>(node, scope); }), - std::make_pair( "UserDefinedValueCondition", [&](const auto & node) { return make< UserDefinedValueCondition>(node, scope); }), - std::make_pair( "TrafficSignalCondition", [&](const auto & node) { return make< TrafficSignalCondition>(node, scope); }), - std::make_pair("TrafficSignalControllerCondition", [&](const auto & node) { return make(node, scope); }))) + choice(node, { + { "ParameterCondition", [&](const auto & node) { return make< ParameterCondition>(node, scope); } }, + { "TimeOfDayCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "SimulationTimeCondition", [&](const auto & node) { return make< SimulationTimeCondition>(node, scope); } }, + { "StoryboardElementStateCondition", [&](const auto & node) { return make< StoryboardElementStateCondition>(node, scope); } }, + { "UserDefinedValueCondition", [&](const auto & node) { return make< UserDefinedValueCondition>(node, scope); } }, + { "TrafficSignalCondition", [&](const auto & node) { return make< TrafficSignalCondition>(node, scope); } }, + { "TrafficSignalControllerCondition", [&](const auto & node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/collision_condition.cpp b/openscenario/openscenario_interpreter/src/syntax/collision_condition.cpp index 24651b21773..5ec4137cd3a 100644 --- a/openscenario/openscenario_interpreter/src/syntax/collision_condition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/collision_condition.cpp @@ -28,9 +28,10 @@ CollisionCondition::CollisionCondition( // clang-format off : Scope(scope), another_given_entity( - choice(node, - std::make_pair("EntityRef", [&](auto && node) { return make(node, scope); }), - std::make_pair("ByType", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }))), + choice(node, { + { "EntityRef", [&](auto && node) { return make(node, scope); } }, + { "ByType", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + })), triggering_entities(triggering_entities) // clang-format on { diff --git a/openscenario/openscenario_interpreter/src/syntax/condition.cpp b/openscenario/openscenario_interpreter/src/syntax/condition.cpp index 89e440c948f..0406f6ce805 100644 --- a/openscenario/openscenario_interpreter/src/syntax/condition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/condition.cpp @@ -34,9 +34,10 @@ static_assert(std::is_trivial::value, ""); Condition::Condition(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("ByEntityCondition", [&](auto && node) { return make(node, scope); }), - std::make_pair( "ByValueCondition", [&](auto && node) { return make< ByValueCondition>(node, scope); }))), + choice(node, { + { "ByEntityCondition", [&](auto && node) { return make(node, scope); } }, + { "ByValueCondition", [&](auto && node) { return make< ByValueCondition>(node, scope); } }, + })), name(readAttribute("name", node, scope)), delay(readAttribute("delay", node, scope, Double())), condition_edge(readAttribute("conditionEdge", node, scope)), diff --git a/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp b/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp index 1fa382f686b..13906e7e13a 100644 --- a/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp @@ -23,9 +23,10 @@ DeterministicParameterDistribution::DeterministicParameterDistribution( const pugi::xml_node & node, Scope & scope) // clang-format off : Group( - choice(node, - std::make_pair("DeterministicMultiParameterDistribution", [&](auto && node){return make(node,scope);}), - std::make_pair("DeterministicSingleParameterDistribution", [&](auto && node){return make(node,scope);}))) + choice(node, { + { "DeterministicMultiParameterDistribution", [&](auto && node) { return make(node,scope); }}, + { "DeterministicSingleParameterDistribution", [&](auto && node) { return make(node,scope); }}, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp b/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp index 76296e5e95d..1a531f502fa 100644 --- a/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp @@ -23,10 +23,11 @@ DeterministicSingleParameterDistributionType::DeterministicSingleParameterDistri const pugi::xml_node & node, Scope & scope) // clang-format off : Group( - choice(node, - std::make_pair("DistributionSet", [&](auto && node){ return make(node, scope);}), - std::make_pair("DistributionRange", [&](auto && node){ return make(node, scope);}), - std::make_pair("UserDefinedDistribution", [&](auto && node){ return make(node, scope);}))) + choice(node, { + { "DistributionSet", [&](auto && node){ return make(node, scope);} }, + { "DistributionRange", [&](auto && node){ return make(node, scope);} }, + { "UserDefinedDistribution", [&](auto && node){ return make(node, scope);} }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp b/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp index 7499024a894..074535d0732 100644 --- a/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp @@ -22,9 +22,10 @@ inline namespace syntax DistributionDefinition::DistributionDefinition(const pugi::xml_node & tree, Scope & scope) // clang-format off : Group( - choice(tree, - std::make_pair("Deterministic", [&](auto && node){return make(node,scope);}), - std::make_pair("Stochastic", [&](auto && node){return make(node,scope);}))) + choice(tree, { + { "Deterministic", [&](auto && node){return make(node,scope);} }, + { "Stochastic", [&](auto && node){return make(node,scope);} }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/entity_action.cpp b/openscenario/openscenario_interpreter/src/syntax/entity_action.cpp index cd04e3f50e3..60ccc1c58c1 100644 --- a/openscenario/openscenario_interpreter/src/syntax/entity_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/entity_action.cpp @@ -23,9 +23,10 @@ inline namespace syntax EntityAction::EntityAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "AddEntityAction", [&](auto && node) { return make< AddEntityAction>(node, scope); }), - std::make_pair("DeleteEntityAction", [&](auto && node) { return make(node, scope); }))), + choice(node, { + { "AddEntityAction", [&](auto && node) { return make< AddEntityAction>(node, scope); } }, + { "DeleteEntityAction", [&](auto && node) { return make(node, scope); } }, + })), entity_ref(readAttribute("entityRef", node, scope), scope) // clang-format on { diff --git a/openscenario/openscenario_interpreter/src/syntax/entity_condition.cpp b/openscenario/openscenario_interpreter/src/syntax/entity_condition.cpp index df89c5ba0fe..cee1325a036 100644 --- a/openscenario/openscenario_interpreter/src/syntax/entity_condition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/entity_condition.cpp @@ -32,24 +32,24 @@ EntityCondition::EntityCondition( const pugi::xml_node & node, Scope & scope, const TriggeringEntities & triggering_entities) // clang-format off : ComplexType( - choice(node, - std::make_pair( "EndOfRoadCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "CollisionCondition", [&](const auto & node) { return make< CollisionCondition>(node, scope, triggering_entities); }), - std::make_pair( "OffroadCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "TimeHeadwayCondition", [&](const auto & node) { return make< TimeHeadwayCondition>(node, scope, triggering_entities); }), - std::make_pair( "TimeToCollisionCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "AccelerationCondition", [&](const auto & node) { return make< AccelerationCondition>(node, scope, triggering_entities); }), - std::make_pair( "StandStillCondition", [&](const auto & node) { return make< StandStillCondition>(node, scope, triggering_entities); }), - std::make_pair( "SpeedCondition", [&](const auto & node) { return make< SpeedCondition>(node, scope, triggering_entities); }), - std::make_pair( "RelativeSpeedCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "TraveledDistanceCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "ReachPositionCondition", [&](const auto & node) { return make< ReachPositionCondition>(node, scope, triggering_entities); }), - std::make_pair( "DistanceCondition", [&](const auto & node) { return make< DistanceCondition>(node, scope, triggering_entities); }), - std::make_pair( "RelativeDistanceCondition", [&](const auto & node) { return make< RelativeDistanceCondition>(node, scope, triggering_entities); }), - std::make_pair("RelativeClearanceCondition", [&](const auto & node) { return make(node, scope, triggering_entities); }), - std::make_pair( "AngleCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "RelativeAngleCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }) - )) + choice(node, { + { "EndOfRoadCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "CollisionCondition", [&](const auto & node) { return make< CollisionCondition>(node, scope, triggering_entities); } }, + { "OffroadCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "TimeHeadwayCondition", [&](const auto & node) { return make< TimeHeadwayCondition>(node, scope, triggering_entities); } }, + { "TimeToCollisionCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "AccelerationCondition", [&](const auto & node) { return make< AccelerationCondition>(node, scope, triggering_entities); } }, + { "StandStillCondition", [&](const auto & node) { return make< StandStillCondition>(node, scope, triggering_entities); } }, + { "SpeedCondition", [&](const auto & node) { return make< SpeedCondition>(node, scope, triggering_entities); } }, + { "RelativeSpeedCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "TraveledDistanceCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "ReachPositionCondition", [&](const auto & node) { return make< ReachPositionCondition>(node, scope, triggering_entities); } }, + { "DistanceCondition", [&](const auto & node) { return make< DistanceCondition>(node, scope, triggering_entities); } }, + { "RelativeDistanceCondition", [&](const auto & node) { return make< RelativeDistanceCondition>(node, scope, triggering_entities); } }, + { "RelativeClearanceCondition", [&](const auto & node) { return make(node, scope, triggering_entities); } }, + { "AngleCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "RelativeAngleCondition", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/entity_object.cpp b/openscenario/openscenario_interpreter/src/syntax/entity_object.cpp index e345d2237b9..fb53a68ddd3 100644 --- a/openscenario/openscenario_interpreter/src/syntax/entity_object.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/entity_object.cpp @@ -24,11 +24,12 @@ inline namespace syntax EntityObject::EntityObject(const pugi::xml_node & node, Scope & scope) // clang-format off : Group( - choice(node, - std::make_pair("CatalogReference", [&](auto && node) { return CatalogReference(node, scope).make(); }), - std::make_pair("Vehicle", [&](auto && node) { return make(node, scope); }), - std::make_pair("Pedestrian", [&](auto && node) { return make(node, scope); }), - std::make_pair("MiscObject", [&](auto && node) { return make(node, scope); }))) + choice(node, { + { "CatalogReference", [&](auto && node) { return CatalogReference(node, scope).make(); } }, + { "Vehicle", [&](auto && node) { return make(node, scope); } }, + { "Pedestrian", [&](auto && node) { return make(node, scope); } }, + { "MiscObject", [&](auto && node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/environment_action.cpp b/openscenario/openscenario_interpreter/src/syntax/environment_action.cpp index 4c66bd770d9..20de7725b2b 100644 --- a/openscenario/openscenario_interpreter/src/syntax/environment_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/environment_action.cpp @@ -24,9 +24,10 @@ inline namespace syntax EnvironmentAction::EnvironmentAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("Environment", [&](const auto & node) { return make(node, scope); }), - std::make_pair("CatalogReference", [&](const auto & node) { return CatalogReference(node, scope).make(); }))) + choice(node, { + { "Environment", [&](const auto & node) { return make(node, scope); } }, + { "CatalogReference", [&](const auto & node) { return CatalogReference(node, scope).make(); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/global_action.cpp b/openscenario/openscenario_interpreter/src/syntax/global_action.cpp index 90dfad8d7d6..676460e2e57 100644 --- a/openscenario/openscenario_interpreter/src/syntax/global_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/global_action.cpp @@ -22,12 +22,13 @@ inline namespace syntax GlobalAction::GlobalAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "EnvironmentAction", [&](auto && node) { return make< EnvironmentAction>(std::forward(node), scope); }), - std::make_pair( "EntityAction", [&](auto && node) { return make< EntityAction>(std::forward(node), scope); }), - std::make_pair( "ParameterAction", [&](auto && node) { return make< ParameterAction>(std::forward(node), scope); }), - std::make_pair("InfrastructureAction", [&](auto && node) { return make(std::forward(node), scope); }), - std::make_pair( "TrafficAction", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }))) + choice(node, { + { "EnvironmentAction", [&](auto && node) { return make< EnvironmentAction>(std::forward(node), scope); } }, + { "EntityAction", [&](auto && node) { return make< EntityAction>(std::forward(node), scope); } }, + { "ParameterAction", [&](auto && node) { return make< ParameterAction>(std::forward(node), scope); } }, + {"InfrastructureAction", [&](auto && node) { return make(std::forward(node), scope); } }, + { "TrafficAction", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/lane_change_target.cpp b/openscenario/openscenario_interpreter/src/syntax/lane_change_target.cpp index 84abecb2062..27c533a47d2 100644 --- a/openscenario/openscenario_interpreter/src/syntax/lane_change_target.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/lane_change_target.cpp @@ -24,9 +24,10 @@ inline namespace syntax LaneChangeTarget::LaneChangeTarget(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("RelativeTargetLane", [&](auto && node) { return make(node, scope); }), - std::make_pair("AbsoluteTargetLane", [&](auto && node) { return make(node, scope); }))) + choice(node, { + { "RelativeTargetLane", [&](auto && node) { return make(node, scope); } }, + { "AbsoluteTargetLane", [&](auto && node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/lateral_action.cpp b/openscenario/openscenario_interpreter/src/syntax/lateral_action.cpp index b48834cca57..537532484ee 100644 --- a/openscenario/openscenario_interpreter/src/syntax/lateral_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/lateral_action.cpp @@ -22,10 +22,11 @@ inline namespace syntax LateralAction::LateralAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "LaneChangeAction", [&](auto && node) { return make(node, scope); }), - std::make_pair( "LaneOffsetAction", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair("LateralDistanceAction", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }))) + choice(node, { + { "LaneChangeAction", [&](auto && node) { return make(node, scope); } }, + { "LaneOffsetAction", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "LateralDistanceAction", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/longitudinal_action.cpp b/openscenario/openscenario_interpreter/src/syntax/longitudinal_action.cpp index 4e807506b0e..d0b56765779 100644 --- a/openscenario/openscenario_interpreter/src/syntax/longitudinal_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/longitudinal_action.cpp @@ -22,10 +22,11 @@ inline namespace syntax LongitudinalAction::LongitudinalAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "SpeedAction", [&](const auto & node) { return make(node, scope); }), - std::make_pair("LongitudinalDistanceAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "SpeedProfileAction", [&](const auto & node) { return make(node, scope); }))) + choice(node, { + { "SpeedAction", [&](const auto & node) { return make(node, scope); } }, + { "LongitudinalDistanceAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "SpeedProfileAction", [&](const auto & node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/modify_rule.cpp b/openscenario/openscenario_interpreter/src/syntax/modify_rule.cpp index 48d45a072c3..c7ffdd955e5 100644 --- a/openscenario/openscenario_interpreter/src/syntax/modify_rule.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/modify_rule.cpp @@ -25,9 +25,10 @@ inline namespace syntax ModifyRule::ModifyRule(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("AddValue", [&](const auto & node) { return make(node, scope); }), - std::make_pair("MultiplyByValue", [&](const auto & node) { return make(node, scope); }))) + choice(node, { + { "AddValue", [&](const auto & node) { return make(node, scope); } }, + { "MultiplyByValue", [&](const auto & node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/object_controller.cpp b/openscenario/openscenario_interpreter/src/syntax/object_controller.cpp index be8e48fdb82..74737f30369 100644 --- a/openscenario/openscenario_interpreter/src/syntax/object_controller.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/object_controller.cpp @@ -29,9 +29,10 @@ ObjectController::ObjectController() // ObjectController::ObjectController(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("CatalogReference", [&](auto && node) { return CatalogReference(node, scope).make(); }), - std::make_pair("Controller", [&](auto && node) { return make(node, scope); }))) + choice(node, { + { "CatalogReference", [&](auto && node) { return CatalogReference(node, scope).make(); } }, + { "Controller", [&](auto && node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp index 2c4d6e898c6..3a8db545f75 100644 --- a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp @@ -24,11 +24,12 @@ inline namespace syntax OpenScenarioCategory::OpenScenarioCategory(const pugi::xml_node & tree, Scope & scope) : Group( // clang-format off - choice(tree, - std::make_pair("Storyboard", [&](auto && ) { return make(tree, scope);}), // DIRTY HACK!!! - std::make_pair("Catalog", [&](auto && ) { return make(tree, scope);}), - std::make_pair("ParameterValueDistribution",[&](auto && node) { return make(node, scope);}))) -// clang-format on + choice(tree, { + { "Storyboard", [&](auto && ) { return make(tree, scope); } }, // DIRTY HACK!!! + { "Catalog", [&](auto && ) { return make(tree, scope); } }, + { "ParameterValueDistribution",[&](auto && node) { return make(node, scope); } }, + })) + // clang-format on { } } // namespace syntax diff --git a/openscenario/openscenario_interpreter/src/syntax/parameter_action.cpp b/openscenario/openscenario_interpreter/src/syntax/parameter_action.cpp index 3a60af7ffd8..f8d2bfbbe63 100644 --- a/openscenario/openscenario_interpreter/src/syntax/parameter_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/parameter_action.cpp @@ -23,9 +23,10 @@ inline namespace syntax ParameterAction::ParameterAction(const pugi::xml_node & parent, Scope & scope) // clang-format off : ComplexType( - choice(parent, - std::make_pair( "SetAction", [&](auto && node) { return make< ParameterSetAction>(node, scope, readAttribute("parameterRef", parent, scope)); }), - std::make_pair("ModifyAction", [&](auto && node) { return make(node, scope, readAttribute("parameterRef", parent, scope)); }))) + choice(parent, { + { "SetAction", [&](auto && node) { return make< ParameterSetAction>(node, scope, readAttribute("parameterRef", parent, scope)); } }, + { "ModifyAction", [&](auto && node) { return make(node, scope, readAttribute("parameterRef", parent, scope)); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/position.cpp b/openscenario/openscenario_interpreter/src/syntax/position.cpp index 39764457b8c..0ef847c6256 100644 --- a/openscenario/openscenario_interpreter/src/syntax/position.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/position.cpp @@ -23,17 +23,18 @@ inline namespace syntax Position::Position(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "WorldPosition", [&](auto && node) { return make< WorldPosition>(node, scope); }), - std::make_pair( "RelativeWorldPosition", [&](auto && node) { return make< RelativeWorldPosition>(node, scope); }), - std::make_pair("RelativeObjectPosition", [&](auto && node) { return make(node, scope); }), - std::make_pair( "RoadPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "RelativeRoadPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "LanePosition", [&](auto && node) { return make< LanePosition>(node, scope); }), - std::make_pair( "RelativeLanePosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "RoutePosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "GeoPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "TrajectoryPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }))) + choice(node, { + { "WorldPosition", [&](auto && node) { return make< WorldPosition>(node, scope); } }, + { "RelativeWorldPosition", [&](auto && node) { return make< RelativeWorldPosition>(node, scope); } }, + { "RelativeObjectPosition", [&](auto && node) { return make(node, scope); } }, + { "RoadPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "RelativeRoadPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "LanePosition", [&](auto && node) { return make< LanePosition>(node, scope); } }, + { "RelativeLanePosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "RoutePosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "GeoPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "TrajectoryPosition", [&](auto && node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/private_action.cpp b/openscenario/openscenario_interpreter/src/syntax/private_action.cpp index 8c4d76bafea..74414216cd9 100644 --- a/openscenario/openscenario_interpreter/src/syntax/private_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/private_action.cpp @@ -22,15 +22,16 @@ inline namespace syntax PrivateAction::PrivateAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "LongitudinalAction", [&](const auto & node) { return make(node, scope); }), - std::make_pair( "LateralAction", [&](const auto & node) { return make< LateralAction>(node, scope); }), - std::make_pair( "VisibilityAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "SynchronizeAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair("ActivateControllerAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "ControllerAction", [&](const auto & node) { return make< ControllerAction>(node, scope); }), - std::make_pair( "TeleportAction", [&](const auto & node) { return make< TeleportAction>(node, scope); }), - std::make_pair( "RoutingAction", [&](const auto & node) { return make< RoutingAction>(node, scope); }))) + choice(node, { + { "LongitudinalAction", [&](const auto & node) { return make(node, scope); } }, + { "LateralAction", [&](const auto & node) { return make< LateralAction>(node, scope); } }, + { "VisibilityAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "SynchronizeAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "ActivateControllerAction", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "ControllerAction", [&](const auto & node) { return make< ControllerAction>(node, scope); } }, + { "TeleportAction", [&](const auto & node) { return make< TeleportAction>(node, scope); } }, + { "RoutingAction", [&](const auto & node) { return make< RoutingAction>(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/routing_action.cpp b/openscenario/openscenario_interpreter/src/syntax/routing_action.cpp index b4618e83945..c239359101b 100644 --- a/openscenario/openscenario_interpreter/src/syntax/routing_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/routing_action.cpp @@ -22,10 +22,11 @@ inline namespace syntax RoutingAction::RoutingAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "AssignRouteAction", [&](const auto & node) { return make< AssignRouteAction>(node, scope); }), - std::make_pair("FollowTrajectoryAction", [&](const auto & node) { return make(node, scope); }), - std::make_pair( "AcquirePositionAction", [&](const auto & node) { return make< AcquirePositionAction>(node, scope); }))) + choice(node, { + { "AssignRouteAction", [&](const auto & node) { return make< AssignRouteAction>(node, scope); } }, + { "FollowTrajectoryAction", [&](const auto & node) { return make(node, scope); } }, + { "AcquirePositionAction", [&](const auto & node) { return make< AcquirePositionAction>(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/selected_entities.cpp b/openscenario/openscenario_interpreter/src/syntax/selected_entities.cpp index 5aa542b76a7..78b4638dae9 100644 --- a/openscenario/openscenario_interpreter/src/syntax/selected_entities.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/selected_entities.cpp @@ -35,9 +35,10 @@ SelectedEntities::SelectedEntities(const pugi::xml_node & tree, Scope & scope) // clang-format off // This function call is added to check the correctness of the syntax. // DO NOT REMOVE unless syntax check is conducted in another way. - choice(tree, - std::pair{"EntityRef", [](const auto &) { return unspecified; }}, - std::pair{"ByType", [](const auto &) { return unspecified; }}); + choice(tree, { + { "EntityRef", [](const auto &) { return unspecified; } }, + { "ByType", [](const auto &) { return unspecified; } }, + }); // clang-format on } } // namespace syntax diff --git a/openscenario/openscenario_interpreter/src/syntax/shape.cpp b/openscenario/openscenario_interpreter/src/syntax/shape.cpp index fa2001f1017..957c7a63fd2 100644 --- a/openscenario/openscenario_interpreter/src/syntax/shape.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/shape.cpp @@ -23,10 +23,11 @@ inline namespace syntax Shape::Shape(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("Polyline", [&](const auto & node) { return make(node, scope); }), - std::make_pair("Clothoid", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }), - std::make_pair( "Nurbs", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; }))) + choice(node, { + { "Polyline", [&](const auto & node) { return make(node, scope); } }, + { "Clothoid", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + { "Nurbs", [&](const auto & node) { throw UNSUPPORTED_ELEMENT_SPECIFIED(node.name()); return unspecified; } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/speed_action_target.cpp b/openscenario/openscenario_interpreter/src/syntax/speed_action_target.cpp index 8f984ce1a77..e6a8cd04ea2 100644 --- a/openscenario/openscenario_interpreter/src/syntax/speed_action_target.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/speed_action_target.cpp @@ -23,9 +23,10 @@ inline namespace syntax SpeedActionTarget::SpeedActionTarget(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("RelativeTargetSpeed", [&](const auto & node) { return make(node, scope); }), - std::make_pair("AbsoluteTargetSpeed", [&](const auto & node) { return make(node, scope); }))) + choice(node, { + { "RelativeTargetSpeed", [&](const auto & node) { return make(node, scope); } }, + { "AbsoluteTargetSpeed", [&](const auto & node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp b/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp index 4f2d334ae5b..ab7f6372e67 100644 --- a/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp @@ -22,13 +22,14 @@ inline namespace syntax StochasticDistributionType::StochasticDistributionType(const pugi::xml_node & node, Scope & scope) // clang-format off : Group( - choice(node, - std::make_pair("ProbabilityDistributionSet", [&](auto && node){return make(node, scope);}), - std::make_pair("NormalDistribution", [&](auto && node){return make(node, scope);}), - std::make_pair("UniformDistribution", [&](auto && node){return make(node, scope);}), - std::make_pair("PoissonDistribution", [&](auto && node){return make(node, scope);}), - std::make_pair("Histogram", [&](auto && node){return make(node, scope);}), - std::make_pair("UserDefinedDistribution", [&](auto && node){return make(node, scope);}))) + choice(node, { + { "ProbabilityDistributionSet", [&](auto && node){return make(node, scope);} }, + { "NormalDistribution", [&](auto && node){return make(node, scope);} }, + { "UniformDistribution", [&](auto && node){return make(node, scope);} }, + { "PoissonDistribution", [&](auto && node){return make(node, scope);} }, + { "Histogram", [&](auto && node){return make(node, scope);} }, + { "UserDefinedDistribution", [&](auto && node){return make(node, scope);} }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/time_reference.cpp b/openscenario/openscenario_interpreter/src/syntax/time_reference.cpp index 752ec243566..d48f83ce01b 100644 --- a/openscenario/openscenario_interpreter/src/syntax/time_reference.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/time_reference.cpp @@ -24,9 +24,10 @@ inline namespace syntax TimeReference::TimeReference(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair( "None", [&](const auto & node) { return make< None>(node, scope); }), - std::make_pair("Timing", [&](const auto & node) { return make(node, scope); }))) + choice(node, { + { "None", [&](const auto & node) { return make< None>(node, scope); } }, + { "Timing", [&](const auto & node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/traffic_signal_action.cpp b/openscenario/openscenario_interpreter/src/syntax/traffic_signal_action.cpp index 25ff8d77292..e6719015c28 100644 --- a/openscenario/openscenario_interpreter/src/syntax/traffic_signal_action.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/traffic_signal_action.cpp @@ -22,9 +22,10 @@ inline namespace syntax TrafficSignalAction::TrafficSignalAction(const pugi::xml_node & node, Scope & scope) // clang-format off : ComplexType( - choice(node, - std::make_pair("TrafficSignalControllerAction", [&](const auto & node) { return make(node, scope); }), - std::make_pair("TrafficSignalStateAction", [&](const auto & node) { return make(node, scope); }))) + choice(node, { + { "TrafficSignalControllerAction", [&](const auto & node) { return make(node, scope); } }, + { "TrafficSignalStateAction", [&](const auto & node) { return make(node, scope); } }, + })) // clang-format on { } diff --git a/openscenario/openscenario_interpreter/src/syntax/trajectory_ref.cpp b/openscenario/openscenario_interpreter/src/syntax/trajectory_ref.cpp index 837bebdbbe1..e5f78579f71 100644 --- a/openscenario/openscenario_interpreter/src/syntax/trajectory_ref.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/trajectory_ref.cpp @@ -23,9 +23,10 @@ inline namespace syntax TrajectoryRef::TrajectoryRef(const pugi::xml_node & node, Scope & scope) // clang-format off : trajectory( - choice(node, - std::make_pair( "Trajectory", [&](const auto & node) { return make(node, scope); }), - std::make_pair("CatalogReference", [&](const auto & node) { return CatalogReference(node, scope).make(); }))) + choice(node, { + { "Trajectory", [&](const auto & node) { return make(node, scope); } }, + { "CatalogReference", [&](const auto & node) { return CatalogReference(node, scope).make(); } }, + })) // clang-format on { } From 6e7500756ee63d305b69d076c0ca9b05782af283 Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Tue, 24 Sep 2024 09:12:10 +0900 Subject: [PATCH 05/10] Format --- .../syntax/deterministic_parameter_distribution.cpp | 4 ++-- ...erministic_single_parameter_distribution_type.cpp | 6 +++--- .../src/syntax/distribution_definition.cpp | 4 ++-- .../src/syntax/stochastic_distribution_type.cpp | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp b/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp index 13906e7e13a..448532e6d08 100644 --- a/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/deterministic_parameter_distribution.cpp @@ -24,8 +24,8 @@ DeterministicParameterDistribution::DeterministicParameterDistribution( // clang-format off : Group( choice(node, { - { "DeterministicMultiParameterDistribution", [&](auto && node) { return make(node,scope); }}, - { "DeterministicSingleParameterDistribution", [&](auto && node) { return make(node,scope); }}, + { "DeterministicMultiParameterDistribution", [&](auto && node) { return make(node,scope); } }, + { "DeterministicSingleParameterDistribution", [&](auto && node) { return make(node,scope); } }, })) // clang-format on { diff --git a/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp b/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp index 1a531f502fa..23e1e661bc5 100644 --- a/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/deterministic_single_parameter_distribution_type.cpp @@ -24,9 +24,9 @@ DeterministicSingleParameterDistributionType::DeterministicSingleParameterDistri // clang-format off : Group( choice(node, { - { "DistributionSet", [&](auto && node){ return make(node, scope);} }, - { "DistributionRange", [&](auto && node){ return make(node, scope);} }, - { "UserDefinedDistribution", [&](auto && node){ return make(node, scope);} }, + { "DistributionSet", [&](auto && node) { return make(node, scope); } }, + { "DistributionRange", [&](auto && node) { return make(node, scope); } }, + { "UserDefinedDistribution", [&](auto && node) { return make(node, scope); } }, })) // clang-format on { diff --git a/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp b/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp index 074535d0732..12f57f28bb8 100644 --- a/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp @@ -23,8 +23,8 @@ DistributionDefinition::DistributionDefinition(const pugi::xml_node & tree, Scop // clang-format off : Group( choice(tree, { - { "Deterministic", [&](auto && node){return make(node,scope);} }, - { "Stochastic", [&](auto && node){return make(node,scope);} }, + { "Deterministic", [&](auto && node) { return make(node,scope); } }, + { "Stochastic", [&](auto && node) { return make(node,scope); } }, })) // clang-format on { diff --git a/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp b/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp index ab7f6372e67..d659304845b 100644 --- a/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/stochastic_distribution_type.cpp @@ -23,12 +23,12 @@ StochasticDistributionType::StochasticDistributionType(const pugi::xml_node & no // clang-format off : Group( choice(node, { - { "ProbabilityDistributionSet", [&](auto && node){return make(node, scope);} }, - { "NormalDistribution", [&](auto && node){return make(node, scope);} }, - { "UniformDistribution", [&](auto && node){return make(node, scope);} }, - { "PoissonDistribution", [&](auto && node){return make(node, scope);} }, - { "Histogram", [&](auto && node){return make(node, scope);} }, - { "UserDefinedDistribution", [&](auto && node){return make(node, scope);} }, + { "ProbabilityDistributionSet", [&](auto && node) { return make(node, scope); } }, + { "NormalDistribution", [&](auto && node) { return make(node, scope); } }, + { "UniformDistribution", [&](auto && node) { return make(node, scope); } }, + { "PoissonDistribution", [&](auto && node) { return make(node, scope); } }, + { "Histogram", [&](auto && node) { return make(node, scope); } }, + { "UserDefinedDistribution", [&](auto && node) { return make(node, scope); } }, })) // clang-format on { From 9ee8e9833bbcfb65eba6fa5c5f09f05dc0853a04 Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Thu, 10 Oct 2024 14:07:04 +0900 Subject: [PATCH 06/10] Format comment --- .../src/syntax/open_scenario_category.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp index 3a8db545f75..702ebbf514a 100644 --- a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp @@ -23,13 +23,13 @@ inline namespace syntax { OpenScenarioCategory::OpenScenarioCategory(const pugi::xml_node & tree, Scope & scope) : Group( - // clang-format off +// clang-format off choice(tree, { { "Storyboard", [&](auto && ) { return make(tree, scope); } }, // DIRTY HACK!!! { "Catalog", [&](auto && ) { return make(tree, scope); } }, { "ParameterValueDistribution",[&](auto && node) { return make(node, scope); } }, })) - // clang-format on +// clang-format on { } } // namespace syntax From b3a5354f54bf31ab6ea8f56b83f7745b4d623c6c Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Thu, 10 Oct 2024 15:20:46 +0900 Subject: [PATCH 07/10] Format comment --- .../src/syntax/open_scenario_category.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp index 702ebbf514a..e7ee14526c2 100644 --- a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp @@ -22,8 +22,8 @@ namespace openscenario_interpreter inline namespace syntax { OpenScenarioCategory::OpenScenarioCategory(const pugi::xml_node & tree, Scope & scope) -: Group( // clang-format off +: Group( choice(tree, { { "Storyboard", [&](auto && ) { return make(tree, scope); } }, // DIRTY HACK!!! { "Catalog", [&](auto && ) { return make(tree, scope); } }, From 84f77bd7d858a87526d9b4ef86878b2b37baa77f Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Thu, 10 Oct 2024 15:21:25 +0900 Subject: [PATCH 08/10] Add some `extern template` to make build faster --- .../reader/attribute.hpp | 46 ++++++++++++------- .../reader/element.hpp | 25 +++++++++- .../src/reader/attribute.cpp | 26 +++++++---- .../src/reader/element.cpp | 21 +++++++-- 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp index dc3a724e7d7..ce3bb3cd7cd 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -32,20 +31,18 @@ namespace openscenario_interpreter { -struct Scope; - inline namespace reader { template -auto substitute(std::string attribute, Scope & scope) +auto substitute(std::string attribute, const Scope & scope) -> String { auto dirname = [](auto &&, auto && scope) { return scope.dirname(); }; - auto find_pkg_share = [](auto && package_name, auto &&) { + auto find_pkg_share = [](auto && package_name, const auto &) { return ament_index_cpp::get_package_share_directory(package_name); }; - auto ros2 = [](auto && arguments, auto &&) { + auto ros2 = [](auto && arguments, const auto &) { auto remove_trailing_newline = [](auto && s) { while (s.back() == '\n') { s.pop_back(); @@ -65,7 +62,7 @@ auto substitute(std::string attribute, Scope & scope) } }; - auto var = [](auto && name, auto && scope) { + auto var = [](auto && name, const auto & scope) { // TODO: Return the value of the launch configuration variable instead of the OpenSCENARIO parameter. if (const auto found = scope.ref(name); found) { return boost::lexical_cast(found); @@ -76,7 +73,7 @@ auto substitute(std::string attribute, Scope & scope) // NOTE: https://design.ros2.org/articles/roslaunch_xml.html#dynamic-configuration static const std::unordered_map< - std::string, std::function > + std::string, std::function > substitutions{ {"dirname", dirname}, // TODO {"env", env}, @@ -160,7 +157,8 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc } template -auto readAttribute(const std::string & name, const Node & node, const Scope & scope, T && value) -> T +auto readAttribute(const std::string & name, const Node & node, const Scope & scope, T && value) + -> T { if (node.attribute(name.c_str())) { return readAttribute(name, node, scope); @@ -178,13 +176,29 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc return std::optional(); } } - -extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; -extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; -extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Double; -extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> String; -extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; } // namespace reader -} // namespace openscenario_interpreter +struct Scope; + +inline namespace syntax +{ +struct Rule; +} // namespace syntax + +extern template auto substitute(std::string, const Scope &) -> String; + +extern template auto reader::readAttribute( + const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; +extern template auto reader::readAttribute( + const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedShort; +extern template auto reader::readAttribute( + const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; +extern template auto reader::readAttribute( + const std::string &, const pugi::xml_node &, const Scope &) -> Double; +extern template auto reader::readAttribute( + const std::string &, const pugi::xml_node &, const Scope &) -> String; +extern template auto reader::readAttribute( + const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; + +} // namespace openscenario_interpreter #endif // OPENSCENARIO_INTERPRETER__READER__ATTRIBUTE_HPP_ diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp index 6f9d6363ab4..827ffb6532a 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp @@ -72,7 +72,7 @@ auto traverse(const pugi::xml_node & parent, const std::string & name, F && f) - } template -auto readElement(const std::string & name, const pugi::xml_node & parent, Scope & scope) +auto readElement(const std::string & name, const pugi::xml_node & parent, Scope & scope) -> T { if (const auto child = parent.child(name.c_str())) { return T(child, scope); @@ -153,8 +153,29 @@ auto readGroups(const pugi::xml_node & node, Ts &&... xs) return groups; } -auto choice(const pugi::xml_node & node, std::unordered_map> callees) -> Object; +auto choice( + const pugi::xml_node & node, + std::unordered_map> callees) -> Object; } // namespace reader + +struct Scope; + +inline namespace syntax +{ +struct Orientation; +struct Position; +struct Properties; +struct Range; +} // namespace syntax + +extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Orientation; +extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Position; +extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Properties; +extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Range; } // namespace openscenario_interpreter #endif // OPENSCENARIO_INTERPRETER__READER__ELEMENT_HPP_ diff --git a/openscenario/openscenario_interpreter/src/reader/attribute.cpp b/openscenario/openscenario_interpreter/src/reader/attribute.cpp index 6393edd76d7..7caf781272d 100644 --- a/openscenario/openscenario_interpreter/src/reader/attribute.cpp +++ b/openscenario/openscenario_interpreter/src/reader/attribute.cpp @@ -1,13 +1,21 @@ #include +#include +#include namespace openscenario_interpreter { -inline namespace reader -{ -template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; -template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; -template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Double; -template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> String; -template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; -} -} +template auto reader::substitute(std::string, const Scope &) -> String; + +template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> Boolean; +template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> UnsignedShort; +template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> UnsignedInteger; +template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> Double; +template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> String; +template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> syntax::Rule; +} // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/src/reader/element.cpp b/openscenario/openscenario_interpreter/src/reader/element.cpp index 47dc74cff40..8c9a3b5e720 100644 --- a/openscenario/openscenario_interpreter/src/reader/element.cpp +++ b/openscenario/openscenario_interpreter/src/reader/element.cpp @@ -1,10 +1,24 @@ #include +#include +#include +#include +#include +#include namespace openscenario_interpreter { -inline namespace reader -{ -auto choice(const pugi::xml_node & node, std::unordered_map> callees) -> Object +template auto reader::readElement( + const std::string &, const pugi::xml_node &, Scope &) -> syntax::Orientation; +template auto reader::readElement( + const std::string &, const pugi::xml_node &, Scope &) -> syntax::Position; +template auto reader::readElement( + const std::string &, const pugi::xml_node &, Scope &) -> syntax::Properties; +template auto reader::readElement( + const std::string &, const pugi::xml_node &, Scope &) -> syntax::Range; + +auto reader::choice( + const pugi::xml_node & node, + std::unordered_map> callees) -> Object { std::unordered_map specs{}; @@ -56,5 +70,4 @@ auto choice(const pugi::xml_node & node, std::unordered_map(*iter))(std::get<1>(*iter)); } } -} // namespace reader } // namespace openscenario_interpreter From 8fc9e2e18091b1c2884c431e86a3ff929919d893 Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Thu, 10 Oct 2024 15:49:31 +0900 Subject: [PATCH 09/10] Make `substitute()` non-templated to make build faster --- .../reader/attribute.hpp | 110 ++++-------------- .../reader/element.hpp | 39 ++++--- .../src/reader/attribute.cpp | 84 +++++++++++-- .../src/reader/element.cpp | 19 +-- 4 files changed, 125 insertions(+), 127 deletions(-) diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp index ce3bb3cd7cd..b75efc3d6d5 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp @@ -31,74 +31,16 @@ namespace openscenario_interpreter { -inline namespace reader -{ -template -auto substitute(std::string attribute, const Scope & scope) -> String -{ - auto dirname = [](auto &&, auto && scope) { return scope.dirname(); }; - - auto find_pkg_share = [](auto && package_name, const auto &) { - return ament_index_cpp::get_package_share_directory(package_name); - }; - - auto ros2 = [](auto && arguments, const auto &) { - auto remove_trailing_newline = [](auto && s) { - while (s.back() == '\n') { - s.pop_back(); - } - return s; - }; - if (auto && result = remove_trailing_newline(concealer::dollar("ros2 " + arguments)); - result.find('\n') != std::string::npos) { - throw SyntaxError( - "The substitution result by `$(ros2 ...)` must not contain a newline character. " - "You gave `$(ros2 ", - arguments, ")` and the result was ", - std::quoted(boost::replace_all_copy(result, "\n", "\\n")), - ", which is unacceptable for the reasons stated above."); - } else { - return result; - } - }; - - auto var = [](auto && name, const auto & scope) { - // TODO: Return the value of the launch configuration variable instead of the OpenSCENARIO parameter. - if (const auto found = scope.ref(name); found) { - return boost::lexical_cast(found); - } else { - return String(); - } - }; - - // NOTE: https://design.ros2.org/articles/roslaunch_xml.html#dynamic-configuration - static const std::unordered_map< - std::string, std::function > - substitutions{ - {"dirname", dirname}, - // TODO {"env", env}, - // TODO {"eval", eval}, - // TODO {"exec-in-package", exec_in_package}, - // TODO {"find-exec", find_exec}, - // TODO {"find-pkg-prefix", find_pkg_prefix}, - {"find-pkg-share", find_pkg_share}, - {"ros2", - ros2}, // NOTE: TIER IV extension (Not included in the ROS 2 Launch XML Substitution) - {"var", var}, - }; - - static const auto pattern = std::regex(R"((.*)\$\((([\w-]+)\s?([^\)]*))\)(.*))"); +struct Scope; - for (std::smatch result; std::regex_match(attribute, result, pattern);) { - if (const auto iter = substitutions.find(result.str(3)); iter != std::end(substitutions)) { - attribute = result.str(1) + std::get<1>(*iter)(result.str(4), scope) + result.str(5); - } else { - throw SyntaxError("Unknown substitution ", std::quoted(result.str(3)), " specified"); - } - } +inline namespace syntax +{ +struct Rule; +} // namespace syntax - return attribute; -} +inline namespace reader +{ +auto substitute(std::string attribute, const Scope & scope) -> String; template auto readAttribute(const std::string & name, const Node & node, const Scope & scope) -> T @@ -156,6 +98,19 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc } } +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> Boolean; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> UnsignedShort; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> UnsignedInteger; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> Double; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> String; +extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) + -> syntax::Rule; + template auto readAttribute(const std::string & name, const Node & node, const Scope & scope, T && value) -> T @@ -177,28 +132,5 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc } } } // namespace reader - -struct Scope; - -inline namespace syntax -{ -struct Rule; -} // namespace syntax - -extern template auto substitute(std::string, const Scope &) -> String; - -extern template auto reader::readAttribute( - const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; -extern template auto reader::readAttribute( - const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedShort; -extern template auto reader::readAttribute( - const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; -extern template auto reader::readAttribute( - const std::string &, const pugi::xml_node &, const Scope &) -> Double; -extern template auto reader::readAttribute( - const std::string &, const pugi::xml_node &, const Scope &) -> String; -extern template auto reader::readAttribute( - const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; - } // namespace openscenario_interpreter #endif // OPENSCENARIO_INTERPRETER__READER__ATTRIBUTE_HPP_ diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp index 827ffb6532a..ad208b4df95 100644 --- a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp +++ b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/element.hpp @@ -36,6 +36,17 @@ namespace openscenario_interpreter { + +struct Scope; + +inline namespace syntax +{ +struct Orientation; +struct Position; +struct Properties; +struct Range; +} // namespace syntax + inline namespace reader { using Cardinality = @@ -89,6 +100,15 @@ auto readElement(const std::string & name, const pugi::xml_node & parent, Scope } } +extern template auto readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Orientation; +extern template auto readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Position; +extern template auto readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Properties; +extern template auto readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Range; + template auto readElement(const std::string & name, const pugi::xml_node & parent, Scope & scope, U && value) { @@ -157,25 +177,6 @@ auto choice( const pugi::xml_node & node, std::unordered_map> callees) -> Object; } // namespace reader - -struct Scope; - -inline namespace syntax -{ -struct Orientation; -struct Position; -struct Properties; -struct Range; -} // namespace syntax - -extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) - -> syntax::Orientation; -extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) - -> syntax::Position; -extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) - -> syntax::Properties; -extern template auto reader::readElement(const std::string &, const pugi::xml_node &, Scope &) - -> syntax::Range; } // namespace openscenario_interpreter #endif // OPENSCENARIO_INTERPRETER__READER__ELEMENT_HPP_ diff --git a/openscenario/openscenario_interpreter/src/reader/attribute.cpp b/openscenario/openscenario_interpreter/src/reader/attribute.cpp index 7caf781272d..a2a6e33ccce 100644 --- a/openscenario/openscenario_interpreter/src/reader/attribute.cpp +++ b/openscenario/openscenario_interpreter/src/reader/attribute.cpp @@ -4,18 +4,82 @@ namespace openscenario_interpreter { -template auto reader::substitute(std::string, const Scope &) -> String; +inline namespace reader +{ +auto substitute(std::string attribute, const Scope & scope) -> String +{ + auto dirname = [](auto &&, auto && scope) { return scope.dirname(); }; + + auto find_pkg_share = [](auto && package_name, const auto &) { + return ament_index_cpp::get_package_share_directory(package_name); + }; + + auto ros2 = [](auto && arguments, const auto &) { + auto remove_trailing_newline = [](auto && s) { + while (s.back() == '\n') { + s.pop_back(); + } + return s; + }; + if (auto && result = remove_trailing_newline(concealer::dollar("ros2 " + arguments)); + result.find('\n') != std::string::npos) { + throw SyntaxError( + "The substitution result by `$(ros2 ...)` must not contain a newline character. " + "You gave `$(ros2 ", + arguments, ")` and the result was ", + std::quoted(boost::replace_all_copy(result, "\n", "\\n")), + ", which is unacceptable for the reasons stated above."); + } else { + return result; + } + }; + + auto var = [](auto && name, const auto & scope) { + // TODO: Return the value of the launch configuration variable instead of the OpenSCENARIO parameter. + if (const auto found = scope.ref(name); found) { + return boost::lexical_cast(found); + } else { + return String(); + } + }; + + // NOTE: https://design.ros2.org/articles/roslaunch_xml.html#dynamic-configuration + static const std::unordered_map< + std::string, std::function > + substitutions{ + {"dirname", dirname}, + // TODO {"env", env}, + // TODO {"eval", eval}, + // TODO {"exec-in-package", exec_in_package}, + // TODO {"find-exec", find_exec}, + // TODO {"find-pkg-prefix", find_pkg_prefix}, + {"find-pkg-share", find_pkg_share}, + {"ros2", + ros2}, // NOTE: TIER IV extension (Not included in the ROS 2 Launch XML Substitution) + {"var", var}, + }; + + static const auto pattern = std::regex(R"((.*)\$\((([\w-]+)\s?([^\)]*))\)(.*))"); + + for (std::smatch result; std::regex_match(attribute, result, pattern);) { + if (const auto iter = substitutions.find(result.str(3)); iter != std::end(substitutions)) { + attribute = result.str(1) + std::get<1>(*iter)(result.str(4), scope) + result.str(5); + } else { + throw SyntaxError("Unknown substitution ", std::quoted(result.str(3)), " specified"); + } + } + + return attribute; +} -template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) - -> Boolean; -template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Boolean; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedShort; -template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> UnsignedInteger; -template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) - -> Double; -template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) - -> String; -template auto reader::readAttribute(const std::string &, const pugi::xml_node &, const Scope &) +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Double; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> String; +template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> syntax::Rule; +} // namespace reader } // namespace openscenario_interpreter diff --git a/openscenario/openscenario_interpreter/src/reader/element.cpp b/openscenario/openscenario_interpreter/src/reader/element.cpp index 8c9a3b5e720..c2d80aa8c80 100644 --- a/openscenario/openscenario_interpreter/src/reader/element.cpp +++ b/openscenario/openscenario_interpreter/src/reader/element.cpp @@ -7,16 +7,16 @@ namespace openscenario_interpreter { -template auto reader::readElement( - const std::string &, const pugi::xml_node &, Scope &) -> syntax::Orientation; -template auto reader::readElement( - const std::string &, const pugi::xml_node &, Scope &) -> syntax::Position; -template auto reader::readElement( - const std::string &, const pugi::xml_node &, Scope &) -> syntax::Properties; -template auto reader::readElement( - const std::string &, const pugi::xml_node &, Scope &) -> syntax::Range; +inline namespace reader +{ +template auto readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Orientation; +template auto readElement(const std::string &, const pugi::xml_node &, Scope &) -> syntax::Position; +template auto readElement(const std::string &, const pugi::xml_node &, Scope &) + -> syntax::Properties; +template auto readElement(const std::string &, const pugi::xml_node &, Scope &) -> syntax::Range; -auto reader::choice( +auto choice( const pugi::xml_node & node, std::unordered_map> callees) -> Object { @@ -70,4 +70,5 @@ auto reader::choice( return callees.at(std::get<0>(*iter))(std::get<1>(*iter)); } } +} // namespace reader } // namespace openscenario_interpreter From c47b8b31c65feeacaa4a77fea945f796fcc0aa79 Mon Sep 17 00:00:00 2001 From: Shota Minami Date: Thu, 10 Oct 2024 17:12:22 +0900 Subject: [PATCH 10/10] Add missing copyright notice --- .../src/reader/attribute.cpp | 14 ++++++++++++++ .../src/reader/element.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/openscenario/openscenario_interpreter/src/reader/attribute.cpp b/openscenario/openscenario_interpreter/src/reader/attribute.cpp index a2a6e33ccce..c04707b7fbc 100644 --- a/openscenario/openscenario_interpreter/src/reader/attribute.cpp +++ b/openscenario/openscenario_interpreter/src/reader/attribute.cpp @@ -1,3 +1,17 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include diff --git a/openscenario/openscenario_interpreter/src/reader/element.cpp b/openscenario/openscenario_interpreter/src/reader/element.cpp index c2d80aa8c80..d773084ccc7 100644 --- a/openscenario/openscenario_interpreter/src/reader/element.cpp +++ b/openscenario/openscenario_interpreter/src/reader/element.cpp @@ -1,3 +1,17 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include