object-introspection/types/std_map_type.toml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.9 KiB
TOML
Raw Normal View History

2022-12-19 14:37:51 +00:00
[info]
type_name = "std::map"
stub_template_params = [2,3]
2022-12-19 14:37:51 +00:00
ctype = "STD_MAP_TYPE"
header = "map"
# Old:
typeName = "std::map<"
2022-12-19 14:37:51 +00:00
ns = ["namespace std"]
numTemplateParams = 2
2022-12-19 14:37:51 +00:00
replaceTemplateParamIndex = [2]
allocatorIndex = 3
[codegen]
decl = """
template<class K, class T, class C, class A>
void getSizeType(const %1%<K, T, C, A> &container, size_t& returnArg);
"""
func = """
template<class K, class T, class C, class A>
void getSizeType(const %1%<K, T, C, A> &container, size_t& returnArg)
{
constexpr size_t nodeSize = sizeof(typename %1%<K, T, C, A>::node_type);
size_t numElems = container.size();
SAVE_SIZE(sizeof(%1%<K, T, C, A>) + (nodeSize * numElems));
SAVE_DATA((uintptr_t)nodeSize);
SAVE_DATA((uintptr_t)numElems);
for (auto const& it : container)
{
getSizeType(it.first, returnArg);
getSizeType(it.second, returnArg);
}
}
"""
handler = """
template <typename DB, typename T0, typename T1, typename T2, typename T3>
struct TypeHandler<DB, %1%<T0, T1, T2, T3>> {
using type = types::st::Pair<DB,
types::st::VarInt<DB>,
types::st::List<DB, types::st::Pair<DB,
typename TypeHandler<DB, T0>::type,
typename TypeHandler<DB, T1>::type
>>>;
static types::st::Unit<DB> getSizeType(
const %1%<T0, T1, T2, T3>& container,
typename TypeHandler<DB, %1%<T0, T1, T2, T3>>::type returnArg) {
constexpr size_t nodeSize = sizeof(typename %1%<T0, T1, T2, T3>::node_type);
auto tail = returnArg.write(nodeSize).write(container.size());
// The double ampersand is needed otherwise this loop doesn't work with
// vector<bool>
for (const auto& it : container) {
tail = tail.delegate([&it](auto ret) {
return OIInternal::getSizeType<DB>(it.second, ret.delegate([&it](auto ret) {
return OIInternal::getSizeType<DB>(it.first, ret);
}));
});
}
return tail.finish();
}
};
"""