Nebula
Loading...
Searching...
No Matches
attribute.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
17//------------------------------------------------------------------------------
18#include "ids/id.h"
19#include "util/fourcc.h"
20#include "util/stringatom.h"
21#include "util/hashtable.h"
22#include "table.h"
23#include "attributeid.h"
24
25namespace MemDb
26{
27
29{
30public:
32 template<typename T>
33 explicit Attribute(Util::StringAtom name, T const& defaultValue, uint32_t flags);
35 explicit Attribute(Util::StringAtom name, SizeT typeSizeBytes, void const* defaultValue, uint32_t flags);
37 Attribute() = default;
39 Attribute(Attribute&& desc) noexcept;
41 ~Attribute();
42
44 void operator=(Attribute&& rhs) noexcept;
46 void operator=(Attribute& rhs);
47
53 void* defVal = nullptr;
55 uint32_t externalFlags;
56};
57
58//------------------------------------------------------------------------------
61template<typename T> inline
62Attribute::Attribute(Util::StringAtom name, T const& defaultValue, uint32_t flags) :
63 name(name),
64 typeSize(sizeof(T)),
65 externalFlags(flags)
66{
67 this->defVal = Memory::Alloc(Memory::HeapType::ObjectHeap, sizeof(T));
68 Memory::Copy(&defaultValue, this->defVal, sizeof(T));
69}
70
71//------------------------------------------------------------------------------
74inline
75Attribute::Attribute(Util::StringAtom name, SizeT typeSizeBytes, void const* defaultValue, uint32_t flags) :
76 name(name),
77 typeSize(typeSizeBytes),
78 externalFlags(flags)
79{
80 if (typeSizeBytes > 0)
81 {
82 this->defVal = Memory::Alloc(Memory::HeapType::ObjectHeap, typeSizeBytes);
83 if (defaultValue != nullptr)
84 {
85 Memory::Copy(defaultValue, this->defVal, typeSizeBytes);
86 }
87 else
88 {
89 // just set everything to zero
90 Memory::Clear(this->defVal, typeSizeBytes);
91 }
92 }
93}
94
95//------------------------------------------------------------------------------
98inline
100 name(desc.name), typeSize(desc.typeSize), defVal(desc.defVal)
101{
102 desc.defVal = nullptr;
103 desc.name = nullptr;
104 desc.typeSize = 0;
105}
106
107//------------------------------------------------------------------------------
110inline
112{
113 if (this->defVal != nullptr)
114 {
115 Memory::Free(Memory::HeapType::ObjectHeap, this->defVal);
116 }
117}
118
119//------------------------------------------------------------------------------
122inline void
124{
125 this->typeSize = rhs.typeSize;
126 this->defVal = rhs.defVal;
127 this->name = rhs.name;
128
129 rhs.typeSize = 0;
130 rhs.defVal = nullptr;
131 rhs.name = nullptr;
132}
133
134//------------------------------------------------------------------------------
137inline void
139{
140 this->typeSize = rhs.typeSize;
141 this->defVal = rhs.defVal;
142 this->name = rhs.name;
143
144 rhs.typeSize = 0;
145 rhs.defVal = nullptr;
146 rhs.name = nullptr;
147}
148
149} // namespace MemDb
Definition attribute.h:29
Attribute()=default
default constructor
SizeT typeSize
size of type in bytes
Definition attribute.h:51
Util::StringAtom name
name of attribute
Definition attribute.h:49
void operator=(Attribute &&rhs) noexcept
move assignment operator
Definition attribute.h:123
uint32_t externalFlags
externally managed flags
Definition attribute.h:55
~Attribute()
desctructor
Definition attribute.h:111
void * defVal
default value
Definition attribute.h:53
A StringAtom.
Definition stringatom.h:22
Contains declarations for tables and table partitions.
Attribute.
Definition attribute.h:26
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!!!)
Definition osxmemory.cc:213
void * Alloc(HeapType heapType, size_t size, size_t alignment)
Allocate a block of memory from one of the global heaps.
Definition osxmemory.cc:56
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition osxmemory.cc:136
void Clear(void *ptr, size_t numBytes)
Overwrite a chunk of memory with 0's.
Definition osxmemory.cc:229
int SizeT
Definition types.h:49