8#ifndef SEN_CORE_META_STRUCT_TRAITS_H
9#define SEN_CORE_META_STRUCT_TRAITS_H
27 [[noreturn]]
static void throwNonNativeField(
const char* structName,
const char* fieldName);
29 [[nodiscard]]
static const VarMap&
getMap(
const Var& var, std::string_view structType);
33 std::string_view fieldName,
34 std::string_view fieldType,
35 std::string_view structType);
47 err.append(
"struct '");
49 err.append(
"' has no fields");
58 err.append(
"no field index for struct '");
68 err.append(
"field '");
69 err.append(fieldName);
70 err.append(
"' of struct '");
71 err.append(structName);
72 err.append(
"' has not a native type");
79 err.append(
"struct '");
80 err.append(structName);
81 err.append(
"' has no field of index ");
82 err.append(std::to_string(index));
88 static VarMap emptyMap = {};
101 err.append(
"struct ");
102 err.append(structType);
103 err.append(
": variant does not hold a variant map (");
104 err.append(var.
getCopyAs<std::string>());
106 throw std::runtime_error(err);
112 std::string_view fieldName,
113 std::string_view fieldType,
114 std::string_view structType)
116 std::ignore = fieldType;
117 std::ignore = structType;
119 if (
const auto itr = map.find(fieldName); itr != map.end())
Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers...
Definition span.h:34
constexpr bool empty() const noexcept
Definition span.h:136
void throwRuntimeError(const std::string &err)
Throws std::exception that attempts to collect the stack trace. We also wrap it to avoid including st...
Definition type_traits.h:34
std::map< std::string, Var, std::less<> > VarMap
A map of vars to represent structures.
Definition var.h:107
Base class for struct traits.
Definition struct_traits.h:21
static void expectAtLeastOneField(const char *name, const Span< uint16_t > &fields)
Definition struct_traits.h:53
static const VarMap & getMap(const Var &var, std::string_view structType)
Definition struct_traits.h:86
static void throwInvalidFieldIndex(const char *structName, uint16_t index)
Definition struct_traits.h:76
static void throwNonNativeField(const char *structName, const char *fieldName)
Definition struct_traits.h:65
static void extractField(const VarMap &map, T &val, std::string_view fieldName, std::string_view fieldType, std::string_view structType)
Definition struct_traits.h:110
static constexpr bool available
Definition struct_traits.h:22
static void throwEmptyStructError(const char *name)
Definition struct_traits.h:44
Can hold any supported value type. Wraps std::variant to allow recursion and implements some helpers.
Definition var.h:119
constexpr bool isEmpty() const noexcept
True if the Var holds a value of std::monostate.
Definition var.h:199
T getCopyAs() const
See sen::getCopyAs().
Definition var.h:203
constexpr T & get()
Same as std::get<T>(this->value);.
Definition var.h:210
constexpr bool holds() const noexcept
True if the Var holds a value of T.
Definition var.h:177