84 : memberTag(memberTag), offsetInBytes(offsetInBytes)
92 constexpr StructInfo(
bool isPacked) : isPacked(isPacked) {}
100 constexpr ArrayInfo(
bool isPacked,
uint32_t numElements) : isPacked(isPacked), numElements(numElements) {}
105 MemberInfo memberInfo;
106 StructInfo structInfo;
115 static_assert(
sizeof(TypeInfo) == 8,
"Size must be 8 bytes");
120 : hasLink(false), type(type), numberOfChildren(0), sizeInBytes(sizeInBytes), structInfo(structInfo)
125 : hasLink(true), type(type), linkIndex(0), sizeInBytes(sizeInBytes), memberInfo(member)
130 : hasLink(false), type(type), numberOfChildren(numberOfChildren), sizeInBytes(sizeInBytes), arrayInfo(arrayInfo)
135 : hasLink(true), type(type), linkIndex(0), sizeInBytes(sizeInBytes), emptyInfo()
139 [[nodiscard]]
constexpr auto getNumberOfChildren()
const {
return numberOfChildren; }
144 [[nodiscard]]
constexpr bool setNumberOfChildren(
size_t numChildren)
146 if (numChildren >
static_cast<decltype(numberOfChildren)
>(~0ull))
148 numberOfChildren =
static_cast<decltype(numberOfChildren)
>(numChildren);
153 [[nodiscard]]
constexpr bool hasValidLinkIndex()
const {
return hasLink and linkIndex > 0; }
156 [[nodiscard]]
constexpr bool needsLinking()
const {
return hasLink and linkIndex == 0; }
160 [[nodiscard]]
constexpr auto getLinkIndex()
const {
return linkIndex; }
165 [[nodiscard]]
constexpr bool setLinkIndex(
ssize_t newLinkIndex)
167 if (newLinkIndex >
static_cast<decltype(linkIndex)
>(~0ull))
169 linkIndex =
static_cast<decltype(linkIndex)
>(newLinkIndex);
174 [[nodiscard]]
constexpr bool isPrimitiveType()
const {
return isPrimitiveCategory(type); }
177 [[nodiscard]]
constexpr bool isPrimitiveOrPackedStruct()
const
179 if (isPrimitiveType())
184 [[nodiscard]]
static constexpr bool isPrimitiveCategory(
TypeCategory category)
197template <
typename T,
typename SFINAESelector =
void>
198struct ExtendedTypeInfo;
205struct ReflectPrimitive
207 template <
typename TypeVisitor>
208 [[nodiscard]]
static constexpr bool build(TypeVisitor&)
215template <>
struct Reflect<char> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeINT8;}};
224template <>
struct Reflect<float> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeFLOAT32;}};
225template <>
struct Reflect<double> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeDOUBLE64;}};
226template <>
struct Reflect<bool> :
public ReflectPrimitive {
static constexpr auto getCategory(){
return TypeCategory::TypeBOOL;}};
229template <
typename T>
struct IsPrimitive {
static constexpr bool value = TypeInfo::isPrimitiveCategory(Reflect<T>::getCategory()); };
234struct ExtendedTypeInfo<T, typename SC::TypeTraits::EnableIf<IsPrimitive<T>::value>::type>
237 static constexpr bool IsPacked =
true;
243template <
typename T,
size_t N>
248 template <
typename TypeVisitor>
249 [[nodiscard]]
static constexpr bool build(TypeVisitor& builder)
251 using Type =
typename TypeVisitor::Type;
254 constexpr bool isPacked = ExtendedTypeInfo<T>::IsPacked;
255 if (not builder.addType(Type::template createArray<T[N]>(
"Array", 1, TypeInfo::ArrayInfo{isPacked, N})))
259 if (not builder.addType(Type::template createGeneric<T>()))
266template <
typename T,
int N>
267struct ExtendedTypeInfo<T[N]>
270 static constexpr bool IsPacked = ExtendedTypeInfo<T>::IsPacked;
276template <
typename Type>
283 template <
typename TypeVisitor>
284 [[nodiscard]]
static constexpr bool build(TypeVisitor& builder)
287 if (not builder.addType(TypeVisitor::Type::template createStruct<T>()))
291 if (not Reflect<Type>::visit(builder))
299struct ExtendedStructTypeInfo
301 size_t memberSizeSum = 0;
302 bool IsPacked =
false;
304 constexpr ExtendedStructTypeInfo()
307 if (Reflect<T>::visit(*
this))
311 IsPacked = memberSizeSum ==
sizeof(T);
315 template <
typename R,
int N>
316 constexpr bool operator()(
int memberTag, R T::* member,
const char (&name)[N],
size_t offset)
322 if (not ExtendedTypeInfo<R>().IsPacked)
326 memberSizeSum +=
sizeof(R);
331template <
typename T,
typename SFINAESelector>
332struct ExtendedTypeInfo
335 static constexpr bool IsPacked = ExtendedStructTypeInfo<T>().IsPacked;
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:42