[ox/std] Make HashMap::at return Result<T&> instead of Result<T*>
This commit is contained in:
parent
c46ec57431
commit
af9991c008
12
deps/ox/src/ox/clargs/clargs.cpp
vendored
12
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -39,32 +39,32 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
|
||||
|
||||
bool ClArgs::getBool(const char *arg, bool defaultValue) const noexcept {
|
||||
auto [value, err] = m_ints.at(arg);
|
||||
return !err ? *value : defaultValue;
|
||||
return !err ? value : defaultValue;
|
||||
}
|
||||
|
||||
String ClArgs::getString(const char *arg, const char *defaultValue) const noexcept {
|
||||
auto [value, err] = m_strings.at(arg);
|
||||
return !err ? *value : defaultValue;
|
||||
return !err ? value : defaultValue;
|
||||
}
|
||||
|
||||
int ClArgs::getInt(const char *arg, int defaultValue) const noexcept {
|
||||
auto [value, err] = m_ints.at(arg);
|
||||
return !err ? *value : defaultValue;
|
||||
return !err ? value : defaultValue;
|
||||
}
|
||||
|
||||
Result<bool> ClArgs::getBool(const char *arg) const noexcept {
|
||||
oxRequire(out, m_bools.at(arg));
|
||||
return *out;
|
||||
return out;
|
||||
}
|
||||
|
||||
Result<String> ClArgs::getString(const char *argName) const noexcept {
|
||||
oxRequire(out, m_strings.at(argName));
|
||||
return *out;
|
||||
return out;
|
||||
}
|
||||
|
||||
Result<int> ClArgs::getInt(const char *arg) const noexcept {
|
||||
oxRequire(out, m_ints.at(arg));
|
||||
return *out;
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
18
deps/ox/src/ox/std/hashmap.hpp
vendored
18
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -46,12 +46,12 @@ class HashMap {
|
||||
/**
|
||||
* K is assumed to be a null terminated string.
|
||||
*/
|
||||
Result<T*> at(K key);
|
||||
Result<T&> at(K key);
|
||||
|
||||
/**
|
||||
* K is assumed to be a null terminated string.
|
||||
*/
|
||||
Result<const T*> at(K key) const;
|
||||
Result<const T&> at(K key) const;
|
||||
|
||||
bool contains(K key) const;
|
||||
|
||||
@ -132,21 +132,23 @@ T &HashMap<K, T>::operator[](K k) {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
Result<T*> HashMap<K, T>::at(K k) {
|
||||
Result<T&> HashMap<K, T>::at(K k) {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "Value not found for key")};
|
||||
AllocAlias<T> v;
|
||||
return {*bit_cast<T*>(&v), OxError(1)};
|
||||
}
|
||||
return &p->value;
|
||||
return p->value;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
Result<const T*> HashMap<K, T>::at(K k) const {
|
||||
Result<const T&> HashMap<K, T>::at(K k) const {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return OxError(1, "Value not found for key");
|
||||
AllocAlias<T> v;
|
||||
return {*bit_cast<T*>(&v), OxError(1)};
|
||||
}
|
||||
return &p->value;
|
||||
return p->value;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user