mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
68290655b1
This change is fully backwards compatible with the old ContainerInfo parser, as it is just adding new fields. The old fields will continue to be used by legacy OICodeGen until that is removed. Also add a README to document the format.
38 lines
965 B
TOML
38 lines
965 B
TOML
[info]
|
|
type_name = "std::variant"
|
|
ctype = "STD_VARIANT_TYPE"
|
|
header = "variant"
|
|
|
|
# Old:
|
|
typeName = "std::variant"
|
|
ns = ["namespace std"]
|
|
|
|
[codegen]
|
|
decl = """
|
|
template<class... Types>
|
|
void getSizeType(const %1%<Types...> &container, size_t& returnArg);
|
|
"""
|
|
|
|
func = """
|
|
template<class... Types>
|
|
void getSizeType(const %1%<Types...> &container, size_t& returnArg)
|
|
{
|
|
SAVE_SIZE(sizeof(%1%<Types...>));
|
|
SAVE_DATA(container.index());
|
|
|
|
// This check should be `container.valueless_by_exception()` but it doesn't
|
|
// work with the variable sized integers used in `std::variant`. For fewer
|
|
// than 256 options it uses a `uint8_t` index but checks against -1 of
|
|
// `uintptr_t`. Manually check for any out of bounds indices as a workaround.
|
|
if (container.index() >= sizeof...(Types)) {
|
|
return;
|
|
}
|
|
|
|
std::visit([&returnArg](auto &&arg) {
|
|
// Account for inline contents
|
|
SAVE_SIZE(-sizeof(arg));
|
|
getSizeType(arg, returnArg);
|
|
}, container);
|
|
}
|
|
"""
|