diff --git a/openscenario/openscenario_interpreter/CMakeLists.txt b/openscenario/openscenario_interpreter/CMakeLists.txt index 72ac634e062..a83c6e60bbd 100644 --- a/openscenario/openscenario_interpreter/CMakeLists.txt +++ b/openscenario/openscenario_interpreter/CMakeLists.txt @@ -54,11 +54,13 @@ ament_export_include_directories(${boost_json_SOURCE_DIR}/include) 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 diff --git a/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp b/openscenario/openscenario_interpreter/include/openscenario_interpreter/reader/attribute.hpp index 945e1a346a3..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, Scope & scope) -{ - auto dirname = [](auto &&, auto && scope) { return scope.dirname(); }; +struct Scope; - auto find_pkg_share = [](auto && package_name, auto &&) { - return ament_index_cpp::get_package_share_directory(package_name); - }; - - auto ros2 = [](auto && arguments, 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, 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"); - } - } +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,8 +98,22 @@ 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 { if (node.attribute(name.c_str())) { return readAttribute(name, node, scope); @@ -177,5 +133,4 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc } } // namespace reader } // 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 7ff746d4981..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 = @@ -72,7 +83,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); @@ -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) { @@ -153,62 +173,9 @@ 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/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/reader/attribute.cpp b/openscenario/openscenario_interpreter/src/reader/attribute.cpp new file mode 100644 index 00000000000..c04707b7fbc --- /dev/null +++ b/openscenario/openscenario_interpreter/src/reader/attribute.cpp @@ -0,0 +1,99 @@ +// 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 + +namespace openscenario_interpreter +{ +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 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 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; +} // 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..d773084ccc7 --- /dev/null +++ b/openscenario/openscenario_interpreter/src/reader/element.cpp @@ -0,0 +1,88 @@ +// 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 +#include +#include +#include + +namespace openscenario_interpreter +{ +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 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 8b5c21794d4..b0e2a45997b 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 e70d6443a76..a160c63de16 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..448532e6d08 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..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 @@ -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/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(); diff --git a/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp b/openscenario/openscenario_interpreter/src/syntax/distribution_definition.cpp index 7499024a894..12f57f28bb8 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..e7ee14526c2 100644 --- a/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp +++ b/openscenario/openscenario_interpreter/src/syntax/open_scenario_category.cpp @@ -22,12 +22,13 @@ namespace openscenario_interpreter inline namespace syntax { OpenScenarioCategory::OpenScenarioCategory(const pugi::xml_node & tree, Scope & scope) +// clang-format off : 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);}))) + 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 { } 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..d659304845b 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 { }