EHS/include/ehs/db/DbVarTmpl.h

78 lines
1.3 KiB
C
Raw Normal View History

2024-04-08 03:10:24 -07:00
#pragma once
#include "ehs/EHS.h"
#include "ehs/Serializer.h"
2024-04-08 03:10:24 -07:00
#include "ehs/Str.h"
namespace ehs
{
class DbVar;
class DbVarTmpl
2024-04-08 03:10:24 -07:00
{
private:
friend class DbTable;
2024-04-08 03:10:24 -07:00
UInt_64 hashId;
Str_8 id;
Byte* def;
2024-04-10 18:26:20 -07:00
UInt_64 size;
2024-04-08 03:10:24 -07:00
public:
~DbVarTmpl();
2024-04-08 03:10:24 -07:00
DbVarTmpl();
2024-04-10 18:26:20 -07:00
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);
}
2024-04-10 18:26:20 -07:00
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);
}
2024-04-08 03:10:24 -07:00
2024-04-10 18:26:20 -07:00
DbVarTmpl(Str_8 id);
2024-04-08 03:10:24 -07:00
DbVarTmpl(DbVarTmpl&& varTmpl) noexcept;
DbVarTmpl(const DbVarTmpl& varTmpl);
DbVarTmpl& operator=(DbVarTmpl&& varTmpl) noexcept;
DbVarTmpl& operator=(const DbVarTmpl& varTmpl);
2024-04-10 18:26:20 -07:00
operator Byte *() const;
2024-04-08 03:10:24 -07:00
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
2024-04-10 18:26:20 -07:00
template<typename T>
T* GetDefaultArray() const
{
return (T*)def;
}
2024-04-08 03:10:24 -07:00
2024-04-10 18:26:20 -07:00
template<typename T>
T GetDefault() const
{
return *(T*)def;
}
UInt_64 GetSize() const;
private:
void Serialize(Serializer<UInt_64> &data) const;
void Deserialize(Serializer<UInt_64> &data);
2024-04-08 03:10:24 -07:00
};
}