diff --git a/deps/ox/src/ox/model/modelvalue.hpp b/deps/ox/src/ox/model/modelvalue.hpp index ac040cf7..0b72e3c3 100644 --- a/deps/ox/src/ox/model/modelvalue.hpp +++ b/deps/ox/src/ox/model/modelvalue.hpp @@ -52,7 +52,7 @@ class ModelValue { private: Type m_type = Type::Undefined; union { - bool b{}; + bool b; int8_t i8; uint8_t ui8; int16_t i16; @@ -61,7 +61,7 @@ class ModelValue { uint32_t ui32; int64_t i64; uint64_t ui64; - String *str; + String *str = nullptr; ModelObject *obj; ModelUnion *uni; ModelValueVector *vec; @@ -69,33 +69,34 @@ class ModelValue { template consteval static Type getType() noexcept { - if constexpr(is_bool_v) { + using U = typename ox::remove_reference::type; + if constexpr(is_bool_v) { return Type::Bool; - } else if constexpr(is_integer_v) { - if (!is_signed_v && sizeof(T) == 1) { + } else if constexpr(is_integer_v) { + if (!is_signed_v && sizeof(U) == 1) { return Type::UnsignedInteger8; - } else if constexpr(!is_signed_v && sizeof(T) == 2) { + } else if constexpr(!is_signed_v && sizeof(U) == 2) { return Type::UnsignedInteger16; - } else if constexpr(!is_signed_v && sizeof(T) == 4) { + } else if constexpr(!is_signed_v && sizeof(U) == 4) { return Type::UnsignedInteger32; - } else if constexpr(!is_signed_v && sizeof(T) == 8) { + } else if constexpr(!is_signed_v && sizeof(U) == 8) { return Type::UnsignedInteger64; - } else if constexpr(is_signed_v && sizeof(T) == 1) { + } else if constexpr(is_signed_v && sizeof(U) == 1) { return Type::SignedInteger8; - } else if constexpr(is_signed_v && sizeof(T) == 2) { + } else if constexpr(is_signed_v && sizeof(U) == 2) { return Type::SignedInteger16; - } else if constexpr(is_signed_v && sizeof(T) == 4) { + } else if constexpr(is_signed_v && sizeof(U) == 4) { return Type::SignedInteger32; - } else if constexpr(is_signed_v && sizeof(T) == 8) { + } else if constexpr(is_signed_v && sizeof(U) == 8) { return Type::SignedInteger64; } - } else if constexpr(is_same_v) { + } else if constexpr(is_same_v) { return Type::Union; - } else if constexpr(is_same_v) { + } else if constexpr(is_same_v) { return Type::Object; - } else if constexpr(is_same_v) { + } else if constexpr(is_same_v) { return Type::String; - } else if constexpr(is_same_v) { + } else if constexpr(is_same_v) { return Type::Vector; } else { return Type::Undefined; @@ -192,10 +193,6 @@ class ModelValue { constexpr ModelValue &operator=(ModelValue &&val) noexcept; - constexpr ModelValue &operator=(const auto &val) noexcept; - - constexpr ModelValue &operator=(auto &&val) noexcept; - private: constexpr void freeResources() noexcept; @@ -356,6 +353,66 @@ class ModelObject { m_typeVersion = other.m_typeVersion; } + [[nodiscard]] + constexpr auto begin() noexcept { + return m_fieldsOrder.begin(); + } + + [[nodiscard]] + constexpr auto end() noexcept { + return m_fieldsOrder.end(); + } + + [[nodiscard]] + constexpr auto begin() const noexcept { + return m_fieldsOrder.begin(); + } + + [[nodiscard]] + constexpr auto end() const noexcept { + return m_fieldsOrder.end(); + } + + [[nodiscard]] + constexpr auto rbegin() noexcept { + return m_fieldsOrder.rbegin(); + } + + [[nodiscard]] + constexpr auto rend() noexcept { + return m_fieldsOrder.rend(); + } + + [[nodiscard]] + constexpr auto rbegin() const noexcept { + return m_fieldsOrder.rbegin(); + } + + [[nodiscard]] + constexpr auto rend() const noexcept { + return m_fieldsOrder.rend(); + } + + [[nodiscard]] + constexpr auto cbegin() const noexcept { + return m_fieldsOrder.cbegin(); + } + + [[nodiscard]] + constexpr auto cend() const noexcept { + return m_fieldsOrder.cend(); + } + + [[nodiscard]] + constexpr auto crbegin() const noexcept { + return m_fieldsOrder.crbegin(); + } + + [[nodiscard]] + constexpr auto crend() const noexcept { + return m_fieldsOrder.crend(); + } + constexpr auto &operator=(const ModelObject &other) noexcept { if (&other == this) [[unlikely]] { return *this; @@ -474,9 +531,9 @@ class ModelUnion { m_unionIdx = i; } - constexpr void set(int i, auto val) noexcept { + constexpr auto set(int i, auto val) noexcept { m_unionIdx = i; - *m_fieldsOrder[i] = val; + return m_fieldsOrder[static_cast(i)]->value.set(val); } constexpr void set(std::size_t i, auto val) noexcept { @@ -712,7 +769,7 @@ constexpr Error ModelValue::set(T &&v) noexcept { auto &value = getValue(*this); if constexpr(type == Type::Vector || type == Type::Object || type == Type::Union || type == Type::String) { - safeDelete(value); + safeDelete(&value); } value = ox::forward(v); return OxError(0); @@ -794,22 +851,6 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept { return *this; } -constexpr ModelValue &ModelValue::operator=(const auto &val) noexcept { - if (this == &val) { - return *this; - } - set(val); - return *this; -} - -constexpr ModelValue &ModelValue::operator=(auto &&val) noexcept { - if (this == &val) { - return *this; - } - set(ox::forward(val)); - return *this; -} - constexpr void ModelValue::freeResources() noexcept { switch (m_type) { case Type::Undefined: