MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ repeated()

template<Reflect::Described Input, typename Node, typename Access = XmlRecordAccess<Node>>
template<auto Pointer>
XmlRecordBinding & MayaFlux::IO::XmlRecordBinding< Input, Node, Access >::repeated ( std::string child_name,
std::string defaults_name = {},
std::string required_item_attribute = {},
size_t minimum = 0 )
inline

Definition at line 63 of file XmlRecordBinding.hpp.

64 {},
66 size_t minimum = 0)
67 {
69 using Item = typename Values::value_type;
71 static_assert(Reflect::Described<Item>);
72
75 binding.defaults_name = std::move(defaults_name);
76 binding.decode = [name = binding.name, defaults_name = binding.defaults_name,
80 Item defaults {};
81 bool defaults_seen = false;
82 size_t count = 0;
83 auto& values = input.*Pointer;
84 const bool traversed = Access::for_each_child(node, [&](const Node& child) {
85 if (error_row)
87
88 const auto child_name = Access::name(child);
89 if (!defaults_name.empty() && child_name == defaults_name) {
90 if (defaults_seen || count != 0) {
91 error = "<" + defaults_name + "> must appear once before the "
92 + name + " children";
93 return false;
94 }
95 defaults_seen = true;
96 if (!required_item_attribute.empty()
98 error = "<" + defaults_name + "> has an unsupported attribute "
100 return false;
101 }
102 if (has_children(child)) {
103 error = "<" + defaults_name + "> may not have children";
104 return false;
105 }
106 return overlay(defaults, child, error);
107 }
108 if (child_name != name)
109 return true;
110 if (!required_item_attribute.empty()
112 error = "<" + label(child) + "> needs a "
113 + required_item_attribute + " attribute";
114 return false;
115 }
116 if (has_children(child)) {
117 error = "<" + name + "> may not have children";
118 return false;
119 }
121 if (!overlay(item, child, error))
122 return false;
123 values.push_back(std::move(item));
124 ++count;
125 return true;
126 });
127 if (!traversed)
128 return false;
129 if (count < minimum) {
130 if (error_row)
132 error = "<" + std::string(Access::name(node)) + "> needs at least "
133 + std::to_string(minimum) + " " + name + " children";
134 return false;
135 }
136 return true;
137 };
138 m_children.push_back(std::move(binding));
139 return *this;
140 }
static bool has_children(const Node &node)
std::vector< ChildBinding > m_children
static bool overlay(T &target, const Node &node, std::string &error)
static std::string label(const Node &node)
Bind described attributes and configured XML child collections.