EHS
DbVar.h
Go to the documentation of this file.
1#pragma once
2
3#include "ehs/Types.h"
4#include "ehs/Serializer.h"
5
6namespace ehs
7{
8 class DbVarTmpl;
9 class DbObject;
10
11 class EHS_LIB_IO DbVar
12 {
13 private:
14 friend class DbObject;
15
16 UInt_64 hashId;
17 DbObject *parent;
18 Byte *value;
19 UInt_64 size;
20
21 public:
22 ~DbVar();
23
24 DbVar();
25
26 DbVar(UInt_64 hashId, const DbVarTmpl *master);
27
28 DbVar(DbVar &&var) noexcept;
29
30 DbVar(const DbVar &var);
31
32 DbVar &operator=(DbVar &&var) noexcept;
33
34 DbVar &operator=(const DbVar &var);
35
36 explicit operator Byte *() const;
37
38 UInt_64 GetHashId() const;
39
40 template<typename T>
41 void SetValueArray(const T* const newValue, const UInt_64 newSize)
42 {
43 size = sizeof(T) * newSize;
44
45 value = new Byte[size];
46
47 Util::Copy(value, newValue, size);
48 }
49
50 template<typename T = Char_8>
51 void SetValueStr(const T * const newValue)
52 {
53 size = sizeof(T) * Str<Char_8, UInt_64>::Len(newValue);
54
55 value = new Byte[size];
56
57 Util::Copy(value, newValue, size);
58 }
59
60 template<typename T = Char_8, typename I = UInt_64>
61 void SetValueStr(const Str<T, I>& newValue)
62 {
63 size = newValue.Size(true);
64
65 value = new Byte[size];
66
67 Util::Copy(value, &newValue[0], size);
68 }
69
70 template<typename T>
71 void SetValue(const Byte* newValue)
72 {
73 size = sizeof(T);
74
75 value = new Byte[size];
76
77 Util::Copy(value, newValue, size);
78 }
79
80 template<typename T>
81 T* GetValueArray() const
82 {
83 return (T*)value;
84 }
85
86 template<typename T = Char_8, typename I = UInt_64>
88 {
89 return {(T*)value, size / sizeof(T)};
90 }
91
92 template<typename T>
93 T GetValue() const
94 {
95 return *(T*)value;
96 }
97
98 UInt_64 GetSize() const;
99
100 private:
101 void Serialize(Serializer<UInt_64> &data) const;
102
103 void Deserialize(Serializer<UInt_64> &data);
104 };
105}
Definition: DbObject.h:11
Definition: DbVarTmpl.h:12
Definition: DbVar.h:12
void SetValueArray(const T *const newValue, const UInt_64 newSize)
Definition: DbVar.h:41
void SetValueStr(const Str< T, I > &newValue)
Definition: DbVar.h:61
T GetValue() const
Definition: DbVar.h:93
T * GetValueArray() const
Definition: DbVar.h:81
void SetValueStr(const T *const newValue)
Definition: DbVar.h:51
Str< T, I > GetValueStr() const
Definition: DbVar.h:87
void SetValue(const Byte *newValue)
Definition: DbVar.h:71
Definition: Str.h:29
N Size(bool inBytes=false) const
Definition: Str.h:526
static void Copy(void *out, const void *in, UInt_64 size)
Definition: Util.cpp:53
Definition: Anchor.h:6
unsigned char Byte
Definition: Types.h:39