[ox/oc] Move vector handling over to isVector_v

This commit is contained in:
Gary Talent 2021-05-03 13:35:50 -04:00
parent 3a335084c9
commit 18491dafd9
3 changed files with 6 additions and 31 deletions

View File

@ -53,9 +53,6 @@ class OrganicClawReader {
template<typename T> template<typename T>
Error field(const char *key, T *val, std::size_t len); Error field(const char *key, T *val, std::size_t len);
template<typename T>
Error field(const char *key, Vector<T> *val);
template<typename T> template<typename T>
Error field(const char*, HashMap<String, T> *val); Error field(const char*, HashMap<String, T> *val);
@ -112,7 +109,9 @@ class OrganicClawReader {
template<typename T> template<typename T>
Error OrganicClawReader::field(const char *key, T *val) { Error OrganicClawReader::field(const char *key, T *val) {
auto err = OxError(0); auto err = OxError(0);
if (targetValid()) { if constexpr(isVector_v<T>) {
return field(key, val->data(), val->size());
} else if (targetValid()) {
const auto &jv = value(key); const auto &jv = value(key);
if (jv.empty() || jv.isObject()) { if (jv.empty() || jv.isObject()) {
auto reader = child(key); auto reader = child(key);
@ -161,11 +160,6 @@ Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) {
return OxError(0); return OxError(0);
} }
template<typename T>
Error OrganicClawReader::field(const char *key, ox::Vector<T> *val) {
return field(key, val->data(), val->size());
}
template<typename T> template<typename T>
Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) { Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) {
const auto &srcVal = value(key); const auto &srcVal = value(key);

View File

@ -53,16 +53,12 @@ struct TestStruct {
TestStruct() noexcept = default; TestStruct() noexcept = default;
TestStruct(const TestStruct&) noexcept;
TestStruct(TestStruct &&other) noexcept; TestStruct(TestStruct &&other) noexcept;
~TestStruct() noexcept { ~TestStruct() noexcept {
delete[] CString; delete[] CString;
} }
constexpr TestStruct &operator=(const TestStruct&) noexcept;
constexpr TestStruct &operator=(TestStruct&&) noexcept; constexpr TestStruct &operator=(TestStruct&&) noexcept;
}; };
@ -108,19 +104,10 @@ constexpr ox::Error model(T *io, TestStruct *obj) noexcept {
return OxError(0); return OxError(0);
} }
TestStruct::TestStruct(const TestStruct &other) noexcept {
ox::copyModel(this, &other);
}
TestStruct::TestStruct(TestStruct &&other) noexcept { TestStruct::TestStruct(TestStruct &&other) noexcept {
ox::moveModel(this, &other); ox::moveModel(this, &other);
} }
constexpr TestStruct &TestStruct::operator=(const TestStruct &other) noexcept {
ox::copyModel(this, &other);
return *this;
}
constexpr TestStruct &TestStruct::operator=(TestStruct &&other) noexcept { constexpr TestStruct &TestStruct::operator=(TestStruct &&other) noexcept {
ox::moveModel(this, &other); ox::moveModel(this, &other);
return *this; return *this;

View File

@ -51,9 +51,6 @@ class OrganicClawWriter {
template<typename U> template<typename U>
Error field(const char*, UnionView<U> val); Error field(const char*, UnionView<U> val);
template<typename T>
Error field(const char*, ox::Vector<T> *val);
template<typename T> template<typename T>
Error field(const char*, HashMap<String, T> *val); Error field(const char*, HashMap<String, T> *val);
@ -106,7 +103,9 @@ Error OrganicClawWriter::field(const char *key, ox::BString<L> *val) {
template<typename T> template<typename T>
Error OrganicClawWriter::field(const char *key, T *val) { Error OrganicClawWriter::field(const char *key, T *val) {
if (val && targetValid()) { if constexpr(isVector_v<T>) {
return field(key, val->data(), val->size());
} else if (val && targetValid()) {
OrganicClawWriter w; OrganicClawWriter w;
oxReturnError(model(&w, val)); oxReturnError(model(&w, val));
if (!w.m_json.isNull()) { if (!w.m_json.isNull()) {
@ -130,11 +129,6 @@ Error OrganicClawWriter::field(const char *key, UnionView<U> val) {
return OxError(0); return OxError(0);
} }
template<typename T>
Error OrganicClawWriter::field(const char *key, ox::Vector<T> *val) {
return field(key, val->data(), val->size());
}
template<typename T> template<typename T>
Error OrganicClawWriter::field(const char *key, ox::HashMap<String, T> *val) { Error OrganicClawWriter::field(const char *key, ox::HashMap<String, T> *val) {
if (targetValid()) { if (targetValid()) {