[ox/model] Fix sizeOf functions
This commit is contained in:
parent
7c07fc9726
commit
a946f8dae1
246
deps/ox/src/ox/model/modelvalue.hpp
vendored
246
deps/ox/src/ox/model/modelvalue.hpp
vendored
@ -199,129 +199,6 @@ class ModelValue {
|
||||
|
||||
};
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t sizeOf(const ModelValueVector*) noexcept {
|
||||
VectorMemMap<PlatSpec> v;
|
||||
return sizeOf<PlatSpec>(&v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t sizeOf(const ModelUnion*) noexcept {
|
||||
VectorMemMap<PlatSpec> v;
|
||||
return sizeOf<PlatSpec>(&v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t sizeOf(const ModelValue *t) noexcept {
|
||||
std::size_t size = 0;
|
||||
switch (t->type()) {
|
||||
case ModelValue::Type::Bool:
|
||||
size = sizeof(t->get<bool>());
|
||||
break;
|
||||
case ModelValue::Type::Undefined:
|
||||
size = 1;
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger8:
|
||||
size = sizeof(t->get<uint8_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger16:
|
||||
size = sizeof(t->get<uint16_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger32:
|
||||
size = sizeof(t->get<uint32_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger64:
|
||||
size = sizeof(t->get<uint64_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger8:
|
||||
size = sizeof(t->get<int8_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger16:
|
||||
size = sizeof(t->get<int16_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger32:
|
||||
size = sizeof(t->get<int32_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger64:
|
||||
size = sizeof(t->get<int64_t>());
|
||||
break;
|
||||
case ModelValue::Type::String:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::String>());
|
||||
break;
|
||||
case ModelValue::Type::Object:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::ModelObject>());
|
||||
break;
|
||||
case ModelValue::Type::Union:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::ModelUnion>());
|
||||
break;
|
||||
case ModelValue::Type::Vector:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::ModelValueVector>());
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t alignOf(const ModelValueVector&) noexcept {
|
||||
VectorMemMap<PlatSpec> v;
|
||||
return alignOf<PlatSpec>(v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t alignOf(const ModelValue &t) noexcept {
|
||||
std::size_t size = 0;
|
||||
switch (t.type()) {
|
||||
case ModelValue::Type::Bool:
|
||||
size = PlatSpec::alignOf(t.get<bool>());
|
||||
break;
|
||||
case ModelValue::Type::Undefined:
|
||||
size = 1;
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger8:
|
||||
size = PlatSpec::alignOf(t.get<uint8_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger16:
|
||||
size = PlatSpec::alignOf(t.get<uint16_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger32:
|
||||
size = PlatSpec::alignOf(t.get<uint32_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger64:
|
||||
size = PlatSpec::alignOf(t.get<uint64_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger8:
|
||||
size = PlatSpec::alignOf(t.get<int8_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger16:
|
||||
size = PlatSpec::alignOf(t.get<int16_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger32:
|
||||
size = PlatSpec::alignOf(t.get<int32_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger64:
|
||||
size = PlatSpec::alignOf(t.get<int64_t>());
|
||||
break;
|
||||
case ModelValue::Type::String:
|
||||
size = PlatSpec::alignOf(t.get<ox::String>());
|
||||
break;
|
||||
case ModelValue::Type::Object:
|
||||
size = alignOf<PlatSpec>(t.get<ox::ModelObject>());
|
||||
break;
|
||||
case ModelValue::Type::Union:
|
||||
size = alignOf<PlatSpec>(t.get<ox::ModelUnion>());
|
||||
break;
|
||||
case ModelValue::Type::Vector:
|
||||
size = alignOf<PlatSpec>(t.get<ox::ModelValueVector>());
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
class ModelValueVector {
|
||||
private:
|
||||
Vector<ModelValue> m_vec;
|
||||
@ -743,6 +620,129 @@ class ModelUnion {
|
||||
|
||||
};
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t sizeOf(const ModelValueVector*) noexcept {
|
||||
VectorMemMap<PlatSpec> v;
|
||||
return sizeOf<PlatSpec>(&v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t sizeOf(const ModelUnion*) noexcept {
|
||||
VectorMemMap<PlatSpec> v;
|
||||
return sizeOf<PlatSpec>(&v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t sizeOf(const ModelValue *t) noexcept {
|
||||
std::size_t size = 0;
|
||||
switch (t->type()) {
|
||||
case ModelValue::Type::Bool:
|
||||
size = sizeof(t->get<bool>());
|
||||
break;
|
||||
case ModelValue::Type::Undefined:
|
||||
size = 1;
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger8:
|
||||
size = sizeof(t->get<uint8_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger16:
|
||||
size = sizeof(t->get<uint16_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger32:
|
||||
size = sizeof(t->get<uint32_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger64:
|
||||
size = sizeof(t->get<uint64_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger8:
|
||||
size = sizeof(t->get<int8_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger16:
|
||||
size = sizeof(t->get<int16_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger32:
|
||||
size = sizeof(t->get<int32_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger64:
|
||||
size = sizeof(t->get<int64_t>());
|
||||
break;
|
||||
case ModelValue::Type::String:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::String>());
|
||||
break;
|
||||
case ModelValue::Type::Object:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::ModelObject>());
|
||||
break;
|
||||
case ModelValue::Type::Union:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::ModelUnion>());
|
||||
break;
|
||||
case ModelValue::Type::Vector:
|
||||
size = sizeOf<PlatSpec>(&t->get<ox::ModelValueVector>());
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t alignOf(const ModelValueVector&) noexcept {
|
||||
VectorMemMap<PlatSpec> v;
|
||||
return alignOf<PlatSpec>(v);
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t alignOf(const ModelValue &t) noexcept {
|
||||
std::size_t size = 0;
|
||||
switch (t.type()) {
|
||||
case ModelValue::Type::Bool:
|
||||
size = PlatSpec::alignOf(t.get<bool>());
|
||||
break;
|
||||
case ModelValue::Type::Undefined:
|
||||
size = 1;
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger8:
|
||||
size = PlatSpec::alignOf(t.get<uint8_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger16:
|
||||
size = PlatSpec::alignOf(t.get<uint16_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger32:
|
||||
size = PlatSpec::alignOf(t.get<uint32_t>());
|
||||
break;
|
||||
case ModelValue::Type::UnsignedInteger64:
|
||||
size = PlatSpec::alignOf(t.get<uint64_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger8:
|
||||
size = PlatSpec::alignOf(t.get<int8_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger16:
|
||||
size = PlatSpec::alignOf(t.get<int16_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger32:
|
||||
size = PlatSpec::alignOf(t.get<int32_t>());
|
||||
break;
|
||||
case ModelValue::Type::SignedInteger64:
|
||||
size = PlatSpec::alignOf(t.get<int64_t>());
|
||||
break;
|
||||
case ModelValue::Type::String:
|
||||
size = PlatSpec::alignOf(t.get<ox::String>());
|
||||
break;
|
||||
case ModelValue::Type::Object:
|
||||
size = alignOf<PlatSpec>(t.get<ox::ModelObject>());
|
||||
break;
|
||||
case ModelValue::Type::Union:
|
||||
size = alignOf<PlatSpec>(t.get<ox::ModelUnion>());
|
||||
break;
|
||||
case ModelValue::Type::Vector:
|
||||
size = alignOf<PlatSpec>(t.get<ox::ModelValueVector>());
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept {
|
||||
h->template setTypeInfo<ModelObject>(obj->m_typeName.c_str(), obj->m_typeVersion, {}, static_cast<int>(obj->m_fieldsOrder.size()));
|
||||
for (auto &f : obj->m_fieldsOrder) {
|
||||
|
Loading…
Reference in New Issue
Block a user