diff --git a/deps/ox/src/ox/model/desctypes.hpp b/deps/ox/src/ox/model/desctypes.hpp index 382ed822..a924aee8 100644 --- a/deps/ox/src/ox/model/desctypes.hpp +++ b/deps/ox/src/ox/model/desctypes.hpp @@ -35,7 +35,7 @@ struct DescriptorField { // order of fields matters static constexpr auto TypeName = "net.drinkingtea.ox.DescriptorField"; - static constexpr auto TypeVersion = 1; + static constexpr auto TypeVersion = 2; // do not serialize type const struct DescriptorType *type = nullptr; @@ -82,7 +82,7 @@ using FieldList = Vector; struct DescriptorType { static constexpr auto TypeName = "net.drinkingtea.ox.DescriptorType"; - static constexpr auto TypeVersion = 1; + static constexpr auto TypeVersion = 2; String typeName; PrimitiveType primitiveType = PrimitiveType::UnsignedInteger; @@ -117,9 +117,14 @@ template constexpr Error model(T *io, DescriptorType *type) noexcept { io->template setTypeInfo(); oxReturnError(io->field("typeName", &type->typeName)); - auto pt = static_cast(type->primitiveType); - oxReturnError(io->field("primitiveType", &pt)); - type->primitiveType = static_cast(pt); + if constexpr(ox_strcmp(T::opType(), "Reflect") == 0) { + uint8_t pt = 0; + oxReturnError(io->field("primitiveType", &pt)); + } else { + auto pt = type ? static_cast(type->primitiveType) : 0; + oxReturnError(io->field("primitiveType", &pt)); + type->primitiveType = static_cast(pt); + } oxReturnError(io->field("fieldList", &type->fieldList)); oxReturnError(io->field("length", &type->length)); oxReturnError(io->field("preloadable", &type->preloadable)); @@ -128,7 +133,7 @@ constexpr Error model(T *io, DescriptorType *type) noexcept { template constexpr Error model(T *io, DescriptorField *field) noexcept { - io->template setTypeInfo(DescriptorField::TypeName, 4); + io->template setTypeInfo(); oxReturnError(io->field("typeName", &field->typeName)); oxReturnError(io->field("fieldName", &field->fieldName)); oxReturnError(io->field("subscriptLevels", &field->subscriptLevels)); diff --git a/deps/ox/src/ox/model/descwrite.hpp b/deps/ox/src/ox/model/descwrite.hpp index e8666296..26eef4a9 100644 --- a/deps/ox/src/ox/model/descwrite.hpp +++ b/deps/ox/src/ox/model/descwrite.hpp @@ -67,7 +67,7 @@ class TypeDescWriter { } static constexpr auto opType() noexcept { - return OpType::WriteDefinition; + return OpType::Reflect; } private: @@ -121,7 +121,7 @@ constexpr Error TypeDescWriter::field(const char *name, T *val, std::size_t) noe if (t == nullptr) { type(p, &alreadyExisted); } - m_type->fieldList.emplace_back(t, name, detail::indirectionLevels(val), alreadyExisted ? t->typeName : ""); + m_type->fieldList.emplace_back(t, name, detail::indirectionLevels(val), t->typeName); return OxError(0); } return OxError(1); @@ -133,7 +133,7 @@ constexpr Error TypeDescWriter::field(const char *name, T val) noexcept { bool alreadyExisted = false; const auto t = type(val, &alreadyExisted); oxAssert(t != nullptr, "field(const char *name, T val): Type not found or generated"); - m_type->fieldList.emplace_back(t, name, 0, alreadyExisted ? t->typeName : ""); + m_type->fieldList.emplace_back(t, name, 0, t->typeName); return OxError(0); } return OxError(1); diff --git a/deps/ox/src/ox/model/fieldcounter.hpp b/deps/ox/src/ox/model/fieldcounter.hpp index 5d5bfd65..724bbf84 100644 --- a/deps/ox/src/ox/model/fieldcounter.hpp +++ b/deps/ox/src/ox/model/fieldcounter.hpp @@ -43,7 +43,7 @@ class FieldCounter { } static constexpr auto opType() { - return OpType::Read; + return OpType::Reflect; } }; diff --git a/deps/ox/src/ox/model/optype.hpp b/deps/ox/src/ox/model/optype.hpp index ba943057..5927b68e 100644 --- a/deps/ox/src/ox/model/optype.hpp +++ b/deps/ox/src/ox/model/optype.hpp @@ -18,6 +18,7 @@ namespace OpType { constexpr auto Read = "Read"; constexpr auto Write = "Write"; constexpr auto WriteDefinition = "WriteDefinition"; + constexpr auto Reflect = "Reflect"; } // empty default implementations of model functions @@ -39,6 +40,11 @@ constexpr Error modelWriteDefinition(T*, O*) noexcept { return OxError(1, "Model: modelWriteDefinition not implemented"); } +template +constexpr Error modelReflect(T*, O*) noexcept { + return OxError(1, "Model: modelReflect not implemented"); +} + template constexpr Error model(T *io, O *obj) noexcept { if constexpr(ox_strcmp(T::opType(), OpType::Read) == 0) { @@ -47,6 +53,8 @@ constexpr Error model(T *io, O *obj) noexcept { return modelWrite(io, obj); } else if constexpr(ox_strcmp(T::opType(), OpType::WriteDefinition) == 0) { return modelWriteDefinition(io, obj); + } else if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) { + return modelReflect(io, obj); } else { oxAssert(OxError(1), "Missing model function"); return OxError(1); diff --git a/deps/ox/src/ox/model/typenamecatcher.hpp b/deps/ox/src/ox/model/typenamecatcher.hpp index 09a9ad10..46bdb4c9 100644 --- a/deps/ox/src/ox/model/typenamecatcher.hpp +++ b/deps/ox/src/ox/model/typenamecatcher.hpp @@ -46,7 +46,7 @@ struct TypeNameCatcher { } static constexpr auto opType() noexcept { - return OpType::WriteDefinition; + return OpType::Reflect; } }; diff --git a/deps/ox/src/ox/model/typestore.hpp b/deps/ox/src/ox/model/typestore.hpp index 249c0c26..d2ec47f4 100644 --- a/deps/ox/src/ox/model/typestore.hpp +++ b/deps/ox/src/ox/model/typestore.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "typenamecatcher.hpp" #include "desctypes.hpp" @@ -60,10 +61,14 @@ class TypeStore { const String name = nameCstr; auto [val, err] = m_cache.at(name); if (err) { - oxRequireM(dt, loadDescriptor(name)); - auto &out = m_cache[name]; - out = std::move(dt); - return out.get(); + if (!std::is_constant_evaluated()) { + oxRequireM(dt, loadDescriptor(name)); + auto &out = m_cache[name]; + out = std::move(dt); + return out.get(); + } else { + return OxError(1, "Type not available"); + } } return val->get(); } @@ -87,10 +92,10 @@ class TypeStore { } protected: - constexpr virtual Result> loadDescriptor(const ox::String&) noexcept { + virtual Result> loadDescriptor(const ox::String&) noexcept { return OxError(1); } }; -} \ No newline at end of file +}