78 std::string defaults_name = {},
79 std::string required_item_attribute = {},
82 using Values = std::remove_cvref_t<decltype(std::declval<Input&>().*Pointer)>;
83 using Item =
typename Values::value_type;
84 static_assert(std::same_as<Values, std::vector<Item>>);
85 static_assert(Described<Item>);
88 binding.name = std::move(child_name);
89 binding.defaults_name = std::move(defaults_name);
90 binding.decode = [name = binding.name, defaults_name = binding.defaults_name,
91 required_item_attribute = std::move(required_item_attribute), minimum](
92 Input& input,
const Source& source, std::string& error,
93 uint64_t* error_location) {
95 bool defaults_seen =
false;
97 auto& values = input.*Pointer;
98 const bool traversed = Access::for_each_child(source, [&](
const Source& child) {
100 *error_location = Access::location(child);
102 const auto child_name = Access::name(child);
103 if (!defaults_name.empty() && child_name == defaults_name) {
104 if (defaults_seen || count != 0) {
105 error =
"<" + defaults_name +
"> must appear once before the "
106 + name +
" children";
109 defaults_seen =
true;
110 if (!required_item_attribute.empty()
111 && Access::attribute(child, required_item_attribute)) {
112 error =
"<" + defaults_name +
"> has an unsupported attribute "
113 + required_item_attribute;
117 error =
"<" + defaults_name +
"> may not have children";
120 return overlay(defaults, child, error);
122 if (child_name != name)
124 if (!required_item_attribute.empty()
125 && !Access::attribute(child, required_item_attribute)) {
127 + required_item_attribute +
" attribute";
131 error =
"<" + name +
"> may not have children";
134 Item item = defaults;
135 if (!
overlay(item, child, error))
137 values.push_back(std::move(item));
143 if (count < minimum) {
145 *error_location = Access::location(source);
146 error =
"<" + std::string(Access::name(source)) +
"> needs at least "
147 + std::to_string(minimum) +
" " + name +
" children";
160 [[nodiscard]] std::optional<Input>
read(
const Source& source,
161 std::string& error, uint64_t* error_location =
nullptr)
const
164 *error_location = Access::location(source);
166 if (!Access::attribute(source, name)) {
167 error =
"<" +
label(source) +
"> needs a " + name +
" attribute";
174 [&](
const auto& visit) {
175 return Access::for_each_attribute(source,
176 [&](std::string_view name, std::string_view value) {
177 return is_ignored(name) || visit(name, value);
179 },
label(source), error);
182 const bool known_children = Access::for_each_child(source, [&](
const Source& child) {
183 const auto child_name = Access::name(child);
186 return child_name == binding.
name
192 *error_location = Access::location(child);
193 error =
"<" + std::string(child_name) +
"> is not allowed in <"
194 + std::string(Access::name(source)) +
">";
200 if (!binding.decode(input, source, error, error_location))