EHS/include/ehs/db/DbVar.h

106 lines
1.7 KiB
C
Raw Normal View History

2024-04-08 03:10:24 -07:00
#pragma once
#include "ehs/Types.h"
#include "ehs/Serializer.h"
2024-04-08 03:10:24 -07:00
namespace ehs
{
class DbVarTmpl;
class DbObject;
2024-04-08 03:10:24 -07:00
class DbVar
{
private:
friend class DbObject;
2024-04-08 03:10:24 -07:00
UInt_64 hashId;
DbObject *parent;
2024-04-10 18:26:20 -07:00
Byte *value;
2024-04-08 03:10:24 -07:00
UInt_64 size;
public:
~DbVar();
DbVar();
2024-04-10 18:26:20 -07:00
DbVar(UInt_64 hashId, const DbVarTmpl *master);
2024-04-08 03:10:24 -07:00
DbVar(DbVar &&var) noexcept;
2024-04-08 03:10:24 -07:00
DbVar(const DbVar &var);
2024-04-08 03:10:24 -07:00
DbVar &operator=(DbVar &&var) noexcept;
2024-04-08 03:10:24 -07:00
DbVar &operator=(const DbVar &var);
2024-04-08 03:10:24 -07:00
explicit operator Byte *() const;
2024-04-08 03:10:24 -07:00
UInt_64 GetHashId() const;
2024-04-10 18:26:20 -07:00
template<typename T>
void SetValueArray(const T* const newValue, const UInt_64 newSize)
{
size = sizeof(T) * newSize;
value = new Byte[size];
Util::Copy(value, newValue, size);
}
template<typename T = Char_8>
void SetValueStr(const T * const newValue)
{
size = sizeof(T) * Str<Char_8, UInt_64>::Len(newValue);
value = new Byte[size];
Util::Copy(value, newValue, size);
}
template<typename T = Char_8, typename I = UInt_64>
void SetValueStr(const Str<T, I>& newValue)
{
size = newValue.Size(true);
2024-04-08 03:10:24 -07:00
2024-04-10 18:26:20 -07:00
value = new Byte[size];
2024-04-10 18:26:20 -07:00
Util::Copy(value, &newValue[0], size);
}
2024-04-10 18:26:20 -07:00
template<typename T>
void SetValue(const Byte* newValue)
{
size = sizeof(T);
value = new Byte[size];
Util::Copy(value, newValue, size);
}
template<typename T>
T* GetValueArray() const
{
return (T*)value;
}
template<typename T = Char_8, typename I = UInt_64>
Str<T, I> GetValueStr() const
{
return {(T*)value, size / sizeof(T)};
}
template<typename T>
T GetValue() const
{
return *(T*)value;
}
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
};
}