Rework for C Interfaces to handle exceptions a bit better.
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:
@@ -8,7 +8,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSet {
|
||||
Arbutils::Collections::List<Script*> _scripts;
|
||||
std::unordered_map<uint32_t, size_t> _lookup;
|
||||
Arbutils::Collections::Dictionary<uint32_t, size_t> _lookup;
|
||||
|
||||
public:
|
||||
~ScriptSet() {
|
||||
@@ -18,22 +18,23 @@ namespace CreatureLib::Battling {
|
||||
}
|
||||
|
||||
void Add(Script* script) {
|
||||
auto f = _lookup.find(script->GetName());
|
||||
if (f != _lookup.end()) {
|
||||
_scripts[f.operator*().second]->Stack();
|
||||
size_t v;
|
||||
if (_lookup.TryGet(script->GetName(), v)) {
|
||||
_scripts[v]->Stack();
|
||||
delete script;
|
||||
return;
|
||||
}
|
||||
|
||||
_scripts.Append(script);
|
||||
_lookup.insert({script->GetName(), _scripts.Count() - 1});
|
||||
_lookup.Insert(script->GetName(), _scripts.Count() - 1);
|
||||
}
|
||||
|
||||
Script* Get(const ConstString& key) const { return Get(key.GetHash()); }
|
||||
|
||||
Script* Get(uint32_t keyHash) const {
|
||||
auto f = _lookup.find(keyHash);
|
||||
if (f != _lookup.end()) {
|
||||
return _scripts[f->second];
|
||||
Script* Get(uint32_t keyHash) const noexcept {
|
||||
size_t v;
|
||||
if (_lookup.TryGet(keyHash, v)) {
|
||||
return _scripts[v];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -41,27 +42,28 @@ namespace CreatureLib::Battling {
|
||||
void Remove(const ConstString& key) { Remove(key.GetHash()); }
|
||||
|
||||
void Remove(uint32_t keyHash) {
|
||||
auto find = _lookup.find(keyHash);
|
||||
if (find != _lookup.end()) {
|
||||
auto script = _scripts[find->second];
|
||||
size_t v;
|
||||
if (_lookup.TryGet(keyHash, v)) {
|
||||
auto script = _scripts[v];
|
||||
script->OnRemove();
|
||||
delete script;
|
||||
_scripts.Remove(find.operator*().second);
|
||||
_lookup.erase(keyHash);
|
||||
_scripts.Remove(v);
|
||||
_lookup.Remove(keyHash);
|
||||
}
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (auto s : _scripts) {
|
||||
s->OnRemove();
|
||||
delete s;
|
||||
}
|
||||
_scripts.Clear();
|
||||
_lookup.clear();
|
||||
_lookup.Clear();
|
||||
}
|
||||
|
||||
bool Has(const ConstString& key) const { return _lookup.find(key) != _lookup.end(); }
|
||||
bool Has(const ConstString& key) const { return _lookup.Has(key); }
|
||||
|
||||
bool Has(uint32_t keyHash) const { return _lookup.find(keyHash) != _lookup.end(); }
|
||||
bool Has(uint32_t keyHash) const { return _lookup.Has(keyHash); }
|
||||
|
||||
size_t Count() const { return _scripts.Count(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user