acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
memory_container.h
1#pragma once
2
3
4#include "memory_base.h"
6#include "memory.h"
7
8
9class shared_memory;
10class paged_memory;
11
12
13class CLASS_DECL_ACME memory_container :
14 virtual public ::particle
15{
16protected:
17
18
19 ::pointer<memory_base> m_pmemory;
20
21
22public:
23
24
25 ::u8 * m_pbyte;
26 //memsize m_memsize;
27
28
29 memory_container(memsize size = 0);
30 memory_container(const memory_container & container);
31 memory_container(const void * pdata, memsize size);
32 template < prototype_payload PAYLOAD >
33 memory_container(PAYLOAD & payload);
34 memory_container(memory_base & memory);
35 memory_container(const ::pointer < memory_base > & pmemory);
36 memory_container(::pointer < memory_base >&& pmemory);
37 template < typename MEMORY>
38 memory_container(const ::pointer<MEMORY> pmemory, ::file::e_open eopen = {}) : memory_container((MEMORY*)pmemory.get(), eopen) {}
39 virtual ~memory_container();
40
41 virtual void create_default_memory();
42
43 inline void defer_create_default_memory() { if (!m_pmemory) create_default_memory(); }
44
45 void allocate_add_up(memsize dwAddUp);
46 void set_size(memsize dwNewLength);
47 void allocate_internal(memsize dwNewLength);
48
49 virtual ::pointer<memory_base>create_memory(const void * p = nullptr, memsize s = 0);
50 ::pointer<memory_base>get_memory();
51 void set_memory(::pointer<memory_base>pmemory);
52
53
54 inline memory_base & memory() { return *get_memory(); }
55
56 memsize size() const { return ::is_null(m_pmemory) ? 0 : m_pmemory->size(); }
57
58 memsize storage_size() const { return m_pmemory->storage_size(); }
59
60 void from_string(const ::wide_character * pwsz);
61 void from_string(const ::scoped_string & scopedstr);
62 void from_string(const ::string & str);
63 template < prototype_payload PAYLOAD >
64 void from_string(const PAYLOAD & payload);
65 ::string as_string() const override;
66 virtual ::memory as_memory() const;
67
68 void read(memory_base *pmemorystorage);
69
70 //virtual stream & write(::stream & stream) const override;
71 //virtual stream & read(::stream & stream) override;
72
73 ::u8 * data() { return ::is_set(m_pmemory)?m_pmemory->data():nullptr; }
74 const ::u8 * data() const { return ::is_set(m_pmemory) ? m_pmemory->data() : nullptr; }
75
76 ::u8 * begin() { return data(); }
77 const ::u8 * begin() const { return data(); }
78
79 ::u8 * end() { return ::is_set(m_pmemory) ? m_pmemory->end() : nullptr; }
80 const ::u8 * end() const { return ::is_set(m_pmemory) ? m_pmemory->end() : nullptr; }
81
82 //::u8 * get_data_raw();
83 //const ::u8 * get_data_raw() const;
84
85 virtual bool is_valid() const;
86
87 void copy_this(const memory_container & container);
88
89 memory_container & operator =(const memory_container &container);
90
91 bool attach(memory_base *pstorage);
92
93 ::pointer < memory_base > detach();
94
95 virtual class memory * get_primitive_memory();
96#if !defined(UNIVERSAL_WINDOWS)
97 virtual shared_memory * get_shared_memory();
98#endif
99 paged_memory * get_virtual_memory();
100
101
102 //string as_string() const;
103 void set_string(const ::scoped_string & scopedstr);
104
105
106};
107
108
109//inline ::u8 * memory_container::get_data_raw()
110//{
111//
112// return m_pmemory->get_data();
113//
114//}
115//
116//inline const ::u8 * memory_container::get_data_raw() const
117//{
118//
119// return m_pmemory->get_data();
120//
121//}
122//
123//inline memsize memory_container::get_size_raw() const
124//{
125// return m_pmemory->get_size();
126//}
127//
128//
129//inline ::u8 * memory_container ::get_data()
130//{
131//
132// return m_pmemory.is_null() ? 0 : get_data_raw();
133//
134//}
135//
136//inline const ::u8 * memory_container ::get_data() const
137//{
138//
139// return m_pmemory.is_null() ? 0 : get_data_raw();
140//
141//}
142//
143//inline memsize memory_container ::get_size() const
144//{
145// return m_pmemory.is_null() ? 0 : get_size_raw();
146//}
147//
148
149inline void memory_container ::from_string(const ::wide_character * pwsz)
150{
151
152 if(m_pmemory.is_null())
153 m_pmemory = create_memory();
154
155 m_pmemory->from_string(pwsz);
156
157}
158
159
160inline void memory_container ::from_string(const ::scoped_string & scopedstr)
161{
162
163 if(m_pmemory.is_null())
164 m_pmemory = create_memory();
165
166 m_pmemory->from_string(scopedstr);
167
168}
169
170
171inline void memory_container ::from_string(const ::string & str)
172{
173
174 if(m_pmemory.is_null())
175 {
176
177 m_pmemory = create_memory();
178
179 }
180
181 m_pmemory->from_string(str);
182
183}
184
185
186template < prototype_payload PAYLOAD >
187inline void memory_container ::from_string(const PAYLOAD & payload)
188{
189
190 if(m_pmemory.is_null())
191 m_pmemory = create_memory();
192
193 m_pmemory->from_string(payload);
194
195}
196
197
198//inline string memory_container::as_string() const
199//{
200//
201// if (!m_pmemory)
202// {
203//
204// return "";
205//
206// }
207//
208// return m_pmemory->as_string();
209//
210//}
211
212
213inline ::string memory_container::as_string() const
214{
215
216 return { (const_char_pointer )data(), size() };
217
218}
219
220
221inline ::memory memory_container::as_memory() const
222{
223
224 return { data(), size() };
225
226}
227
228
229template < prototype_payload PAYLOAD >
230memory_container::memory_container(PAYLOAD & payload)
231{
232
233 m_pmemory = &payload.memory_reference();
234 m_pbyte = m_pmemory->data();
235 //m_memsize = m_pmemory->size();
236
237}
Definition memory_base.h:28
Definition memory_base.h:92
Definition paged_memory.h:9
Definition payload.h:54
Definition shared_memory.h:15