Simplified the database.

This commit is contained in:
2024-04-10 18:26:20 -07:00
parent 72347ea9a2
commit 3196c5021e
9 changed files with 131 additions and 279 deletions

View File

@@ -1,6 +1,5 @@
#pragma once
#include "DbType.h"
#include "ehs/EHS.h"
#include "ehs/Serializer.h"
#include "ehs/Str.h"
@@ -13,26 +12,32 @@ namespace ehs
{
private:
friend class DbTable;
friend class DbVar;
UInt_64 hashId;
Str_8 id;
DbType type;
bool array;
UInt_64 size;
Byte* def;
Array<DbVar*> slaves;
UInt_64 size;
public:
~DbVarTmpl();
DbVarTmpl();
DbVarTmpl(Str_8 id, DbType type, UInt_64 size, const Byte* def);
template<typename T>
DbVarTmpl(Str_8 id, const T* const def, UInt_64 size)
: hashId(id.Hash_64()), id((Str_8&&)id), def(new Byte[sizeof(T) * size]), size(sizeof(T) * size)
{
Util::Copy(this->def, def, this->size);
}
DbVarTmpl(Str_8 id, DbType type, const Byte* def);
template<typename T>
DbVarTmpl(Str_8 id, const T* const def)
: hashId(id.Hash_64()), id((Str_8&&)id), def(new Byte[sizeof(T)]), size(sizeof(T))
{
Util::Copy(this->def, def, this->size);
}
DbVarTmpl(Str_8 id, DbType type);
DbVarTmpl(Str_8 id);
DbVarTmpl(DbVarTmpl&& varTmpl) noexcept;
@@ -42,27 +47,29 @@ namespace ehs
DbVarTmpl& operator=(const DbVarTmpl& varTmpl);
operator Byte *() const;
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
void SetType(DbType newType);
template<typename T>
T* GetDefaultArray() const
{
return (T*)def;
}
DbType GetType() const;
void SetIsArray(bool value);
bool IsArray() const;
template<typename T>
T GetDefault() const
{
return *(T*)def;
}
UInt_64 GetSize() const;
Byte* GetDefault() const;
private:
void UpdateSlave(const DbVar *oldSlave, DbVar *newSlave) const;
void Serialize(Serializer<UInt_64> &data) const;
void Deserialize(Serializer<UInt_64> &data);