24 template <
typename R,
typename... A>
27 using Values = std::tuple<std::remove_cvref_t<A>...>;
28 static constexpr size_t count =
sizeof...(A);
31 template <
typename R,
typename... A>
43 template <
typename Placer,
typename State>
46 return Placer([form = std::move(form), initial = std::move(initial)](
47 Surface& surface, std::string& error) -> std::optional<uint32_t> {
54 error =
"could not place the element";
57 return tend.
result->element.id;
61 template <auto Function,
typename Source,
typename Access,
size_t Index,
typename Values>
62 bool decode_parameter(
const Source& call, Values& values, std::array<
bool, std::tuple_size_v<Values>>& given,
66 using Parameter = std::tuple_element_t<Index, Values>;
68 const auto text = Access::attribute(call, Description::parameters[Index]);
75 "<" + std::string(Access::name(call)) +
"> has an invalid " + std::string(Description::parameters[Index])
76 +
" of " + std::string(*text));
83 std::string(Description::parameters[Index]) +
" of " + std::string(Description::name)
84 +
" cannot be written in a document");
95 template <auto Function,
typename Source,
typename Access>
97 const Source& call, std::string& error)
100 using Result =
typename Traits::Result;
101 using Values =
typename Traits::Values;
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");
107 const bool known = Access::for_each_attribute(call, [&](std::string_view name, std::string_view) {
109 || std::ranges::find(Description::parameters, name) != Description::parameters.end()) {
113 "<" + std::string(Access::name(call)) +
"> has an unsupported attribute " + std::string(name)
114 +
" for " + std::string(Description::name));
121 std::array<bool, count> given {};
123 [&]<
size_t... I>(std::index_sequence<I...>) {
125 }(std::make_index_sequence<count> {});
130 while (provided < count && given[provided])
132 for (
size_t i = provided + 1; i < count; ++i) {
135 std::string(Description::parameters[i]) +
" is given without "
136 + std::string(Description::parameters[provided]));
140 if (provided < required) {
142 std::string(Description::name) +
" needs " + std::string(Description::parameters[provided]));
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)
152 }(std::make_index_sequence<count - required + 1> {});
180template <
typename Source,
typename Access = Reflect::RecordAccess<Source>>
191 using Maker = std::function<std::optional<Placer>(
192 const Source&,
const Source&,
const ElementHit&, std::string&)>;
199 template <auto Function>
208 name = std::string(full.substr(full.rfind(
"::") == std::string_view::npos ? 0 : full.rfind(
"::") + 2));
212 Maker([](
const Source& call,
const Source& element,
const ElementHit& hit,
213 std::string& error) -> std::optional<Placer> {
223 "<" + std::string(Access::name(element)) +
"> has an invalid state of " + std::string(*text));
234 bool merge(
const CallTable& other, std::string_view prefix, std::string& error,
bool replace =
false)
239 [[nodiscard]]
bool contains(std::string_view name)
const
245 [[nodiscard]] std::vector<std::string>
names()
const
247 std::vector<std::string> result;
249 result.push_back(entry.first);
254 [[nodiscard]]
const Maker*
find(std::string_view name)
const
256 const auto found =
m_makers.find(name);
257 return found ==
m_makers.end() ? nullptr : &found->second;
bool insert_or_assign(const K &key, V value)
Sets the value for key, adding the entry if it is absent.
Map kept as one sorted vector, cheap to copy.
A function pointer whose generated sidecar defines Generated::Signature<Function>.
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.
Conversion of authored text to one value type.