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

◆ check_reference()

template<typename Source, typename Access = RecordAccess<Source>, typename Exists>
std::optional< std::string_view > MayaFlux::Reflect::check_reference ( const Source & source,
std::string_view attribute,
Exists && exists,
std::string & error )
nodiscard

Check that an element's attribute names a value that exists.

Parameters
attributeName of the referring attribute, which also names what it refers to.
existsCallable taking the value and returning whether it is known, for instance AttributeIndex::contains or a lookup in any container.
errorReceives a located message when nullopt is returned: the attribute is missing, or its value is unknown.
Returns
The value of the attribute.

Definition at line 101 of file AttributeChecks.hpp.

103{
104 const auto value = Access::attribute(source, attribute);
105 if (!value) {
106 error = located_message(Access::location(source),
107 "<" + std::string(Access::name(source)) + "> needs a " + std::string(attribute) + " attribute");
108 return std::nullopt;
109 }
110 if (!std::invoke(std::forward<Exists>(exists), *value)) {
111 error = located_message(Access::location(source),
112 "<" + std::string(Access::name(source)) + "> refers to unknown " + std::string(attribute)
113 + " " + std::string(*value));
114 return std::nullopt;
115 }
116 return value;
117}
std::string located_message(uint64_t location, std::string_view message)
A diagnostic message prefixed with the location of the element it concerns.

References located_message().

Referenced by MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::check_instances().

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