[ox/model] Add preloadable attribute to type descriptor

This commit is contained in:
Gary Talent 2020-05-07 21:04:48 -05:00
parent dfb17c851b
commit f91874182e
3 changed files with 40 additions and 1 deletions

View File

@ -106,6 +106,7 @@ struct DescriptorType {
// - number of bytes for integer and float types // - number of bytes for integer and float types
// - number of fields for structs and lists // - number of fields for structs and lists
int64_t length = 0; int64_t length = 0;
bool preloadable = false;
DescriptorType() = default; DescriptorType() = default;
@ -125,6 +126,7 @@ Error model(T *io, DescriptorType *type) {
err |= io->field("primitiveType", &type->primitiveType); err |= io->field("primitiveType", &type->primitiveType);
err |= io->field("fieldList", &type->fieldList); err |= io->field("fieldList", &type->fieldList);
err |= io->field("length", &type->length); err |= io->field("length", &type->length);
err |= io->field("preloadable", &type->preloadable);
return err; return err;
} }

View File

@ -12,6 +12,26 @@
namespace ox { namespace ox {
namespace detail {
struct preloadable_type {
static constexpr auto Preloadable = true;
};
struct non_preloadable_type {
static constexpr auto Preloadable = false;
};
struct non_preloadable_type2 {
};
static_assert(preloadable<preloadable_type>::value);
static_assert(!preloadable<non_preloadable_type>::value);
static_assert(!preloadable<non_preloadable_type2>::value);
}
static_assert([] { static_assert([] {
int i = 0; int i = 0;
return indirectionLevels(i) == 0; return indirectionLevels(i) == 0;

View File

@ -21,6 +21,22 @@
namespace ox { namespace ox {
namespace detail {
template<bool>
struct BoolWrapper {
};
template<typename T, typename = BoolWrapper<true>>
struct preloadable: false_type {};
template<typename T>
struct preloadable<T, BoolWrapper<T::Preloadable>> {
static constexpr bool value = T::Preloadable;
};
}
template<typename T> template<typename T>
static constexpr int indirectionLevels(T) { static constexpr int indirectionLevels(T) {
return 0; return 0;
@ -187,11 +203,12 @@ void TypeDescWriter::setTypeInfo(const char *name, int) {
} }
m_type = t; m_type = t;
m_type->typeName = name; m_type->typeName = name;
if (ox::is_union_v<T>) { if (is_union_v<T>) {
m_type->primitiveType = PrimitiveType::Union; m_type->primitiveType = PrimitiveType::Union;
} else { } else {
m_type->primitiveType = PrimitiveType::Struct; m_type->primitiveType = PrimitiveType::Struct;
} }
m_type->preloadable = detail::preloadable<T>::value;
} }
template<typename T> template<typename T>