[ox] Add StringView, Writer system, Preloader system

This commit is contained in:
2022-11-30 01:45:11 -06:00
parent 98f35140fe
commit cbb496c59f
64 changed files with 2343 additions and 417 deletions

View File

@@ -15,10 +15,11 @@ namespace ox {
Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcept {
const auto s1End = ox_strchr(buff, ';', buffLen);
if (!s1End) {
oxAssert(false, "fail");
return OxError(1, "Could not read Claw header");
}
const auto s1Size = s1End - buff;
String fmt(buff, s1Size);
const String fmt(buff, s1Size);
buff += s1Size + 1;
buffLen -= s1Size + 1;
@@ -27,7 +28,7 @@ Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcep
return OxError(2, "Could not read Claw header");
}
const auto s2Size = s2End - buff;
String typeName(buff, s2Size);
const String typeName(buff, s2Size);
buff += s2Size + 1;
buffLen -= s2Size + 1;
@@ -36,7 +37,7 @@ Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcep
return OxError(3, "Could not read Claw header");
}
const auto s3Size = s3End - buff;
String versionStr(buff, s3Size);
const String versionStr(buff, s3Size);
buff += s3Size + 1;
buffLen -= s3Size + 1;
@@ -74,7 +75,7 @@ Result<Buffer> stripClawHeader(const ox::Buffer &buff) noexcept {
Result<ModelObject> readClaw(TypeStore *ts, const Buffer &buff) noexcept {
oxRequire(header, readClawHeader(buff));
oxRequire(t, ts->template getLoad(header.typeName, header.typeVersion));
oxRequire(t, ts->template getLoad(header.typeName, header.typeVersion, header.typeParams));
ModelObject obj;
oxReturnError(obj.setType(t));
switch (header.fmt) {

View File

@@ -25,6 +25,7 @@ constexpr auto Error_ClawTypeVersionMismatch = 201;
struct ClawHeader {
String typeName;
int typeVersion = -1;
TypeParamPack typeParams;
ClawFormat fmt = ClawFormat::None;
const char *data = nullptr;
std::size_t dataSize = 0;

View File

@@ -96,7 +96,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
oxReturnError(io->field("Int7", &obj->Int7));
oxReturnError(io->field("Int8", &obj->Int8));
int unionIdx = 0;
if constexpr(ox_strcmp(T::opType(), ox::OpType::Reflect) != 0) {
if constexpr(T::opType() != ox::OpType::Reflect) {
unionIdx = obj->unionIdx;
}
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, unionIdx}));

View File

@@ -24,10 +24,12 @@ namespace detail {
struct TypeInfoCatcher {
const char *name = nullptr;
int version = 0;
template<typename T = void>
constexpr void setTypeInfo(const char *name = T::TypeName, int = T::TypeVersion) noexcept {
constexpr void setTypeInfo(const char *name = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, int = 0) noexcept {
this->name = name;
this->version = v;
}
constexpr Error field(...) noexcept {
@@ -57,6 +59,13 @@ constexpr const char *getTypeName(T *t) noexcept {
return tnc.name;
}
template<typename T>
constexpr int getTypeVersion(T *t) noexcept {
TypeInfoCatcher tnc;
oxIgnoreError(model(&tnc, t));
return tnc.version;
}
template<typename T>
Result<String> writeClawHeader(T *t, ClawFormat fmt) noexcept {
String out;
@@ -72,7 +81,7 @@ Result<String> writeClawHeader(T *t, ClawFormat fmt) noexcept {
}
out += detail::getTypeName(t);
out += ";";
const auto tn = detail::type_version<T>::value;
const auto tn = detail::getTypeVersion(t);
if (tn > -1) {
out += tn;
}