From 7bbd7bfdb5143a21a821cfa34678ae9f885de48a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 1 Apr 2021 02:41:12 -0500 Subject: [PATCH] [ox/std] Make HashMap::at return type consistent between const/non-const --- deps/ox/src/ox/mc/read.hpp | 2 +- deps/ox/src/ox/model/descwrite.cpp | 4 ++-- deps/ox/src/ox/model/descwrite.hpp | 4 ++-- deps/ox/src/ox/oc/read.hpp | 2 +- deps/ox/src/ox/oc/write.hpp | 2 +- deps/ox/src/ox/std/hashmap.hpp | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/deps/ox/src/ox/mc/read.hpp b/deps/ox/src/ox/mc/read.hpp index f3cbad43..d84e6d3c 100644 --- a/deps/ox/src/ox/mc/read.hpp +++ b/deps/ox/src/ox/mc/read.hpp @@ -215,7 +215,7 @@ Error MetalClawReader::field(const char*, HashMap *val) { auto keyLen = reader.stringLength(nullptr); auto wkey = ox_malloca(keyLen + 1, char, 0); oxReturnError(reader.field("", SerStr(wkey.get(), keyLen))); - oxReturnError(reader.field("", &val->at(wkey.get()))); + oxReturnError(reader.field("", &val->operator[](wkey.get()))); } } } diff --git a/deps/ox/src/ox/model/descwrite.cpp b/deps/ox/src/ox/model/descwrite.cpp index 4263cf62..583a2266 100644 --- a/deps/ox/src/ox/model/descwrite.cpp +++ b/deps/ox/src/ox/model/descwrite.cpp @@ -144,12 +144,12 @@ DescriptorType *TypeDescWriter::type(bool*, bool *alreadyExisted) { DescriptorType *TypeDescWriter::getType(TypeName tn, PrimitiveType pt, int b, bool *alreadyExisted) { if (m_typeStore->contains(tn)) { *alreadyExisted = true; - auto type = m_typeStore->at(tn); + auto type = m_typeStore->operator[](tn); oxAssert(type != nullptr, "TypeDescWriter::getType returning null DescriptorType"); return type; } else { *alreadyExisted = false; - auto &t = m_typeStore->at(tn); + auto &t = m_typeStore->operator[](tn); if (!t) { t = new DescriptorType; } diff --git a/deps/ox/src/ox/model/descwrite.hpp b/deps/ox/src/ox/model/descwrite.hpp index ba1f6c3c..9b6053e3 100644 --- a/deps/ox/src/ox/model/descwrite.hpp +++ b/deps/ox/src/ox/model/descwrite.hpp @@ -193,7 +193,7 @@ DescriptorType *TypeDescWriter::type(T *val, bool *alreadyExisted) { oxLogError(model(&nc, val)); if (m_typeStore->contains(nc.name)) { *alreadyExisted = true; - return m_typeStore->at(nc.name); + return m_typeStore->operator[](nc.name); } else { TypeDescWriter dw(m_typeStore); oxLogError(model(&dw, val)); @@ -219,7 +219,7 @@ DescriptorType *TypeDescWriter::type(UnionView val, bool *alreadyExisted) { template void TypeDescWriter::setTypeInfo(const char *name, int) { - auto &t = m_typeStore->at(name); + auto &t = m_typeStore->operator[](name); if (!t) { t = new DescriptorType; } diff --git a/deps/ox/src/ox/oc/read.hpp b/deps/ox/src/ox/oc/read.hpp index 7e377ef9..2c5922ad 100644 --- a/deps/ox/src/ox/oc/read.hpp +++ b/deps/ox/src/ox/oc/read.hpp @@ -171,7 +171,7 @@ Error OrganicClawReader::field(const char *key, HashMap *val) { OrganicClawReader r(srcVal); for (decltype(srcSize) i = 0; i < srcSize; ++i) { auto k = keys[i].c_str(); - oxReturnError(r.field(k, &val->at(k))); + oxReturnError(r.field(k, &val->operator[](k))); } return OxError(0); } diff --git a/deps/ox/src/ox/oc/write.hpp b/deps/ox/src/ox/oc/write.hpp index 99c3fefe..ae386a90 100644 --- a/deps/ox/src/ox/oc/write.hpp +++ b/deps/ox/src/ox/oc/write.hpp @@ -140,7 +140,7 @@ Error OrganicClawWriter::field(const char *key, ox::HashMap *val) { OrganicClawWriter w; for (std::size_t i = 0; i < keys.size(); ++i) { auto k = keys[i].c_str(); - oxReturnError(w.field(k, &val->at(k))); + oxReturnError(w.field(k, &val->operator[](k))); } value(key) = w.m_json; } diff --git a/deps/ox/src/ox/std/hashmap.hpp b/deps/ox/src/ox/std/hashmap.hpp index 359c22c7..66d58ed2 100644 --- a/deps/ox/src/ox/std/hashmap.hpp +++ b/deps/ox/src/ox/std/hashmap.hpp @@ -46,7 +46,7 @@ class HashMap { /** * K is assumed to be a null terminated string. */ - T &at(K key); + Result at(K key); /** * K is assumed to be a null terminated string. @@ -132,8 +132,8 @@ T &HashMap::operator[](K k) { } template -T &HashMap::at(K k) { - return operator[](k); +Result HashMap::at(K k) { + return &operator[](k); } template