From 2734cc00fb26b963d4ee027a585e4be6beb228bd Mon Sep 17 00:00:00 2001 From: Karutoh Date: Wed, 10 Apr 2024 22:28:45 -0700 Subject: [PATCH] Added filter function. --- include/ehs/db/DbTable.h | 4 ++++ src/db/DbTable.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/ehs/db/DbTable.h b/include/ehs/db/DbTable.h index 4c92fce..11e76ab 100644 --- a/include/ehs/db/DbTable.h +++ b/include/ehs/db/DbTable.h @@ -46,6 +46,10 @@ namespace ehs DbObject *CreateObject(); + DbObject *GetObject(UInt_64 variableHashId, const Str_8 &value) const; + + DbObject *GetObject(const Str_8 &variable, const Str_8 &value) const; + DbObject *GetObject(UInt_64 id) const; private: diff --git a/src/db/DbTable.cpp b/src/db/DbTable.cpp index 0db8f80..caf4ed6 100644 --- a/src/db/DbTable.cpp +++ b/src/db/DbTable.cpp @@ -119,6 +119,27 @@ namespace ehs return obj; } + DbObject* DbTable::GetObject(UInt_64 variableHashId, const Str_8& value) const + { + for (UInt_64 i = 0; i < objects.Size(); ++i) + { + objects[i].Load(); + + const DbVar * const var = objects[i].GetVariable(variableHashId); + if (var->GetValueStr() == value) + return &objects[i]; + + objects[i].Free(); + } + + return nullptr; + } + + DbObject* DbTable::GetObject(const Str_8& variable, const Str_8& value) const + { + return GetObject(variable.Hash_64(), value); + } + DbObject* DbTable::GetObject(const UInt_64 id) const { for (UInt_64 i = 0; i < objects.Size(); ++i)