#pragma once #include "ehs/Types.h" #include "ehs/Serializer.h" namespace ehs { class DbVarTmpl; class DbObject; class DbVar { private: friend class DbObject; UInt_64 hashId; DbObject *parent; Byte *value; UInt_64 size; public: ~DbVar(); DbVar(); DbVar(UInt_64 hashId, const DbVarTmpl *master); 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; template void SetValueArray(const T* const newValue, const UInt_64 newSize) { size = sizeof(T) * newSize; value = new Byte[size]; Util::Copy(value, newValue, size); } template void SetValueStr(const T * const newValue) { size = sizeof(T) * Str::Len(newValue); value = new Byte[size]; Util::Copy(value, newValue, size); } template void SetValueStr(const Str& newValue) { size = newValue.Size(true); value = new Byte[size]; Util::Copy(value, &newValue[0], size); } template void SetValue(const Byte* newValue) { size = sizeof(T); value = new Byte[size]; Util::Copy(value, newValue, size); } template T* GetValueArray() const { return (T*)value; } template Str GetValueStr() const { return {(T*)value, size / sizeof(T)}; } template T GetValue() const { return *(T*)value; } UInt_64 GetSize() const; private: void Serialize(Serializer &data) const; void Deserialize(Serializer &data); }; }