From a946f8dae1a10bed798079061513769ee919b814 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 3 Dec 2022 01:32:09 -0600 Subject: [PATCH] [ox/model] Fix sizeOf functions --- deps/ox/src/ox/model/modelvalue.hpp | 246 ++++++++++++++-------------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/deps/ox/src/ox/model/modelvalue.hpp b/deps/ox/src/ox/model/modelvalue.hpp index f448a303..3b55cb55 100644 --- a/deps/ox/src/ox/model/modelvalue.hpp +++ b/deps/ox/src/ox/model/modelvalue.hpp @@ -199,129 +199,6 @@ class ModelValue { }; -template -[[nodiscard]] -constexpr std::size_t sizeOf(const ModelValueVector*) noexcept { - VectorMemMap v; - return sizeOf(&v); -} - -template -[[nodiscard]] -constexpr std::size_t sizeOf(const ModelUnion*) noexcept { - VectorMemMap v; - return sizeOf(&v); -} - -template -[[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()); - break; - case ModelValue::Type::Undefined: - size = 1; - break; - case ModelValue::Type::UnsignedInteger8: - size = sizeof(t->get()); - break; - case ModelValue::Type::UnsignedInteger16: - size = sizeof(t->get()); - break; - case ModelValue::Type::UnsignedInteger32: - size = sizeof(t->get()); - break; - case ModelValue::Type::UnsignedInteger64: - size = sizeof(t->get()); - break; - case ModelValue::Type::SignedInteger8: - size = sizeof(t->get()); - break; - case ModelValue::Type::SignedInteger16: - size = sizeof(t->get()); - break; - case ModelValue::Type::SignedInteger32: - size = sizeof(t->get()); - break; - case ModelValue::Type::SignedInteger64: - size = sizeof(t->get()); - break; - case ModelValue::Type::String: - size = sizeOf(&t->get()); - break; - case ModelValue::Type::Object: - size = sizeOf(&t->get()); - break; - case ModelValue::Type::Union: - size = sizeOf(&t->get()); - break; - case ModelValue::Type::Vector: - size = sizeOf(&t->get()); - break; - } - return size; -} - -template -[[nodiscard]] -constexpr std::size_t alignOf(const ModelValueVector&) noexcept { - VectorMemMap v; - return alignOf(v); -} - -template -[[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()); - break; - case ModelValue::Type::Undefined: - size = 1; - break; - case ModelValue::Type::UnsignedInteger8: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::UnsignedInteger16: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::UnsignedInteger32: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::UnsignedInteger64: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::SignedInteger8: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::SignedInteger16: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::SignedInteger32: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::SignedInteger64: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::String: - size = PlatSpec::alignOf(t.get()); - break; - case ModelValue::Type::Object: - size = alignOf(t.get()); - break; - case ModelValue::Type::Union: - size = alignOf(t.get()); - break; - case ModelValue::Type::Vector: - size = alignOf(t.get()); - break; - } - return size; -} - class ModelValueVector { private: Vector m_vec; @@ -743,6 +620,129 @@ class ModelUnion { }; +template +[[nodiscard]] +constexpr std::size_t sizeOf(const ModelValueVector*) noexcept { + VectorMemMap v; + return sizeOf(&v); +} + +template +[[nodiscard]] +constexpr std::size_t sizeOf(const ModelUnion*) noexcept { + VectorMemMap v; + return sizeOf(&v); +} + +template +[[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()); + break; + case ModelValue::Type::Undefined: + size = 1; + break; + case ModelValue::Type::UnsignedInteger8: + size = sizeof(t->get()); + break; + case ModelValue::Type::UnsignedInteger16: + size = sizeof(t->get()); + break; + case ModelValue::Type::UnsignedInteger32: + size = sizeof(t->get()); + break; + case ModelValue::Type::UnsignedInteger64: + size = sizeof(t->get()); + break; + case ModelValue::Type::SignedInteger8: + size = sizeof(t->get()); + break; + case ModelValue::Type::SignedInteger16: + size = sizeof(t->get()); + break; + case ModelValue::Type::SignedInteger32: + size = sizeof(t->get()); + break; + case ModelValue::Type::SignedInteger64: + size = sizeof(t->get()); + break; + case ModelValue::Type::String: + size = sizeOf(&t->get()); + break; + case ModelValue::Type::Object: + size = sizeOf(&t->get()); + break; + case ModelValue::Type::Union: + size = sizeOf(&t->get()); + break; + case ModelValue::Type::Vector: + size = sizeOf(&t->get()); + break; + } + return size; +} + +template +[[nodiscard]] +constexpr std::size_t alignOf(const ModelValueVector&) noexcept { + VectorMemMap v; + return alignOf(v); +} + +template +[[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()); + break; + case ModelValue::Type::Undefined: + size = 1; + break; + case ModelValue::Type::UnsignedInteger8: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::UnsignedInteger16: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::UnsignedInteger32: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::UnsignedInteger64: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::SignedInteger8: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::SignedInteger16: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::SignedInteger32: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::SignedInteger64: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::String: + size = PlatSpec::alignOf(t.get()); + break; + case ModelValue::Type::Object: + size = alignOf(t.get()); + break; + case ModelValue::Type::Union: + size = alignOf(t.get()); + break; + case ModelValue::Type::Vector: + size = alignOf(t.get()); + break; + } + return size; +} + constexpr Error model(auto *h, CommonPtrWith auto *obj) noexcept { h->template setTypeInfo(obj->m_typeName.c_str(), obj->m_typeVersion, {}, static_cast(obj->m_fieldsOrder.size())); for (auto &f : obj->m_fieldsOrder) {