15 #ifndef OPENSCENARIO_INTERPRETER__READER__ELEMENT_HPP_ 
   16 #define OPENSCENARIO_INTERPRETER__READER__ELEMENT_HPP_ 
   24 #include <pugixml.hpp> 
   26 #include <type_traits> 
   27 #include <unordered_map> 
   41 inline namespace syntax
 
   49 inline namespace reader
 
   52   typename std::iterator_traits<typename pugi::xml_node::iterator>::difference_type;
 
   54 constexpr 
auto unbounded = std::numeric_limits<Cardinality>::max();
 
   56 template <Cardinality MinOccurs, Cardinality MaxOccurs, 
typename F>
 
   59   const auto children = parent.children(name.c_str());
 
   62     if (MinOccurs != 0 and 
size < MinOccurs) {
 
   64         parent.name(), 
" requires class ", name, 
" at least ", MinOccurs, 
" element",
 
   65         (1 < MinOccurs ? 
"s" : 
""), 
", but ", 
size, 
" element", (1 < 
size ? 
"s" : 
""),
 
   67     } 
else if (MaxOccurs < 
size) {
 
   69         parent.name(), 
" requires class ", name, 
" at most ", MaxOccurs, 
" element",
 
   70         (1 < MaxOccurs ? 
"s" : 
""), 
", but ", 
size, 
" element", (1 < 
size ? 
"s" : 
""),
 
   73       for (
const auto & child : children) {
 
   77   } 
else if (MinOccurs != 0) {
 
   79       parent.name(), 
" requires class ", name, 
" at least ", MinOccurs, 
" element",
 
   80       (1 < MinOccurs ? 
"s" : 
""), 
", but there is no specification");
 
   84 template <
typename T, 
typename Scope>
 
   87   if (
const auto child = parent.child(name.c_str())) {
 
   88     return T(child, scope);
 
   98       parent.name(), 
" requires class ", name, 
" as element, but there is no declaration"));
 
  103   -> syntax::Orientation;
 
  107   -> syntax::Properties;
 
  111 template <
typename T, 
typename U, 
typename Scope>
 
  114   if constexpr (std::is_same<T, 
typename std::decay<U>::type>::value) {
 
  117     if (
const auto child = parent.child(name.c_str())) {
 
  118       return T(child, scope);
 
  124     if (
const auto child = parent.child(name.c_str())) {
 
  125       return T(child, scope, value);
 
  128         parent.name(), 
" requires class ", name, 
" as element, but there is no declaration"));
 
  136   std::list<T> elements;
 
  138   traverse<MinOccurs, MaxOccurs>(node, name, [&](
auto && x) {
 
  139     elements.emplace_back(std::forward<decltype(x)>(x), std::forward<decltype(
xs)>(
xs)...);
 
  148   std::list<GroupT> groups;
 
  150   for (
auto child = node.begin(); child != node.end(); ++child) {
 
  152       groups.template emplace_back(
 
  153         std::forward<decltype(*child)>(*child), std::forward<decltype(
xs)>(
xs)...);
 
  158   if (MinOccurs != 0 and groups.size() < MinOccurs) {
 
  160       node.name(), 
" requires Group ", 
demangle(
typeid(GroupT)), 
" at least ", MinOccurs,
 
  161       " element", (1 < MinOccurs ? 
"s" : 
""), 
", but ", groups.size(), 
" element",
 
  162       (1 < groups.size() ? 
"s" : 
""), 
" specified");
 
  165   if (MaxOccurs < groups.size()) {
 
  167       node.name(), 
" requires Group ", 
demangle(
typeid(GroupT)), 
" at most ", MaxOccurs, 
" element",
 
  168       (1 < MaxOccurs ? 
"s" : 
""), 
", but ", groups.size(), 
" element",
 
  169       (1 < groups.size() ? 
"s" : 
""), 
" specified");
 
  176   const pugi::xml_node & node,
 
  177   const std::unordered_map<
std::string, std::function<
Object(
const pugi::xml_node &)>> & callees)
 
Definition: scope.hpp:155
auto size(const T &range)
Definition: size.hpp:25
auto readElement(const std::string &name, const pugi::xml_node &parent, Scope &scope) -> T
Definition: element.hpp:85
auto choice(const pugi::xml_node &node, const std::unordered_map< std::string, std::function< Object(const pugi::xml_node &)>> &callees) -> Object
Definition: element.cpp:33
auto readElements(const std::string &name, const pugi::xml_node &node, Ts &&... xs)
Definition: element.hpp:134
auto traverse(const pugi::xml_node &parent, const std::string &name, F &&f) -> void
Definition: element.hpp:57
typename std::iterator_traits< typename pugi::xml_node::iterator >::difference_type Cardinality
Definition: element.hpp:52
constexpr auto unbounded
Definition: element.hpp:54
auto readGroups(const pugi::xml_node &node, Ts &&... xs)
Definition: element.hpp:146
auto demangle(const char *name) -> std::string
Definition: demangle.cpp:26
Pointer< Expression > Object
Definition: object.hpp:26
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: must_be_default_constructible.hpp:27