Database implementation mostly complete.
This commit is contained in:
@@ -1044,7 +1044,10 @@ namespace ehs
|
||||
void ReadArray(T* const value, O* const size)
|
||||
{
|
||||
if (!*size)
|
||||
*size = (O)Read<N>();
|
||||
{
|
||||
*size = (O)Read<N>();
|
||||
return;
|
||||
}
|
||||
|
||||
for (N i = 0; i < *size; ++i)
|
||||
value[i] = Read<T>();
|
||||
|
@@ -10,27 +10,44 @@ namespace ehs
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Version version;
|
||||
Array<DbTable> tables;
|
||||
|
||||
public:
|
||||
Database();
|
||||
|
||||
Database(Str_8 id, const Version& version);
|
||||
|
||||
Database(const Str_8& filePath);
|
||||
|
||||
Database(Database&& db) noexcept;
|
||||
|
||||
Database(const Database& db);
|
||||
|
||||
Database& operator=(Database&& db) noexcept;
|
||||
|
||||
Database& operator=(const Database& db);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void SetVersion(const Version& newVersion);
|
||||
|
||||
Version GetVersion() const;
|
||||
|
||||
bool HasTable(UInt_64 hashId) const;
|
||||
|
||||
bool HasTable(Str_8& id) const;
|
||||
bool HasTable(const Str_8& id) const;
|
||||
|
||||
bool CreateTable(Str_8 id);
|
||||
DbTable* CreateTable(Str_8 id);
|
||||
|
||||
DbTable* GetTable(UInt_64 hashId) const;
|
||||
|
||||
DbTable* GetTable(Str_8& id) const;
|
||||
DbTable* GetTable(const Str_8& id) const;
|
||||
|
||||
void Save();
|
||||
void Save(const Str_8& directory) const;
|
||||
};
|
||||
}
|
@@ -11,15 +11,17 @@ namespace ehs
|
||||
{
|
||||
private:
|
||||
friend class DbTable;
|
||||
friend class DbVar;
|
||||
|
||||
UInt_64 id;
|
||||
Array<DbVar> vars;
|
||||
bool loaded;
|
||||
DbTable* parent;
|
||||
Array<DbVar> vars;
|
||||
|
||||
public:
|
||||
DbObject();
|
||||
|
||||
DbObject(UInt_64 id);
|
||||
|
||||
DbObject(DbObject&& obj) noexcept;
|
||||
|
||||
DbObject(const DbObject& obj);
|
||||
@@ -28,13 +30,13 @@ namespace ehs
|
||||
|
||||
DbObject& operator=(const DbObject& obj);
|
||||
|
||||
UInt_64 GetId();
|
||||
UInt_64 GetId() const;
|
||||
|
||||
bool HasVariable(UInt_64 hashId);
|
||||
bool HasVariable(UInt_64 hashId) const;
|
||||
|
||||
DbVar* GetVariable(UInt_64 hashId) const;
|
||||
|
||||
void Save();
|
||||
void Save() const;
|
||||
|
||||
void Load();
|
||||
|
||||
@@ -42,6 +44,7 @@ namespace ehs
|
||||
|
||||
void Free();
|
||||
|
||||
DbTable* GetParent() const;
|
||||
private:
|
||||
void CreateVariable(DbVarTmpl* master);
|
||||
};
|
||||
}
|
@@ -4,33 +4,55 @@
|
||||
#include "ehs/Array.h"
|
||||
#include "DbVarTmpl.h"
|
||||
#include "DbObject.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbTable
|
||||
{
|
||||
private:
|
||||
friend class Database;
|
||||
friend class DbVar;
|
||||
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Version version;
|
||||
Array<DbVarTmpl> varTmpls;
|
||||
Array<DbObject> objects;
|
||||
|
||||
public:
|
||||
DbTable();
|
||||
|
||||
DbTable();
|
||||
DbTable(Str_8 id);
|
||||
|
||||
DbTable(DbTable&& table) noexcept;
|
||||
|
||||
DbTable(const DbTable& table);
|
||||
|
||||
DbTable& operator=(DbTable&& table) noexcept;
|
||||
|
||||
DbTable& operator=(const DbTable& table);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
Version GetVersion() const;
|
||||
bool HasVariable(UInt_64 hashId) const;
|
||||
|
||||
bool CreateVariable(Str_8 id, DbType type);
|
||||
bool HasVariable(const Str_8& id) const;
|
||||
|
||||
bool CreateVariable(Str_8 id, DbType type, UInt_64 size);
|
||||
bool CreateVariable(Str_8 id, DbType type, const Byte* defaultValue);
|
||||
|
||||
void Save();
|
||||
bool CreateVariable(Str_8 id, DbType type, UInt_64 size, const Byte* defaultValue);
|
||||
|
||||
DbObject *CreateObject();
|
||||
|
||||
private:
|
||||
DbVarTmpl* GetVariableTemplate(UInt_64 hashId) const;
|
||||
|
||||
void Serialize(Serializer<UInt_64>& data) const;
|
||||
|
||||
void Deserialize(Serializer<UInt_64>& data);
|
||||
};
|
||||
}
|
||||
|
@@ -22,5 +22,40 @@ namespace ehs
|
||||
CHAR_8
|
||||
};
|
||||
|
||||
constexpr UInt_8 DbTypeToSize(DbType type);
|
||||
constexpr UInt_8 DbTypeToSize(const DbType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DbType::SINT_64:
|
||||
return 8;
|
||||
case DbType::UINT_64:
|
||||
return 8;
|
||||
case DbType::SINT_32:
|
||||
return 4;
|
||||
case DbType::UINT_32:
|
||||
return 4;
|
||||
case DbType::SINT_16:
|
||||
return 2;
|
||||
case DbType::UINT_16:
|
||||
return 2;
|
||||
case DbType::SINT_8:
|
||||
return 1;
|
||||
case DbType::UINT_8:
|
||||
return 1;
|
||||
case DbType::FLOAT:
|
||||
return 4;
|
||||
case DbType::DOUBLE:
|
||||
return 8;
|
||||
case DbType::BOOLEAN:
|
||||
return 1;
|
||||
case DbType::CHAR_32:
|
||||
return 4;
|
||||
case DbType::CHAR_16:
|
||||
return 2;
|
||||
case DbType::CHAR_8:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "DbType.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbVarTmpl;
|
||||
class DbObject;
|
||||
|
||||
class DbVar
|
||||
{
|
||||
private:
|
||||
friend class DbObject;
|
||||
friend class DbVarTmpl;
|
||||
|
||||
UInt_64 hashId;
|
||||
DbObject *parent;
|
||||
DbVarTmpl *master;
|
||||
UInt_64 size;
|
||||
Byte* data;
|
||||
Byte *data;
|
||||
|
||||
public:
|
||||
~DbVar();
|
||||
|
||||
DbVar();
|
||||
|
||||
DbVar(UInt_64 hashId, UInt_64 size, Byte* data);
|
||||
DbVar(UInt_64 hashId, DbVarTmpl *master, UInt_64 size, const Byte *data);
|
||||
|
||||
DbVar(DbVar&& var) noexcept;
|
||||
DbVar(DbVar &&var) noexcept;
|
||||
|
||||
DbVar(const DbVar& var);
|
||||
DbVar(const DbVar &var);
|
||||
|
||||
DbVar& operator=(DbVar&& var) noexcept;
|
||||
DbVar &operator=(DbVar &&var) noexcept;
|
||||
|
||||
DbVar& operator=(const DbVar& var);
|
||||
DbVar &operator=(const DbVar &var);
|
||||
|
||||
explicit operator Byte*() const;
|
||||
explicit operator Byte *() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
void SetData(UInt_64 newSize, const Byte* newData);
|
||||
|
||||
void SetData(const Byte* newData);
|
||||
|
||||
Byte* GetData() const;
|
||||
|
||||
private:
|
||||
void Serialize(Serializer<UInt_64> &data) const;
|
||||
|
||||
void Deserialize(Serializer<UInt_64> &data);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -2,23 +2,35 @@
|
||||
|
||||
#include "DbType.h"
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DbVarTmpl : public BaseObj
|
||||
class DbVar;
|
||||
|
||||
class DbVarTmpl
|
||||
{
|
||||
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;
|
||||
|
||||
public:
|
||||
~DbVarTmpl();
|
||||
|
||||
DbVarTmpl();
|
||||
|
||||
DbVarTmpl(Str_8 id, DbType type, bool array);
|
||||
DbVarTmpl(Str_8 id, DbType type, UInt_64 size, const Byte* def);
|
||||
|
||||
DbVarTmpl(Str_8 id, DbType type, const Byte* def);
|
||||
|
||||
DbVarTmpl(DbVarTmpl&& varTmpl) noexcept;
|
||||
|
||||
@@ -41,5 +53,16 @@ namespace ehs
|
||||
void SetIsArray(bool value);
|
||||
|
||||
bool IsArray() const;
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
13
include/ehs/io/BaseDirectory.h
Normal file
13
include/ehs/io/BaseDirectory.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class BaseDirectory
|
||||
{
|
||||
public:
|
||||
static Array<Str_8> GetAllFiles(const Str_8& dir);
|
||||
};
|
||||
}
|
9
include/ehs/io/Directory.h
Normal file
9
include/ehs/io/Directory.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/system/OS.h"
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "Directory_W32.h"
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#include "Directory_LNX.h"
|
||||
#endif
|
12
include/ehs/io/Directory_LNX.h
Normal file
12
include/ehs/io/Directory_LNX.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseDirectory.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Directory : public BaseDirectory
|
||||
{
|
||||
public:
|
||||
static Array<Str_8> GetAllFiles(const Str_8& dir);
|
||||
};
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/system/OS.h"
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "File_W32.h"
|
||||
|
Reference in New Issue
Block a user