[ox] Remove SerStr
This commit is contained in:
parent
e0289ee7e0
commit
23054c9f6f
8
deps/ox/src/ox/model/descwrite.hpp
vendored
8
deps/ox/src/ox/model/descwrite.hpp
vendored
@ -143,9 +143,6 @@ class TypeDescWriter {
|
||||
[[nodiscard]]
|
||||
constexpr const DescriptorType *type(const char *val) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const DescriptorType *type(SerStr val) const noexcept;
|
||||
|
||||
template<std::size_t SmallStrSz>
|
||||
[[nodiscard]]
|
||||
constexpr const DescriptorType *type(const BasicString<SmallStrSz>*) const noexcept {
|
||||
@ -332,11 +329,6 @@ constexpr const DescriptorType *TypeDescWriter::type(const char*) const noexcept
|
||||
return getType(types::String, 0, PT, 0);
|
||||
}
|
||||
|
||||
constexpr const DescriptorType *TypeDescWriter::type(SerStr) const noexcept {
|
||||
constexpr auto PT = PrimitiveType::String;
|
||||
return getType(types::String, 0, PT, 0);
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr const DescriptorType *TypeDescWriter::type(const BString<sz>*) const noexcept {
|
||||
constexpr auto PT = PrimitiveType::String;
|
||||
|
24
deps/ox/src/ox/model/modelops.hpp
vendored
24
deps/ox/src/ox/model/modelops.hpp
vendored
@ -71,10 +71,6 @@ class MemberList {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
constexpr Error field(const char *name, SerStr s) noexcept {
|
||||
return field(name, s.target());
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
constexpr void setTypeInfo(const char* = T::TypeName, int = ModelTypeVersion_v<T>,
|
||||
const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {
|
||||
@ -131,10 +127,6 @@ class Copier {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
constexpr Error field(const char *name, SerStr s) {
|
||||
return field(name, s.target());
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion, const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {
|
||||
}
|
||||
@ -192,10 +184,6 @@ class Mover {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
constexpr Error field(const char *name, SerStr s) noexcept {
|
||||
return field(name, s.target());
|
||||
}
|
||||
|
||||
template<typename T = void>
|
||||
constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion, const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {
|
||||
}
|
||||
@ -260,18 +248,6 @@ class Equals {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Error field(const char*, SerStr s) noexcept {
|
||||
const auto a = s.c_str();
|
||||
const auto b = *cbit_cast<const char**>(m_other->vars[m_i]);
|
||||
++m_i;
|
||||
if (a && b && ox_strcmp(a, b) == 0) {
|
||||
return OxError(0);
|
||||
} else {
|
||||
this->value = false;
|
||||
return OxError(1);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return OpType::Read;
|
||||
|
70
deps/ox/src/ox/model/types.hpp
vendored
70
deps/ox/src/ox/model/types.hpp
vendored
@ -157,76 +157,6 @@ constexpr bool isSmartPtr_v<::std::unique_ptr<T>> = true;
|
||||
#endif
|
||||
|
||||
|
||||
class SerStr {
|
||||
|
||||
protected:
|
||||
int m_cap = 0;
|
||||
char *m_str = nullptr;
|
||||
char **m_tgt = nullptr;
|
||||
|
||||
public:
|
||||
template<std::size_t sz>
|
||||
explicit constexpr SerStr(BString<sz> *str) noexcept {
|
||||
m_str = str->data();
|
||||
m_cap = str->cap();
|
||||
}
|
||||
|
||||
constexpr SerStr(char *str, int cap) noexcept {
|
||||
m_str = str;
|
||||
m_cap = cap;
|
||||
}
|
||||
|
||||
explicit constexpr SerStr(char **tgt, int cap = -1) noexcept {
|
||||
m_tgt = tgt;
|
||||
m_str = const_cast<char*>(*tgt);
|
||||
m_cap = cap;
|
||||
}
|
||||
|
||||
explicit constexpr SerStr(char *str, char **tgt, int cap = -1) noexcept {
|
||||
m_tgt = tgt;
|
||||
m_str = str;
|
||||
m_cap = cap;
|
||||
}
|
||||
|
||||
template<std::size_t cap>
|
||||
explicit constexpr SerStr(char (&str)[cap]) noexcept {
|
||||
m_str = str;
|
||||
m_cap = cap;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *c_str() const noexcept {
|
||||
return m_str;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto target() const noexcept {
|
||||
return m_tgt;
|
||||
}
|
||||
|
||||
constexpr char *data(std::size_t sz = 0) noexcept {
|
||||
if (m_tgt && sz) {
|
||||
if (!*m_tgt || sz > static_cast<std::size_t>(m_cap)) {
|
||||
*m_tgt = new char[sz];
|
||||
m_str = *m_tgt;
|
||||
m_cap = static_cast<int>(sz);
|
||||
}
|
||||
}
|
||||
return m_str;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int len() const noexcept {
|
||||
return static_cast<int>(m_str ? ox_strlen(m_str) : 0);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int cap() const noexcept {
|
||||
return m_cap;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename Union, bool force = false>
|
||||
class UnionView {
|
||||
|
||||
|
28
deps/ox/src/ox/oc/read.cpp
vendored
28
deps/ox/src/ox/oc/read.cpp
vendored
@ -181,34 +181,6 @@ Error OrganicClawReader::field(const char *key, bool *val) noexcept {
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::field(const char *key, SerStr val) noexcept {
|
||||
auto err = OxError(0);
|
||||
const char *begin = nullptr, *end = nullptr;
|
||||
const auto &jv = value(key);
|
||||
if (targetValid()) {
|
||||
if (jv.empty()) {
|
||||
auto data = val.data();
|
||||
if (data) {
|
||||
data[0] = 0;
|
||||
}
|
||||
} else if (jv.isString()) {
|
||||
jv.getString(&begin, &end);
|
||||
auto strSize = end - begin;
|
||||
auto data = val.data(static_cast<std::size_t>(strSize) + 1);
|
||||
if (strSize >= val.cap()) {
|
||||
err = OxError(1, "String size exceeds capacity of destination");
|
||||
} else {
|
||||
ox_memcpy(data, begin, static_cast<std::size_t>(strSize));
|
||||
data[strSize] = 0;
|
||||
}
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
}
|
||||
++m_fieldIt;
|
||||
return err;
|
||||
}
|
||||
|
||||
Error OrganicClawReader::fieldCString(const char *key, char *val, std::size_t buffLen) noexcept {
|
||||
auto err = OxError(0);
|
||||
const char *begin = nullptr, *end = nullptr;
|
||||
|
4
deps/ox/src/ox/oc/read.hpp
vendored
4
deps/ox/src/ox/oc/read.hpp
vendored
@ -72,8 +72,6 @@ class OrganicClawReader {
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, BString<L> *val) noexcept;
|
||||
|
||||
Error field(const char *key, SerStr val) noexcept;
|
||||
|
||||
Error fieldCString(const char *key, char *val, std::size_t buffLen) noexcept;
|
||||
|
||||
Error fieldCString(const char *key, char **val) noexcept;
|
||||
@ -205,7 +203,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
|
||||
|
||||
template<std::size_t L>
|
||||
Error OrganicClawReader::field(const char *key, BString<L> *val) noexcept {
|
||||
return field(key, SerStr(val->data(), static_cast<int>(val->cap())));
|
||||
return fieldCString(key, val->data(), val->cap());
|
||||
}
|
||||
|
||||
// array handler
|
||||
|
2
deps/ox/src/ox/oc/test/tests.cpp
vendored
2
deps/ox/src/ox/oc/test/tests.cpp
vendored
@ -332,7 +332,7 @@ const std::map<std::string_view, ox::Error(*)()> tests = {
|
||||
}
|
||||
case ox::PrimitiveType::String: {
|
||||
ox::Vector<char> v(rdr->stringLength(fieldName) + 1);
|
||||
oxAssert(rdr->field(fieldName, ox::SerStr(v.data(), static_cast<int>(v.size()))), "Walking model failed.");
|
||||
oxAssert(rdr->fieldCString(fieldName, v.data(), v.size()), "Walking model failed.");
|
||||
oxOutf("{}:\tstring:\t{}\n", fieldName, v.data());
|
||||
break;
|
||||
}
|
||||
|
8
deps/ox/src/ox/oc/write.cpp
vendored
8
deps/ox/src/ox/oc/write.cpp
vendored
@ -18,14 +18,6 @@ OrganicClawWriter::OrganicClawWriter(Json::Value json, int unionIdx) noexcept:
|
||||
m_unionIdx(unionIdx) {
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::field(const char *key, SerStr val) noexcept {
|
||||
if (targetValid() && val.len()) {
|
||||
value(key) = val.c_str();
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::fieldCString(const char *key, const char *const*val, int len) noexcept {
|
||||
if (targetValid() && len) {
|
||||
value(key) = *val;
|
||||
|
14
deps/ox/src/ox/oc/write.hpp
vendored
14
deps/ox/src/ox/oc/write.hpp
vendored
@ -141,12 +141,20 @@ class OrganicClawWriter {
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, const BString<L> *val) noexcept {
|
||||
return field(key, SerStr(val->data(), val->cap()));
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
++m_fieldIt;
|
||||
return {};
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, BString<L> *val) noexcept {
|
||||
return field(key, SerStr(val->data(), static_cast<int>(val->cap())));
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
++m_fieldIt;
|
||||
return {};
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
@ -163,8 +171,6 @@ class OrganicClawWriter {
|
||||
return field(key, const_cast<const BasicString<L>*>(val));
|
||||
}
|
||||
|
||||
Error field(const char*, SerStr val) noexcept;
|
||||
|
||||
Error fieldCString(const char*, const char *const*val, int len) noexcept;
|
||||
|
||||
Error fieldCString(const char *name, char **val, int len) noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user