85 : memberTag(memberTag), offsetInBytes(offsetInBytes)
93 constexpr StructInfo(
bool isPacked) : isPacked(isPacked) {}
101 constexpr ArrayInfo(
bool isPacked,
uint32_t numElements) : isPacked(isPacked), numElements(numElements) {}
106 MemberInfo memberInfo;
107 StructInfo structInfo;
116 static_assert(
sizeof(TypeInfo) == 8,
"Size must be 8 bytes");
121 : hasLink(false), type(type), numberOfChildren(0), sizeInBytes(sizeInBytes), structInfo(structInfo)
126 : hasLink(true), type(type), linkIndex(0), sizeInBytes(sizeInBytes), memberInfo(member)
131 : hasLink(false), type(type), numberOfChildren(numberOfChildren), sizeInBytes(sizeInBytes), arrayInfo(arrayInfo)
136 : hasLink(true), type(type), linkIndex(0), sizeInBytes(sizeInBytes), emptyInfo()
140 [[nodiscard]]
constexpr auto getNumberOfChildren()
const {
return numberOfChildren; }
145 [[nodiscard]]
constexpr bool setNumberOfChildren(
size_t numChildren)
147 if (numChildren >
static_cast<decltype(numberOfChildren)
>(MaxValue()))
149 numberOfChildren =
static_cast<decltype(numberOfChildren)
>(numChildren);
154 [[nodiscard]]
constexpr bool hasValidLinkIndex()
const {
return hasLink and linkIndex > 0; }
157 [[nodiscard]]
constexpr bool needsLinking()
const {
return hasLink and linkIndex == 0; }
161 [[nodiscard]]
constexpr auto getLinkIndex()
const {
return linkIndex; }
166 [[nodiscard]]
constexpr bool setLinkIndex(
ssize_t newLinkIndex)
168 if (newLinkIndex >
static_cast<decltype(linkIndex)
>(MaxValue()))
170 linkIndex =
static_cast<decltype(linkIndex)
>(newLinkIndex);
175 [[nodiscard]]
constexpr bool isPrimitiveType()
const {
return isPrimitiveCategory(type); }
178 [[nodiscard]]
constexpr bool isPrimitiveOrPackedStruct()
const
180 if (isPrimitiveType())
185 [[nodiscard]]
static constexpr bool isPrimitiveCategory(
TypeCategory category)
198template <
typename T,
typename SFINAESelector =
void>
199struct ExtendedTypeInfo;
206struct ReflectPrimitive
208 template <
typename TypeVisitor>
209 [[nodiscard]]
static constexpr bool build(TypeVisitor&)
216template <>
struct Reflect<char> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeINT8;}};
225template <>
struct Reflect<float> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeFLOAT32;}};
226template <>
struct Reflect<double> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeDOUBLE64;}};
227template <>
struct Reflect<bool> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeBOOL;}};
230template <
typename T>
struct IsPrimitive {
static constexpr bool value = TypeInfo::isPrimitiveCategory(Reflect<T>::getCategory()); };
235struct ExtendedTypeInfo<T, typename SC::TypeTraits::EnableIf<IsPrimitive<T>::value>::type>
238 static constexpr bool IsPacked =
true;
244template <
typename T,
size_t N>
249 template <
typename TypeVisitor>
250 [[nodiscard]]
static constexpr bool build(TypeVisitor& builder)
252 using Type =
typename TypeVisitor::Type;
255 constexpr bool isPacked = ExtendedTypeInfo<T>::IsPacked;
256 if (not builder.addType(Type::template createArray<T[N]>(
"Array", 1, TypeInfo::ArrayInfo{isPacked, N})))
260 if (not builder.addType(Type::template createGeneric<T>()))
267template <
typename T,
int N>
268struct ExtendedTypeInfo<T[N]>
271 static constexpr bool IsPacked = ExtendedTypeInfo<T>::IsPacked;
277template <
typename Type>
284 template <
typename TypeVisitor>
285 [[nodiscard]]
static constexpr bool build(TypeVisitor& builder)
288 if (not builder.addType(TypeVisitor::Type::template createStruct<T>()))
292 if (not Reflect<Type>::visit(builder))
300struct ExtendedStructTypeInfo
302 size_t memberSizeSum = 0;
303 bool IsPacked =
false;
305 constexpr ExtendedStructTypeInfo()
308 if (Reflect<T>::visit(*
this))
312 IsPacked = memberSizeSum ==
sizeof(T);
316 template <
typename R,
int N>
317 constexpr bool operator()(
int memberTag, R T::* member,
const char (&name)[N],
size_t offset)
323 if (not ExtendedTypeInfo<R>().IsPacked)
327 memberSizeSum +=
sizeof(R);
332template <
typename T,
typename SFINAESelector>
333struct ExtendedTypeInfo
336 static constexpr bool IsPacked = ExtendedStructTypeInfo<T>().IsPacked;
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:42