[ox] Fix some template issue that come up with some versions of Clang, fix empty string read in OC
This commit is contained in:
parent
1b93b2038f
commit
960889749d
9
deps/ox/src/ox/mc/read.hpp
vendored
9
deps/ox/src/ox/mc/read.hpp
vendored
@ -27,7 +27,7 @@
|
||||
namespace ox {
|
||||
|
||||
template<Reader_c Reader>
|
||||
class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<Reader>> {
|
||||
class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<Reader>, ox::OpType::Read> {
|
||||
|
||||
private:
|
||||
FieldBitmapReader<Reader> m_fieldPresence;
|
||||
@ -127,11 +127,6 @@ class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<R
|
||||
|
||||
constexpr void nextField() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return OpType::Read;
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename I>
|
||||
constexpr Error readInteger(I *val) noexcept;
|
||||
@ -533,7 +528,7 @@ template<typename T>
|
||||
Error readMC(const char *buff, std::size_t buffLen, T *val) noexcept {
|
||||
BufferReader br(buff, buffLen);
|
||||
MetalClawReader reader(br);
|
||||
ModelHandlerInterface handler(&reader);
|
||||
ModelHandlerInterface<MetalClawReader, ox::OpType::Read> handler(&reader);
|
||||
return model(&handler, val);
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/model/descwrite.hpp
vendored
4
deps/ox/src/ox/model/descwrite.hpp
vendored
@ -357,7 +357,7 @@ constexpr const DescriptorType *TypeDescWriter::getType(CRStringView tn, int typ
|
||||
template<typename T>
|
||||
constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore) noexcept {
|
||||
TypeDescWriter writer(typeStore);
|
||||
ModelHandlerInterface handler(&writer);
|
||||
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
|
||||
if (std::is_constant_evaluated()) {
|
||||
std::allocator<T> a;
|
||||
T *t = a.allocate(1);
|
||||
@ -373,7 +373,7 @@ constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore) noexcept {
|
||||
template<typename T>
|
||||
constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore, T *val) noexcept {
|
||||
TypeDescWriter writer(typeStore);
|
||||
ModelHandlerInterface handler(&writer);
|
||||
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
|
||||
oxReturnError(model(&handler, val));
|
||||
return writer.definition();
|
||||
}
|
||||
|
21
deps/ox/src/ox/model/modelhandleradaptor.hpp
vendored
21
deps/ox/src/ox/model/modelhandleradaptor.hpp
vendored
@ -14,7 +14,7 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename Handler>
|
||||
template<typename Handler, OpType opType_v = Handler::opType()>
|
||||
class ModelHandlerInterface {
|
||||
private:
|
||||
Handler *m_handler = nullptr;
|
||||
@ -46,7 +46,7 @@ class ModelHandlerInterface {
|
||||
}
|
||||
|
||||
template<std::size_t len>
|
||||
constexpr Error fieldCString(const char *name, const char val[len]) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
constexpr Error fieldCString(const char *name, const char val[len]) noexcept requires(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, &val[0], len);
|
||||
}
|
||||
|
||||
@ -54,11 +54,11 @@ class ModelHandlerInterface {
|
||||
return m_handler->fieldCString(name, val);
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char *const*val) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
constexpr Error fieldCString(const char *name, const char *const*val) noexcept requires(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val);
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char **val) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
constexpr Error fieldCString(const char *name, const char **val) noexcept requires(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ class ModelHandlerInterface {
|
||||
return m_handler->fieldCString(name, val, buffLen);
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char **val, std::size_t buffLen) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
constexpr Error fieldCString(const char *name, const char **val, std::size_t buffLen) noexcept requires(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val, buffLen);
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ class ModelHandlerInterface {
|
||||
case ModelValue::Type::Union:
|
||||
{
|
||||
auto &u = v->template get<ModelUnion>();
|
||||
if constexpr(Handler::opType() == OpType::Read) {
|
||||
if constexpr(opType_v == OpType::Read) {
|
||||
u.setActiveField(m_handler->whichFieldPresent(name, u));
|
||||
return m_handler->field(name, UnionView<ModelUnion, true>(&u, u.unionIdx()));
|
||||
} else {
|
||||
@ -180,10 +180,10 @@ class ModelHandlerInterface {
|
||||
|
||||
};
|
||||
|
||||
template<typename Handler>
|
||||
template<typename Handler, ox::OpType opType_v = Handler::opType()>
|
||||
class ModelHandlerBase {
|
||||
private:
|
||||
ModelHandlerInterface<Handler> m_interface;
|
||||
ModelHandlerInterface<Handler, opType_v> m_interface;
|
||||
public:
|
||||
constexpr ModelHandlerBase() noexcept: m_interface(static_cast<Handler*>(this)) {}
|
||||
constexpr ModelHandlerBase(const ModelHandlerBase&) noexcept: m_interface(static_cast<Handler*>(this)) {}
|
||||
@ -192,6 +192,11 @@ class ModelHandlerBase {
|
||||
constexpr auto interface() noexcept {
|
||||
return &m_interface;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static constexpr ox::OpType opType() noexcept {
|
||||
return opType_v;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
2
deps/ox/src/ox/oc/read.hpp
vendored
2
deps/ox/src/ox/oc/read.hpp
vendored
@ -194,7 +194,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
*val = BasicString<L>{};
|
||||
} else if (jv.isString()) {
|
||||
*val = jv.asString().c_str();
|
||||
} else {
|
||||
|
10
deps/ox/src/ox/oc/write.hpp
vendored
10
deps/ox/src/ox/oc/write.hpp
vendored
@ -117,7 +117,7 @@ class OrganicClawWriter {
|
||||
if (targetValid()) {
|
||||
const auto &keys = val->keys();
|
||||
OrganicClawWriter w;
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
for (std::size_t i = 0; i < keys.size(); ++i) {
|
||||
const auto k = keys[i].c_str();
|
||||
if (k) [[likely]] {
|
||||
@ -197,7 +197,7 @@ template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) noexcept {
|
||||
if (targetValid() && len) {
|
||||
OrganicClawWriter w((Json::Value(Json::arrayValue)));
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
for (std::size_t i = 0; i < len; ++i) {
|
||||
oxReturnError(handler.field("", &val[i]));
|
||||
}
|
||||
@ -213,7 +213,7 @@ Error OrganicClawWriter::field(const char *key, const T *val) noexcept {
|
||||
return field(key, val->data(), val->size());
|
||||
} else if (val && targetValid()) {
|
||||
OrganicClawWriter w;
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
oxReturnError(model(&handler, val));
|
||||
if (!w.m_json.isNull()) {
|
||||
value(key) = w.m_json;
|
||||
@ -227,7 +227,7 @@ template<typename U, bool force>
|
||||
Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcept {
|
||||
if (targetValid()) {
|
||||
OrganicClawWriter w(val.idx());
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
oxReturnError(model(&handler, val.get()));
|
||||
if (!w.m_json.isNull()) {
|
||||
value(key) = w.m_json;
|
||||
@ -239,7 +239,7 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
|
||||
|
||||
Result<Buffer> writeOC(const auto &val) noexcept {
|
||||
OrganicClawWriter writer;
|
||||
ModelHandlerInterface handler(&writer);
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
||||
oxReturnError(model(&handler, &val));
|
||||
Json::StreamWriterBuilder jsonBuilder;
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
|
@ -22,7 +22,7 @@ template<typename PlatSpec, typename T>
|
||||
constexpr std::size_t sizeOf(const T *t) noexcept;
|
||||
|
||||
template<typename PlatSpec>
|
||||
struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>> {
|
||||
struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>, OpType::Reflect> {
|
||||
std::size_t biggestAlignment = 1;
|
||||
|
||||
template<typename T>
|
||||
@ -64,11 +64,6 @@ struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Reflect;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
1
deps/ox/src/ox/preloader/platspecs.hpp
vendored
1
deps/ox/src/ox/preloader/platspecs.hpp
vendored
@ -13,6 +13,7 @@
|
||||
namespace ox {
|
||||
|
||||
struct NativePlatSpec {
|
||||
static constexpr std::size_t RomStart = 1024;
|
||||
using PtrType = uintptr_t;
|
||||
using size_t = std::size_t;
|
||||
|
||||
|
2
deps/ox/src/ox/preloader/preloader.cpp
vendored
2
deps/ox/src/ox/preloader/preloader.cpp
vendored
@ -6,4 +6,6 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
template class Preloader<NativePlatSpec>;
|
||||
|
||||
}
|
||||
|
12
deps/ox/src/ox/preloader/preloader.hpp
vendored
12
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -15,7 +15,6 @@
|
||||
#include <ox/std/units.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
|
||||
#include "preloader.hpp"
|
||||
#include "platspecs.hpp"
|
||||
|
||||
namespace ox {
|
||||
@ -24,7 +23,7 @@ template<typename PlatSpec>
|
||||
class Preloader;
|
||||
|
||||
template<typename PlatSpec>
|
||||
class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
|
||||
class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
|
||||
private:
|
||||
using PtrType = typename PlatSpec::PtrType;
|
||||
static constexpr auto PtrSize = sizeof(PtrType);
|
||||
@ -115,11 +114,6 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
|
||||
return m_buff;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Write;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr ox::Error pad(const T*) noexcept;
|
||||
|
||||
@ -272,7 +266,7 @@ constexpr ox::Error Preloader<PlatSpec>::endAlloc() noexcept {
|
||||
return m_writer.seekp(0, ox::ios_base::end);
|
||||
}
|
||||
const auto &si = *m_allocStack.back().unwrap();
|
||||
oxReturnError(m_writer.seekp(si.restore, si.seekdir));
|
||||
oxReturnError(m_writer.seekp(static_cast<ox::ssize_t>(si.restore), si.seekdir));
|
||||
m_allocStack.pop_back();
|
||||
return {};
|
||||
}
|
||||
@ -364,4 +358,6 @@ constexpr ox::Error preload(Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *
|
||||
return pl->pad(obj);
|
||||
}
|
||||
|
||||
extern template class Preloader<NativePlatSpec>;
|
||||
|
||||
}
|
||||
|
7
deps/ox/src/ox/preloader/sizecatcher.hpp
vendored
7
deps/ox/src/ox/preloader/sizecatcher.hpp
vendored
@ -24,7 +24,7 @@ template<typename PlatSpec, typename T>
|
||||
constexpr std::size_t sizeOf(const T *t) noexcept;
|
||||
|
||||
template<typename PlatSpec>
|
||||
class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>> {
|
||||
class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>, OpType::Reflect> {
|
||||
private:
|
||||
std::size_t m_size = 0;
|
||||
|
||||
@ -61,11 +61,6 @@ class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>> {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Reflect;
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr void pad(const auto *val) noexcept;
|
||||
};
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace ox {
|
||||
|
||||
template<typename PlatSpec>
|
||||
class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>> {
|
||||
class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>, OpType::Reflect> {
|
||||
private:
|
||||
std::size_t m_size = 0;
|
||||
|
||||
@ -55,11 +55,6 @@ class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>> {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Reflect;
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename T, std::size_t SmallVecSize>
|
||||
constexpr ox::Error fieldStr(CRStringView, const ox::BasicString<SmallVecSize> *val) noexcept;
|
||||
|
18
deps/ox/src/ox/std/span.hpp
vendored
18
deps/ox/src/ox/std/span.hpp
vendored
@ -28,27 +28,29 @@ class SpanView {
|
||||
template<typename RefType = T const&, typename PtrType = T const*, bool reverse = false>
|
||||
using iterator = SpanIterator<T, RefType, PtrType, reverse>;
|
||||
|
||||
constexpr SpanView() noexcept {}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr SpanView(ox::Array<T, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz, typename Allocator>
|
||||
constexpr SpanView(ox::Vector<T, sz, Allocator> const&v) noexcept:
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr SpanView(const T a[sz]) noexcept:
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
}
|
||||
|
||||
constexpr SpanView(const T *a, std::size_t sz) noexcept:
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
}
|
||||
|
||||
constexpr iterator<> begin() noexcept {
|
||||
|
2
deps/ox/src/ox/std/types.hpp
vendored
2
deps/ox/src/ox/std/types.hpp
vendored
@ -159,6 +159,8 @@ struct ResizedInt<T, bits, false> {
|
||||
template<typename T, std::size_t bits>
|
||||
using ResizedInt_t = typename ResizedInt<T, bits>::type;
|
||||
|
||||
using ssize_t = Signed<std::size_t>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user