Database is now working and functional.

This commit is contained in:
2024-04-09 02:31:10 -07:00
parent d13fe81ac5
commit 72347ea9a2
8 changed files with 55 additions and 10 deletions

View File

@@ -83,6 +83,11 @@ namespace ehs
return nullptr;
}
DbVar* DbObject::GetVariable(const Str_8& id) const
{
return GetVariable(id.Hash_64());
}
void DbObject::Save() const
{
if (!IsLoaded())
@@ -95,7 +100,7 @@ namespace ehs
for (UInt_64 i = 0; i < vars.Size(); ++i)
vars[i].Serialize(data);
File file(parent->GetId() + "/" + Str_8::FromNum(id), Mode::WRITE, Disposition::CREATE_PERSISTENT);
File file(parent->GetId() + "/" + Str_8::FromNum(id) + ".eho", Mode::WRITE, Disposition::CREATE_PERSISTENT);
file.WriteSerializer_64(data);
}
@@ -104,14 +109,17 @@ namespace ehs
if (IsLoaded())
return;
File file(parent->GetId() + "/" + Str_8::FromNum(id), Mode::READ, Disposition::OPEN);
File file(parent->GetId() + "/" + Str_8::FromNum(id) + ".eho", Mode::READ, Disposition::OPEN);
Serializer<UInt_64> data = file.ReadSerializer_64(Endianness::LE, file.Size());
file.Release();
vars.Resize(data.Read<UInt_64>());
for (UInt_64 i = 0; i < vars.Size(); ++i)
{
vars[i].parent = this;
vars[i].Deserialize(data);
}
}
bool DbObject::IsLoaded() const
@@ -126,7 +134,7 @@ namespace ehs
void DbObject::CreateVariable(DbVarTmpl* master)
{
vars.Push(DbVar(master->GetHashId(), master, master->GetSize(), master->GetDefault()));
vars.Push(DbVar(master->GetHashId(), master));
vars[vars.End()].parent = this;
}
}