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

◆ call_described()

template<auto Function, typename Source, typename Access>
std::optional< typename FunctionTraits< decltype(Function)>::Result > MayaFlux::Portal::Forma::Detail::call_described ( const Source & call,
std::string & error )

Calls a described function with the arguments an element's attributes give by parameter name.

Arguments are the leading parameters, as in C++: a trailing run may be left to the function's own defaults, which the sidecar's call applies because it calls by name, and a later parameter cannot be given while an earlier one is skipped.

Definition at line 96 of file CallTable.hpp.

98 {
99 using Traits = FunctionTraits<decltype(Function)>;
100 using Result = typename Traits::Result;
101 using Values = typename Traits::Values;
102 using Description = Reflect::Generated::Signature<Function>;
103 constexpr size_t count = Traits::count;
104 constexpr size_t required = Description::required;
105 static_assert(Description::parameters.size() == count, "the sidecar does not describe this function");
106
107 const bool known = Access::for_each_attribute(call, [&](std::string_view name, std::string_view) {
108 if (name == reserved_call_attribute
109 || std::ranges::find(Description::parameters, name) != Description::parameters.end()) {
110 return true;
111 }
112 error = Reflect::located_message(Access::location(call),
113 "<" + std::string(Access::name(call)) + "> has an unsupported attribute " + std::string(name)
114 + " for " + std::string(Description::name));
115 return false;
116 });
117 if (!known)
118 return std::nullopt;
119
120 Values values {};
121 std::array<bool, count> given {};
122 bool decoded = true;
123 [&]<size_t... I>(std::index_sequence<I...>) {
124 ((decoded = decoded && decode_parameter<Function, Source, Access, I>(call, values, given, error)), ...);
125 }(std::make_index_sequence<count> {});
126 if (!decoded)
127 return std::nullopt;
128
129 size_t provided = 0;
130 while (provided < count && given[provided])
131 ++provided;
132 for (size_t i = provided + 1; i < count; ++i) {
133 if (given[i]) {
134 error = Reflect::located_message(Access::location(call),
135 std::string(Description::parameters[i]) + " is given without "
136 + std::string(Description::parameters[provided]));
137 return std::nullopt;
138 }
139 }
140 if (provided < required) {
141 error = Reflect::located_message(Access::location(call),
142 std::string(Description::name) + " needs " + std::string(Description::parameters[provided]));
143 return std::nullopt;
144 }
145
146 std::optional<Result> result;
147 [&]<size_t... N>(std::index_sequence<N...>) {
148 ((provided == required + N
149 ? (result.emplace(Description::template call<required + N>(values)), true)
150 : false)
151 || ...);
152 }(std::make_index_sequence<count - required + 1> {});
153 return result;
154 }
void error(Component component, Context context, std::source_location location, std::string_view message)
Log an error message and optionally throw an exception.
std::vector< double > count(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sample count per window (as double for pipeline uniformity).
Definition Analysis.cpp:506
bool decode_parameter(const Source &call, Values &values, std::array< bool, std::tuple_size_v< Values > > &given, std::string &error)
Definition CallTable.hpp:62
constexpr std::string_view reserved_call_attribute
Attribute of a form element that names the function it calls.
Definition CallTable.hpp:14
std::string located_message(uint64_t location, std::string_view message)
A diagnostic message prefixed with the location of the element it concerns.
The parameter names of a described function, which C++ cannot supply itself.
Definition Describe.hpp:52

References decode_parameter(), MayaFlux::Reflect::located_message(), and MayaFlux::Portal::Forma::reserved_call_attribute.

Here is the call graph for this function: