[ox/model] Fix modelEquals string and vector handling

This commit is contained in:
Gary Talent 2021-05-03 13:31:31 -04:00
parent eb1a83d907
commit 3a335084c9

View File

@ -73,7 +73,7 @@ class Copier {
template<typename FT> template<typename FT>
constexpr Error field(const char *name, const FT *v) noexcept { constexpr Error field(const char *name, const FT *v) noexcept {
if constexpr(isVector(v)) { if constexpr(isVector_v<FT>) {
return field(name, v->data(), v->size()); return field(name, v->data(), v->size());
} else { } else {
auto &src = *v; auto &src = *v;
@ -109,11 +109,11 @@ class Copier {
} }
template<typename T = void> template<typename T = void>
constexpr void setTypeInfo(const char* = T::TypeName, int = T::Fields) { constexpr void setTypeInfo(const char* = T::TypeName, int = T::Fields) noexcept {
} }
[[nodiscard]] [[nodiscard]]
static constexpr auto opType() { static constexpr auto opType() noexcept {
return "Copy"; return "Copy";
} }
@ -132,7 +132,7 @@ class Mover {
template<typename FT> template<typename FT>
constexpr Error field(const char *name, FT *v) noexcept { constexpr Error field(const char *name, FT *v) noexcept {
if constexpr(isVector(v)) { if constexpr(isVector_v<FT>) {
return field(name, v->data(), v->size()); return field(name, v->data(), v->size());
} else { } else {
auto &src = *v; auto &src = *v;
@ -185,21 +185,18 @@ class Equals {
private: private:
std::size_t m_i = 0; std::size_t m_i = 0;
MemberList<size> *m_dst = nullptr; MemberList<size> *m_other = nullptr;
public: public:
bool value = false; bool value = false;
constexpr Equals(MemberList<size> *dst) noexcept: m_dst(dst) { constexpr Equals(MemberList<size> *other) noexcept: m_other(other) {
} }
template<typename FT> template<typename FT>
constexpr Error field(const char *name, const FT *v) noexcept { constexpr Error field(const char*, const FT *v) noexcept {
if constexpr(isVector(v)) { const auto &src = *v;
return field(name, v->data(), v->size()); const auto &dst = *cbit_cast<FT*>(m_other->vars[m_i]);
} else {
auto &src = *v;
auto &dst = *cbit_cast<FT*>(m_dst->vars[m_i]);
++m_i; ++m_i;
if (dst == src) { if (dst == src) {
return OxError(0); return OxError(0);
@ -208,13 +205,12 @@ class Equals {
return OxError(1); return OxError(1);
} }
} }
}
template<typename FT> template<typename FT>
constexpr Error field(const char*, const FT *list, int elements) noexcept { constexpr Error field(const char*, const FT *list, int elements) noexcept {
for (auto i = 0l; i < elements; ++i) { for (auto i = 0l; i < elements; ++i) {
auto &src = list[i]; const auto &src = list[i];
auto &dst = cbit_cast<FT*>(m_dst->vars[m_i])[i]; const auto &dst = cbit_cast<FT*>(m_other->vars[m_i])[i];
if (!(dst == src)) { if (!(dst == src)) {
this->value = false; this->value = false;
return OxError(1); return OxError(1);
@ -226,8 +222,8 @@ class Equals {
template<typename U> template<typename U>
constexpr Error field(const char*, UnionView<U> u) noexcept { constexpr Error field(const char*, UnionView<U> u) noexcept {
auto &dst = *cbit_cast<U*>(m_dst->vars[m_i]); const auto &dst = *cbit_cast<U*>(m_other->vars[m_i]);
auto &src = *u.get(); const auto &src = *u.get();
++m_i; ++m_i;
if (dst == src) { if (dst == src) {
return OxError(0); return OxError(0);
@ -237,8 +233,16 @@ class Equals {
} }
} }
constexpr Error field(const char *name, SerStr s) noexcept { constexpr Error field(const char*, SerStr s) noexcept {
return field(name, s.target()); 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);
}
} }
template<typename T = void> template<typename T = void>