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

◆ read()

template<Described Input, typename Source, typename Access = RecordAccess<Source>>
std::optional< Input > MayaFlux::Reflect::RecordBinding< Input, Source, Access >::read ( const Source & source,
std::string & error,
uint64_t * error_location = nullptr ) const
inlinenodiscard

Decode the source element into a new Input.

Parameters
error_locationReceives the position of the failing element when given.

Definition at line 160 of file RecordBinding.hpp.

162 {
163 if (error_location)
165 for (const auto& name : m_required) {
167 error = "<" + label(source) + "> needs a " + name + " attribute";
168 return std::nullopt;
169 }
170 }
171
172 Input input {};
174 [&](const auto& visit) {
177 return is_ignored(name) || visit(name, value);
178 });
179 }, label(source), error);
180 if (!overlaid)
181 return std::nullopt;
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
187 || (!binding.defaults_name.empty() && child_name == binding.defaults_name);
188 });
189 if (known)
190 return true;
191 if (error_location)
193 error = "<" + std::string(child_name) + "> is not allowed in <"
195 return false;
196 });
197 if (!known_children)
198 return std::nullopt;
199 for (const ChildBinding& binding : m_children) {
200 if (!binding.decode(input, source, error, error_location))
201 return std::nullopt;
202 }
203 return input;
204 }
bool is_ignored(std::string_view name) const
static std::string label(const Source &source)
std::vector< std::string > m_ignored_children
std::vector< std::string > m_required
std::vector< ChildBinding > m_children
Bind described attributes and configured child collections of a source element.
bool overlay_text_fields(T &target, Fields &&fields, std::string_view label, std::string &error)
Overlay named text values onto a described value.

References MayaFlux::Reflect::RecordBinding< Input, Source, Access >::ChildBinding::defaults_name, is_ignored(), label(), m_children, m_ignored_children, m_required, MayaFlux::Reflect::RecordBinding< Input, Source, Access >::ChildBinding::name, and MayaFlux::Reflect::overlay_text_fields().

Referenced by MayaFlux::IO::collect_records(), and MayaFlux::Portal::Forma::ActionTable< Source, Access >::expose_typed().

Here is the call graph for this function:
Here is the caller graph for this function: