15 #ifndef OPENSCENARIO_INTERPRETER__READER__ATTRIBUTE_HPP_ 
   16 #define OPENSCENARIO_INTERPRETER__READER__ATTRIBUTE_HPP_ 
   18 #include <ament_index_cpp/get_package_share_directory.hpp> 
   19 #include <boost/algorithm/string/replace.hpp> 
   26 #include <pugixml.hpp> 
   30 #include <unordered_map> 
   36 inline namespace syntax
 
   41 inline namespace reader
 
   45 template <
typename T, 
typename Node, 
typename Scope>
 
   48   auto is_openscenario_standard_expression = [](
const auto & s) {
 
   49     return s.substr(0, 2) == 
"${" and s.back() == 
'}';
 
   52   auto read_openscenario_standard_expression = [&](
const auto & s) {
 
   53     return boost::lexical_cast<T>(
evaluate(
std::string(std::begin(s) + 2, std::end(s) - 1), scope));
 
   56   auto is_openscenario_standard_parameter_reference = [](
const auto & s) {
 
   57     return s.front() == 
'$';
 
   60   auto read_openscenario_standard_parameter_reference = [&](
const auto & s) {
 
   62     if (
auto && 
object = scope.
ref(s.substr(1)); object) {
 
   63       return boost::lexical_cast<T>(boost::lexical_cast<String>(
object));
 
   66         "There is no parameter named ", std::quoted(s.substr(1)), 
" (Attribute ", std::quoted(name),
 
   67         " of class ", std::quoted(node.name()), 
" references this parameter)");
 
   71   auto read_openscenario_standard_literal = [&](
const auto & s) {
 
   73       return boost::lexical_cast<T>(s);
 
   74     } 
catch (
const boost::bad_lexical_cast &) {
 
   76         "Value ", std::quoted(s), 
" specified for attribute ", std::quoted(name),
 
   77         " is invalid (Is not value of type ", 
makeTypename(
typeid(T)), 
")");
 
   83   if (
const auto & attribute = node.attribute(name.c_str())) {
 
   87     } 
else if (is_openscenario_standard_expression(value)) {
 
   88       return read_openscenario_standard_expression(value);
 
   89     } 
else if (is_openscenario_standard_parameter_reference(value)) {
 
   90       return read_openscenario_standard_parameter_reference(value);
 
   92       return read_openscenario_standard_literal(value);
 
   96       "Required attribute ", std::quoted(name), 
" not specified for class ",
 
   97       std::quoted(node.name()));
 
  114 template <
typename T, 
typename Node, 
typename Scope>
 
  118   if (node.attribute(name.c_str())) {
 
  119     return readAttribute<T>(name, node, scope);
 
  125 template <
typename T, 
typename Node, 
typename Scope>
 
  128   if (node.attribute(name.c_str())) {
 
  129     return std::make_optional(readAttribute<T>(name, node, scope));
 
  131     return std::optional<T>();
 
Definition: scope.hpp:155
auto ref(Ts &&... xs) const -> decltype(auto)
Definition: scope.hpp:211
auto readAttribute(const std::string &name, const Node &node, const Scope &scope) -> T
Definition: attribute.hpp:46
std::string evaluate(const std::string &, const Scope &)
Definition: evaluate.cpp:237
auto substitute(const std::string &attribute, const Scope &scope) -> String
Definition: attribute.cpp:23
std::string String
Definition: string.hpp:24
auto makeTypename(Ts &&... xs)
Definition: demangle.hpp:30
std::string string
Definition: junit5.hpp:26
Definition: boolean.hpp:26
Definition: double.hpp:25
Definition: unsigned_integer.hpp:27
Definition: unsigned_short.hpp:26