acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_array_binary_stream.h
1// From file/binary_stream.h by camilo on 2022-10-14 23:46 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include "acme/filesystem/file/binary_stream.h"
6
7
8template < prototype_particle_array POINTER_ARRAY >
9inline binary_stream & operator <<(binary_stream & stream, const POINTER_ARRAY & a)
10{
11
12 ::collection::count c = a.get_count();
13
14 stream << c;
15
16 for (auto & p : a)
17 {
18
19 stream.write_particle(p.m_p);
20
21 if (stream.nok())
22 {
23
24 break;
25
26 }
27
28 }
29
30 return stream;
31
32}
33
34
35template < prototype_particle_array POINTER_ARRAY >
36inline binary_stream & operator >>(binary_stream & stream, POINTER_ARRAY & a)
37{
38
39 ::collection::count c;
40
41 stream >> c;
42
43 if (stream.nok())
44 {
45
46 return stream;
47
48 }
49
50 a.set_size(c);
51
52 ::collection::index i = 0;
53
54 try
55 {
56
57 for (; i < c && stream.has_ok_flag(); i++)
58 {
59
60 a[i] = stream.read_particle();
61
62 }
63
64 }
65 catch (...)
66 {
67
68 stream.set_nok();
69
70 }
71
72 if (stream.nok())
73 {
74
75 a.set_size(i);
76
77 }
78
79 return stream;
80
81}
82
83
84template < prototype_object_array ARRAY >
85inline binary_stream & operator <<(binary_stream & stream, const ARRAY & a)
86{
87
88 ::collection::count c = a.get_count();
89
90 stream << c;
91
92 for (auto & element : a)
93 {
94
95 stream << element;
96
97 if (stream.nok())
98 {
99
100 break;
101
102 }
103
104 }
105
106 return stream;
107
108}
109
110
111template < prototype_object_array ARRAY >
112inline binary_stream & operator >>(binary_stream & stream, ARRAY & a)
113{
114
115 ::collection::count c;
116
117 stream >> c;
118
119 if (stream.nok() || c <= 0)
120 {
121
122 return stream;
123
124 }
125
126 a.set_size(c);
127
128 ::collection::index i = 0;
129
130 try
131 {
132
133 for (; i < c && stream.has_ok_flag(); i++)
134 {
135
136 stream >> a[i];
137
138 }
139
140 }
141 catch (...)
142 {
143
144 stream.set_nok();
145
146 }
147
148 if (stream.nok())
149 {
150
151 a.set_size(i);
152
153 }
154
155 return stream;
156
157}
158
159
160template < prototype_raw_pointer_array ARRAY >
161inline binary_stream & operator <<(binary_stream & stream, const ARRAY & a)
162{
163
164 ::collection::count c = a.get_count();
165
166 stream << c;
167
168 for (auto & p : a)
169 {
170
171 stream << *p;
172
173 if (stream.nok())
174 {
175
176 break;
177
178 }
179
180 }
181
182 return stream;
183
184}
185
186
187template < prototype_raw_pointer_array ARRAY >
188inline binary_stream & operator >>(binary_stream & stream, ARRAY & a)
189{
190
191 ::collection::count c;
192
193 stream >> c;
194
195 if (stream.nok())
196 {
197
198 return stream;
199
200 }
201
202 a.set_size(c);
203
204 ::collection::index i = 0;
205
206 try
207 {
208
209 for (; i < c && stream.has_ok_flag(); i++)
210 {
211
212 auto p = ___new typename ARRAY::BASE_TYPE();
213
214 a[i] = p;
215
216 stream >> *p;
217
218 }
219
220 }
221 catch (...)
222 {
223
224 stream.set_nok();
225
226 }
227
228 if (stream.nok())
229 {
230
231 a.set_size(i);
232
233 }
234
235 return stream;
236
237}
238
239
240template < prototype_raw_type_array ARRAY >
241inline binary_stream & operator <<(binary_stream & stream, const ARRAY & a)
242{
243
244 ::collection::count c = a.get_count();
245
246 stream << c;
247
248 stream.write({ a.get_data(), sizeof(typename ARRAY::BASE_TYPE) * c});
249
250 return stream;
251
252}
253
254template < prototype_raw_type_array ARRAY >
255inline binary_stream & operator >>(binary_stream & stream, ARRAY & a)
256{
257
258 ::collection::count c;
259
260 stream >> c;
261
262 if (stream.nok())
263 {
264
265 return stream;
266
267 }
268
269 a.set_size(c);
270
271 auto iRead = stream.m_pfile->read({ a.get_data(), sizeof(typename ARRAY::BASE_TYPE) * c });
272
273 if (stream.nok() || iRead < (memsize)(sizeof(typename ARRAY::BASE_TYPE) * c))
274 {
275
276 a.set_size(iRead / sizeof(typename ARRAY::BASE_TYPE));
277
278 }
279
280 return stream;
281
282}
283
284
285inline binary_stream & operator <<(binary_stream & stream, const ::property_set & propertyset)
286{
287
288 return stream << (const property_holder_array_base & ) propertyset;
289
290}
291
292
293inline binary_stream & operator >>(binary_stream & stream, ::property_set & propertyset)
294{
295
296 return stream >> (property_holder_array_base &) propertyset;
297
298}
299
300
301CLASS_DECL_ACME binary_stream& binary_stream_write_property(::binary_stream& stream, const property& property);
302CLASS_DECL_ACME binary_stream& binary_stream_read_property(::binary_stream& stream, property& property);
303
304
305inline binary_stream & operator <<(binary_stream & stream, const ::property * pproperty)
306{
307
308 return binary_stream_write_property(stream, *pproperty);
309
310}
311
312
313inline binary_stream & operator >>(binary_stream & stream, ::property * pproperty)
314{
315
316 return binary_stream_read_property(stream, *pproperty);
317
318}
319
320
321
322
Definition binary_stream.h:12
Definition property_set.h:512
Definition property.h:81
Definition ___serialization_draft.h:42