object-introspection/types/cxx11_string_type.toml
2023-06-30 12:54:02 +01:00

56 lines
1.6 KiB
TOML

[info]
type_name = "std::__cxx11::basic_string"
stub_template_params = [2]
ctype = "STRING_TYPE"
header = "string"
# Old:
typeName = "std::__cxx11::basic_string<"
ns = ["namespace std"]
numTemplateParams = 1
replaceTemplateParamIndex = []
[codegen]
decl = """
template<typename T, typename Traits, typename Allocator>
void getSizeType(const %1%<T, Traits, Allocator> &container, size_t& returnArg);
"""
func = """
template<typename T, typename Traits, typename Allocator>
void getSizeType(const %1%<T, Traits, Allocator> &container, size_t& returnArg)
{
SAVE_SIZE(sizeof(%1%<T>));
SAVE_DATA((uintptr_t)container.capacity());
SAVE_DATA((uintptr_t)container.size());
// Test for small string optimisation - whether the underlying string is
// contained within the string object.
SAVE_SIZE(
(((uintptr_t)container.data() < (uintptr_t)(&container + sizeof(%1%<T>)))
&&
((uintptr_t)container.data() >= (uintptr_t)&container))
? 0 : (container.capacity() * sizeof(T))
);
}
"""
handler = """
template <typename DB, typename T0>
struct TypeHandler<DB, %1% <T0>> {
using type =
types::st::Pair<DB, types::st::VarInt<DB>, types::st::VarInt<DB>>;
static types::st::Unit<DB> getSizeType(
const %1% <T0> & container,
typename TypeHandler<DB, %1% <T0>>::type returnArg) {
bool sso = ((uintptr_t)container.data() <
(uintptr_t)(&container + sizeof(%1% <T0>))) &&
((uintptr_t)container.data() >= (uintptr_t)&container);
return returnArg.write(container.capacity()).write(container.size());
}
};
"""