Replace most collections with Arbutils collections for more safety.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define CREATURELIB_BASELIBRARY_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
@@ -9,7 +10,7 @@
|
||||
|
||||
namespace CreatureLib::Library {
|
||||
template <class T> class BaseLibrary {
|
||||
std::unordered_map<uint32_t, const T*> _values;
|
||||
Arbutils::Collections::Dictionary<uint32_t, const T*> _values;
|
||||
|
||||
public:
|
||||
BaseLibrary(size_t initialCapacity = 32) : _values(initialCapacity) {}
|
||||
@@ -18,46 +19,40 @@ namespace CreatureLib::Library {
|
||||
for (const auto& v : _values) {
|
||||
delete v.second;
|
||||
}
|
||||
_values.clear();
|
||||
_values.Clear();
|
||||
}
|
||||
|
||||
inline void Insert(const Arbutils::CaseInsensitiveConstString& key, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.insert({key.GetHash(), value});
|
||||
_values.Insert(key.GetHash(), value);
|
||||
}
|
||||
inline void Insert(uint32_t hashedKey, const T* value) {
|
||||
AssertNotNull(value)
|
||||
_values.insert({hashedKey, value});
|
||||
_values.Insert(hashedKey, value);
|
||||
}
|
||||
|
||||
inline void Delete(const Arbutils::CaseInsensitiveConstString& key) { _values.erase(key.GetHash()); }
|
||||
inline void Delete(uint32_t hashedKey) { _values.erase({hashedKey}); }
|
||||
inline void Delete(uint32_t hashedKey) { _values.Remove(hashedKey); }
|
||||
|
||||
bool TryGet(const Arbutils::CaseInsensitiveConstString& name, const T*& out) const {
|
||||
return TryGet(name.GetHash(), out);
|
||||
}
|
||||
bool TryGet(uint32_t hashedKey, const T*& out) const {
|
||||
auto find = this->_values.find(hashedKey);
|
||||
if (find == this->_values.end()) {
|
||||
out = nullptr;
|
||||
return false;
|
||||
}
|
||||
out = find->second;
|
||||
return true;
|
||||
}
|
||||
bool TryGet(uint32_t hashedKey, const T*& out) const { return _values.TryGet(hashedKey, out); }
|
||||
|
||||
[[nodiscard]] inline const T* Get(const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return _values.at(name.GetHash());
|
||||
return _values.Get(name.GetHash());
|
||||
}
|
||||
[[nodiscard]] inline const T* Get(uint32_t hashedKey) const { return _values.at(hashedKey); }
|
||||
[[nodiscard]] inline const T* Get(uint32_t hashedKey) const { return _values.Get(hashedKey); }
|
||||
|
||||
[[nodiscard]] inline const T* operator[](const Arbutils::CaseInsensitiveConstString& name) const {
|
||||
return Get(name);
|
||||
}
|
||||
[[nodiscard]] inline const T* operator[](uint32_t hashedKey) const { return Get(hashedKey); }
|
||||
[[nodiscard]] inline const std::unordered_map<uint32_t, const T*>& GetIterator() const { return _values; }
|
||||
[[nodiscard]] inline const Arbutils::Collections::Dictionary<uint32_t, const T*>& GetIterator() const {
|
||||
return _values;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t GetCount() const { return _values.size(); }
|
||||
[[nodiscard]] size_t GetCount() const { return _values.Count(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user