acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
chunk.h
1
// Created by camilo on 2021-09-18 21:32 BRT <3ThomasBorregaardSorensen!! (I need to suck you).
2
#pragma once
3
4
5
class
chunk
6
{
7
8
void
* m_p =
nullptr
;
9
10
memsize m_size = 0;
11
12
public
:
13
14
15
chunk(
const
void
* p =
nullptr
, memsize s = 0)
16
{
17
18
assign(p, s);
19
}
20
chunk(
const
chunk & chunk)
21
{
22
23
assign(chunk.m_p, chunk.m_size);
24
}
25
~chunk()
26
{
27
28
destroy();
29
30
}
31
32
void
destroy()
33
{
34
if
(m_p)
35
{
36
37
::acme::get()->m_pheapmanagement->memory(::heap::e_memory_main)->free(m_p);
38
39
}
40
m_p =
nullptr
;
41
m_size = 0;
42
43
}
44
45
chunk & operator =(
const
chunk & chunk)
46
{
47
48
if
(
this
!= &chunk)
49
{
50
51
destroy();
52
assign(chunk.m_p, chunk.m_size);
53
54
}
55
56
return
*
this
;
57
58
}
59
60
memsize size()
const
{
return
m_size; }
61
62
operator
void
* () {
return
m_p; }
63
operator
const
void
* ()
const
{
return
m_p; }
64
65
void
assign(
const
void
* p, memsize s)
66
{
67
68
if
(s <= 0)
69
{
70
71
destroy();
72
}
73
74
m_p = ::acme::get()->m_pheapmanagement->memory(::heap::e_memory_main)->allocate(s,
nullptr
);
75
76
if
(::is_set(m_p))
77
{
78
79
memory_copy(m_p, p, s);
80
81
m_size = s;
82
83
}
84
85
}
86
87
bool
operator == (
const
chunk & chunk)
const
88
{
89
90
if
(::is_null(m_p))
91
{
92
93
if
(::is_null(chunk.m_p))
94
{
95
96
return
true
;
97
98
}
99
else
100
{
101
102
return
false
;
103
104
}
105
106
}
107
else
if
(::is_null(chunk.m_p))
108
{
109
110
return
false
;
111
112
}
113
114
if
(m_size != chunk.m_size)
115
{
116
117
return
false
;
118
119
}
120
121
return
memory_order(m_p, chunk.m_p, m_size) == 0;
122
123
}
124
125
bool
operator !=(
const
chunk & chunk)
const
126
{
127
128
return
!operator==(chunk);
129
130
}
131
132
133
};
134
135
136
memory
chunk.h
Generated by
1.17.0