Started work on database handling.

This commit is contained in:
2024-04-08 03:10:24 -07:00
parent 405acb026f
commit beba947c69
22 changed files with 918 additions and 44 deletions

36
include/ehs/db/Database.h Normal file
View File

@@ -0,0 +1,36 @@
#pragma once
#include "ehs/Array.h"
#include "DbTable.h"
namespace ehs
{
class Database
{
private:
UInt_64 hashId;
Str_8 id;
Array<DbTable> tables;
public:
Database();
Database(const Str_8& filePath);
UInt_64 GetHashId() const;
Str_8 GetId() const;
bool HasTable(UInt_64 hashId) const;
bool HasTable(Str_8& id) const;
bool CreateTable(Str_8 id);
DbTable* GetTable(UInt_64 hashId) const;
DbTable* GetTable(Str_8& id) const;
void Save();
};
}

47
include/ehs/db/DbObject.h Normal file
View File

@@ -0,0 +1,47 @@
#pragma once
#include "ehs/Array.h"
#include "DbVar.h"
namespace ehs
{
class DbTable;
class DbObject
{
private:
friend class DbTable;
UInt_64 id;
Array<DbVar> vars;
bool loaded;
DbTable* parent;
public:
DbObject();
DbObject(DbObject&& obj) noexcept;
DbObject(const DbObject& obj);
DbObject& operator=(DbObject&& obj) noexcept;
DbObject& operator=(const DbObject& obj);
UInt_64 GetId();
bool HasVariable(UInt_64 hashId);
DbVar* GetVariable(UInt_64 hashId) const;
void Save();
void Load();
bool IsLoaded() const;
void Free();
DbTable* GetParent() const;
};
}

36
include/ehs/db/DbTable.h Normal file
View File

@@ -0,0 +1,36 @@
#pragma once
#include "ehs/Version.h"
#include "ehs/Array.h"
#include "DbVarTmpl.h"
#include "DbObject.h"
namespace ehs
{
class DbTable
{
private:
UInt_64 hashId;
Str_8 id;
Version version;
Array<DbVarTmpl> varTmpls;
Array<DbObject> objects;
public:
DbTable();
DbTable();
UInt_64 GetHashId() const;
Str_8 GetId() const;
Version GetVersion() const;
bool CreateVariable(Str_8 id, DbType type);
bool CreateVariable(Str_8 id, DbType type, UInt_64 size);
void Save();
};
}

26
include/ehs/db/DbType.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include "ehs/Types.h"
namespace ehs
{
enum class DbType : UInt_8
{
SINT_64,
UINT_64,
SINT_32,
UINT_32,
SINT_16,
UINT_16,
SINT_8,
UINT_8,
FLOAT,
DOUBLE,
BOOLEAN,
CHAR_32,
CHAR_16,
CHAR_8
};
constexpr UInt_8 DbTypeToSize(DbType type);
}

37
include/ehs/db/DbVar.h Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include "ehs/Types.h"
namespace ehs
{
class DbVar
{
private:
UInt_64 hashId;
UInt_64 size;
Byte* data;
public:
~DbVar();
DbVar();
DbVar(UInt_64 hashId, UInt_64 size, Byte* data);
DbVar(DbVar&& var) noexcept;
DbVar(const DbVar& var);
DbVar& operator=(DbVar&& var) noexcept;
DbVar& operator=(const DbVar& var);
explicit operator Byte*() const;
UInt_64 GetHashId() const;
UInt_64 GetSize() const;
Byte* GetData() const;
};
}

View File

@@ -0,0 +1,45 @@
#pragma once
#include "DbType.h"
#include "ehs/EHS.h"
#include "ehs/BaseObj.h"
#include "ehs/Str.h"
namespace ehs
{
class DbVarTmpl : public BaseObj
{
private:
UInt_64 hashId;
Str_8 id;
DbType type;
bool array;
public:
DbVarTmpl();
DbVarTmpl(Str_8 id, DbType type, bool array);
DbVarTmpl(DbVarTmpl&& varTmpl) noexcept;
DbVarTmpl(const DbVarTmpl& varTmpl);
DbVarTmpl& operator=(DbVarTmpl&& varTmpl) noexcept;
DbVarTmpl& operator=(const DbVarTmpl& varTmpl);
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
void SetType(DbType newType);
DbType GetType() const;
void SetIsArray(bool value);
bool IsArray() const;
};
}