acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
memory.h
1#pragma once
2
3
4#include "memory_base.h"
5//#include "acme/prototype/prototype/pointer.h"
6
7
8// class CLASS_DECL_ACME read_only_memory :
9// public memory_base
10// {
11// public:
12
13
14// read_only_memory(const block& block) : read_only_memory(block.get_data(), block.get_size()) {}
15
16// read_only_memory(const void *p, memsize size)
17// {
18
19// m_memory.m_bOwn = false;
20// m_memory.m_preadonlymemory = this;
21// m_memory.m_pbStorage = (::u8 *) p;
22// m_memory.m_pdata = (::u8 *) p;
23// m_memory.m_cbStorage = size;
24// m_memory.m_iSize = size;
25
26// }
27
28// };
29
30
31class CLASS_DECL_ACME memory :
32 public memory_base
33{
34public:
35
36
37 typedef memory data_type;
38
39
40 bool m_bAligned;
41
42
43 memory();
44 memory(enum_create_new, bool bAligned);
45 template < prototype_integral INTEGRAL >
46 memory(INTEGRAL i, bool bAligned = false) { this->m_pprimitivememory = this; this->m_bAligned = bAligned; this->set_size(i); }
47 memory(const ::std::initializer_list < ::i32 > & iaList);
48 memory(const ::u8 *, memsize size);
49 memory(void*, memsize size);
50 memory(const void *, memsize size);
51 memory(enum_copy_clone, const memory_base & memorybase);
52 memory(const memory_base & memorybase);
53 memory(const memory & memory);
54 memory(const ::block & block);
55 template<prototype_character CHARACTER, ::collection::count c>
56 memory(const CHARACTER (&a)[c]):
57 memory((const void *)a, (memsize)(sizeof(CHARACTER) * (c - 1)))
58 {
59 }
60 memory(memory_container * pcontainer, memsize size = 0, ::u32 uAllocFlags = 0);
61 memory(memory_container * pcontainer, const void * pdata, memsize size);
62 memory(manager * pmanager);
63 memory(const memory & memory, manager * pmanager);
64 memory(const memory * pmemory, manager * pmanager);
65 memory(const ::u8 * pchSrc, character_count nLength, manager * pmanager);
66 memory(memory && memory);
67 memory(const ::scoped_string & scopedstr);
68 memory(const ::string & str);
69 ~memory() override;
70
71
72 virtual ::u8 * impl_alloc(memsize dwAllocation) override;
73 virtual ::u8 * impl_realloc(void * pdata, memsize dwAllocation) override;
74 virtual void impl_free(::u8 * pdata) override;
75
76 using memory_base::operator =;
77 using memory_base::operator +=;
78
79
80 inline memory & operator = (const ::memory & memory) { assign(memory); return *this; }
81 inline memory & operator += (const ::memory & memory) { append(memory); return *this; };
82
83
84 character_count sz_len() const override;
85 void to_sz(char_pointer sz, character_count len) const override;
86
87
88};
89
90using memory_particle = ::make_particle1 < memory >;
91
92using memory_pointer = ::pointer< ::memory_particle>;
93
94inline memory_pointer create_memory() { return allocateø ::memory_particle (); }
95
96
97inline ::memory memory_base::slice(memsize start, memsize count)
98{
99
100 auto p = this->data() + start;
101
102 return {p, count};
103
104}
105
106
107inline ::memory memory_base::left(memsize count)
108{
109
110 auto left = minimum(count, this->size());
111
112 if (left <= 0)
113 {
114
115 return {};
116
117 }
118
119 return slice(0, left);
120
121}
122
123
124inline ::memory memory_base::right(memsize count)
125{
126
127 auto start = this->size() - count;
128
129 if (start <= 0)
130 {
131
132 return {};
133
134 }
135
136 return slice(start, count);
137
138}
139
140
141
142inline void memory_base::set_char_at_grow(character_count iChar, ::i8 ch)
143{
144
145 if (::comparison::ge(iChar, size()))
146 {
147
148 set_size(iChar + 1);
149
150 }
151
152 ((char_pointer )data())[iChar] = ch;
153
154}
155
Definition memory_container.h:15