Fixes functions for getting underlying std map from StringViewDictionary
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
e0c16b772c
commit
e2ea281de1
|
@ -11,13 +11,11 @@ namespace ArbUt {
|
||||||
/// @brief Wrapper around unordered_map, allowing safer access and adding several helper methods.
|
/// @brief Wrapper around unordered_map, allowing safer access and adding several helper methods.
|
||||||
template <class ValueT> class StringViewDictionary {
|
template <class ValueT> class StringViewDictionary {
|
||||||
private:
|
private:
|
||||||
|
struct StringViewHash {
|
||||||
struct StringViewHash
|
|
||||||
{
|
|
||||||
using hash_type = std::hash<StringView>;
|
using hash_type = std::hash<StringView>;
|
||||||
using is_transparent = void;
|
using is_transparent = void;
|
||||||
|
|
||||||
size_t operator()(const char* str) const { return hash_type{}(str); }
|
size_t operator()(const char* str) const { return hash_type{}(str); }
|
||||||
size_t operator()(StringView const& str) const { return hash_type{}(str); }
|
size_t operator()(StringView const& str) const { return hash_type{}(str); }
|
||||||
size_t operator()(u32 hash) const { return hash; }
|
size_t operator()(u32 hash) const { return hash; }
|
||||||
};
|
};
|
||||||
|
@ -86,7 +84,6 @@ namespace ArbUt {
|
||||||
/// @brief Gets a value from the dictionary using the direct hash of the key.
|
/// @brief Gets a value from the dictionary using the direct hash of the key.
|
||||||
[[nodiscard]] inline const ValueT& GetFromHash(u32 hash) const { return _map.find(hash)->second; }
|
[[nodiscard]] inline const ValueT& GetFromHash(u32 hash) const { return _map.find(hash)->second; }
|
||||||
|
|
||||||
|
|
||||||
/// @brief Try to get an item from the dictionary using a key. Returns false if no item is found, and out will
|
/// @brief Try to get an item from the dictionary using a key. Returns false if no item is found, and out will
|
||||||
/// not be touched in that case.
|
/// not be touched in that case.
|
||||||
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(const StringView& key) const noexcept {
|
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(const StringView& key) const noexcept {
|
||||||
|
@ -97,8 +94,8 @@ namespace ArbUt {
|
||||||
return std::ref(find->second);
|
return std::ref(find->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Try to get an item from the dictionary using the hash of a key. Returns false if no item is found, and out will
|
/// @brief Try to get an item from the dictionary using the hash of a key. Returns false if no item is found,
|
||||||
/// not be touched in that case.
|
/// and out will not be touched in that case.
|
||||||
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(u32 hash) const noexcept {
|
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(u32 hash) const noexcept {
|
||||||
const auto& find = _map.find(hash);
|
const auto& find = _map.find(hash);
|
||||||
if (find == _map.end()) {
|
if (find == _map.end()) {
|
||||||
|
@ -132,9 +129,11 @@ namespace ArbUt {
|
||||||
const_iterator end() const { return _map.end(); }
|
const_iterator end() const { return _map.end(); }
|
||||||
|
|
||||||
/// @brief returns the backing unordered_map.
|
/// @brief returns the backing unordered_map.
|
||||||
const std::unordered_map<StringView, ValueT>& GetStdMap() const noexcept { return _map; }
|
const std::unordered_map<StringView, ValueT, StringViewHash, std::equal_to<>>& GetStdMap() const noexcept {
|
||||||
|
return _map;
|
||||||
|
}
|
||||||
/// @brief returns the backing unordered_map.
|
/// @brief returns the backing unordered_map.
|
||||||
std::unordered_map<StringView, ValueT>& GetStdMap() noexcept { return _map; }
|
std::unordered_map<StringView, ValueT, StringViewHash, std::equal_to<>>& GetStdMap() noexcept { return _map; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue