Nebula
Toggle main menu visibility
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
25
namespace
MemDb
26
{
27
28
class
Attribute
29
{
30
public
:
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
49
Util::StringAtom
name
;
51
SizeT
typeSize
= 0;
53
void
*
defVal
=
nullptr
;
55
uint32_t
externalFlags
;
56
};
57
58
//------------------------------------------------------------------------------
61
template
<
typename
T>
inline
62
Attribute::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
//------------------------------------------------------------------------------
74
inline
75
Attribute::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
//------------------------------------------------------------------------------
98
inline
99
Attribute::Attribute
(
Attribute
&& desc) noexcept :
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
//------------------------------------------------------------------------------
110
inline
111
Attribute::~Attribute
()
112
{
113
if
(this->
defVal
!=
nullptr
)
114
{
115
Memory::Free
(Memory::HeapType::ObjectHeap, this->
defVal
);
116
}
117
}
118
119
//------------------------------------------------------------------------------
122
inline
void
123
Attribute::operator=
(
Attribute
&& rhs)
noexcept
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
//------------------------------------------------------------------------------
137
inline
void
138
Attribute::operator=
(
Attribute
& rhs)
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
attributeid.h
MemDb::Attribute::Attribute
Attribute()=default
default constructor
MemDb::Attribute::typeSize
SizeT typeSize
size of type in bytes
Definition
attribute.h:51
MemDb::Attribute::name
Util::StringAtom name
name of attribute
Definition
attribute.h:49
MemDb::Attribute::operator=
void operator=(Attribute &&rhs) noexcept
move assignment operator
Definition
attribute.h:123
MemDb::Attribute::externalFlags
uint32_t externalFlags
externally managed flags
Definition
attribute.h:55
MemDb::Attribute::~Attribute
~Attribute()
desctructor
Definition
attribute.h:111
MemDb::Attribute::defVal
void * defVal
default value
Definition
attribute.h:53
MemDb::Attribute::Attribute
Attribute(Util::StringAtom name, T const &defaultValue, uint32_t flags)
construct from template type, with default value.
Definition
attribute.h:62
Util::StringAtom
A StringAtom.
Definition
stringatom.h:22
fourcc.h
hashtable.h
id.h
table.h
Contains declarations for tables and table partitions.
MemDb
Attribute.
Definition
attribute.h:26
Memory::Copy
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
Memory::Alloc
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
Memory::Free
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition
osxmemory.cc:136
Memory::Clear
void Clear(void *ptr, size_t numBytes)
Overwrite a chunk of memory with 0's.
Definition
osxmemory.cc:229
stringatom.h
SizeT
int SizeT
Definition
types.h:42
code
addons
memdb
attribute.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.