object-introspection/types/array_type.toml
2023-08-29 17:41:10 +01:00

76 lines
1.9 KiB
TOML

[info]
type_name = "std::array"
ctype = "ARRAY_TYPE"
header = "array"
# Old:
numTemplateParams = 1
ns = ["namespace std"]
typeName = "std::array<"
[codegen]
decl = """
template<typename T, long unsigned int N>
void getSizeType(const %1%<T, N> &container, size_t& returnArg);
"""
func = """
template<typename T, long unsigned int N>
void getSizeType(const %1%<T,N> &container, size_t& returnArg)
{
SAVE_DATA((uintptr_t)container.size());
SAVE_SIZE(sizeof(container));
for (auto & it: container) {
// undo the static size that has already been added per-element
SAVE_SIZE(-sizeof(it));
getSizeType(it, returnArg);
}
}
"""
handler = """
template<typename DB, typename T0, long unsigned int N>
struct TypeHandler<DB, %1%<T0, N>> {
using type = types::st::List<DB, typename TypeHandler<DB, T0>::type>;
static types::st::Unit<DB> getSizeType(
const %1%<T0, N> &container,
typename TypeHandler<DB, %1%<T0,N>>::type returnArg) {
auto tail = returnArg.write(container.size());
for (auto & it: container) {
tail = tail.delegate([&it](auto ret) {
return TypeHandler<DB, T0>::getSizeType(it, ret);
});
}
return tail.finish();
}
};
"""
traversal_func = """
auto tail = returnArg.write(container.size());
for (auto & it: container) {
tail = tail.delegate([&it](auto ret) {
return TypeHandler<DB, T0>::getSizeType(it, ret);
});
}
return tail.finish();
"""
[[codegen.processor]]
type = "types::st::List<DB, typename TypeHandler<DB, T0>::type>"
func = """
static constexpr auto childField = make_field<DB, T0>("[]");
size_t size = std::get<ParsedData::List>(d.val).length;
el.exclusive_size = N0 == 0 ? 1 : 0;
el.container_stats.emplace(result::Element::ContainerStats{ .capacity = size, .length = size });
for (size_t i = 0; i < size; i++)
ins.emplace(childField);
"""