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

◆ repeated()

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

Definition at line 77 of file RecordBinding.hpp.

78 {},
80 size_t minimum = 0)
81 {
83 using Item = typename Values::value_type;
85 static_assert(Described<Item>);
86
89 binding.defaults_name = std::move(defaults_name);
90 binding.decode = [name = binding.name, defaults_name = binding.defaults_name,
94 Item defaults {};
95 bool defaults_seen = false;
96 size_t count = 0;
97 auto& values = input.*Pointer;
98 const bool traversed = Access::for_each_child(source, [&](const Source& child) {
101
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";
107 return false;
108 }
109 defaults_seen = true;
110 if (!required_item_attribute.empty()
112 error = "<" + defaults_name + "> has an unsupported attribute "
114 return false;
115 }
116 if (has_children(child)) {
117 error = "<" + defaults_name + "> may not have children";
118 return false;
119 }
120 return overlay(defaults, child, error);
121 }
122 if (child_name != name)
123 return true;
124 if (!required_item_attribute.empty()
126 error = "<" + label(child) + "> needs a "
127 + required_item_attribute + " attribute";
128 return false;
129 }
130 if (has_children(child)) {
131 error = "<" + name + "> may not have children";
132 return false;
133 }
135 if (!overlay(item, child, error))
136 return false;
137 values.push_back(std::move(item));
138 ++count;
139 return true;
140 });
141 if (!traversed)
142 return false;
143 if (count < minimum) {
144 if (error_location)
146 error = "<" + std::string(Access::name(source)) + "> needs at least "
147 + std::to_string(minimum) + " " + name + " children";
148 return false;
149 }
150 return true;
151 };
152 m_children.push_back(std::move(binding));
153 return *this;
154 }
static std::string label(const Source &source)
static bool has_children(const Source &source)
static bool overlay(T &target, const Source &source, std::string &error)
std::vector< ChildBinding > m_children
Bind described attributes and configured child collections of a source element.