acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
___serialization_draft.h
1// 2020-01-11 - Curitiba, ca2
2
3// "pluggable" non-member non-virtual global serializers
4
5// Use cases:
6// - Entry i32_point convenience syntax sugar
7// - syntax sugar
8template < typename TYPE >
9inline stream & operator >> (stream & stream, TYPE & t) { stream.defer_set_loading(); stream.exchange(t); return stream; }
10
11template < typename TYPE >
12inline stream & operator << (stream & stream, const TYPE & t) { stream.defer_set_storing(); stream.exchange((TYPE &) t); return stream; }
13
14::i32 file_procedure()
15{
16
17 ::file pfile = file()->get_file("C:\\window.window");
18
19 in_addr addr;
20
21 ::stream stream(pfile);
22
23 stream >> addr;
24
25}
26
27
28::i32 var_procedure()
29{
30
32
33 in_addr addr;
34
36
37 stream >> addr;
38
39}
40
41class stream
42{
43public:
44
45 virtual void read(::i8 & i) {}
46 virtual void read(string & i) {}
47
48 virtual void write(const ::i8 & i) {}
49 virtual void write(const ::scoped_string & scopedstr) {}
50
51 template < typename TYPE >
52 void default_exchange(TYPE & t) { is_loading() ? read(t) : write(t); }
53
54 virtual void exchange(const ::atom & atom, ::i8 & i) { default_exchange(i); }
55 virtual void exchange(const ::atom & atom, string & str) { default_exchange(str); }
56
57
58
59 template < typename OBJECT >
60 inline void exchange(const ::atom & atom, ::pointer<OBJECT>& pparticle)
61 {
62 if (is_storing())
63 {
64 write_object(atom, pparticle.m_p);
65 }
66 else
67 {
68 pparticle = read_object(atom);
69 }
70 }
71
72
73 virtual void write_object(const ::atom & atom, const ::atom & idFactory, ::particle * pparticle)
74 {
75 exchange("id", idFactory);
76 exchange("", pparticle);
77 }
78
79 virtual ::pointer<::matter>read_object(const ::atom & atom)
80 {
81 ::atom idFactory;
82 exchange("id", idFactory);
83 auto pparticle = øcreate_by_type<::matter>(idFactory);
84 exchange("", pparticle);
85 return pparticle;
86 }
87
88
89};
90
91
93{
94public:
95
96 ::payload & payload();
97
98 virtual void read(::i8 & i) {}
99 virtual void read(string & i) {}
100
101 virtual void write(const ::i8 & i) {}
102 virtual void write(const ::scoped_string & scopedstr) {}
103
104 template < typename TYPE >
105 void default_exchange(const ::atom & atom, TYPE & t) { is_loading() ? t = operator[atom] : operator[atom] = t; }
106
107 virtual void exchange(const ::atom & atom, ::i8 & i) { default_exchange(atom, i); }
108 virtual void exchange(const ::atom & atom, string & str) { default_exchange(atom, str); }
109
110
111
112
113
114
115 virtual void write_object(const ::atom & atom, const ::atom & idFactory, ::particle * pparticle) override
116 {
117 payload_stream stream(allocateø< ::payload(&payload()[atom].propset >()));
118 stream.exchange("id", idFactory);
119 stream.exchange("", pparticle);
120 }
121
122 virtual ::pointer<::contex_object>read_object(const ::atom & atom) override
123 {
124 payload_stream stream(allocateø< ::payload(&payload()[atom].propset >()));
125 ::atom idFactory;
126 stream.exchange("id", idFactory);
127 auto pparticle = øcreate_by_type<::matter>(idFactory);
128 stream.exchange("", pparticle);
129 return pparticle;
130 }
131
132};
133//void __exchange(stream & stream, ::i8 & i) { __exchange_blt(stream, i); }
134//void __exchange(stream & stream, string & str) { __exchange_string(stream, str); }
135//void __exchange(stream & stream, in_addr & addr) { __exchange_stringable(stream, addr); }
136//
137//
138//void __exchange(stream & stream, const ::atom & atom, ::i8 & i) { __exchange_blt(stream, i); }
139//void __exchange(stream & stream, const ::atom & atom, string & str) { __exchange_string(stream, str); }
140//void __exchange(stream & stream, const ::atom & atom, in_addr & addr) { __exchange_stringable(stream, addr); }
141//
142//
143//void __exchange(payload_stream & stream, ::i8 & i) { __exchange_blt(stream, i); }
144//void __exchange(payload_stream & stream, string & str) { __exchange_string(stream, str); }
145//void __exchange(payload_stream & stream, in_addr & addr) { __exchange_stringable(stream, addr); }
146
147
148class window :
149 virtual public matter
150{
151public:
152
153 ::i8 m_iVisible;
154 string m_strTitle;
155 in_addr m_addr;
156 ::pointer<::matter> m_pobject;
157
158 virtual void exchange(stream & s);
159
160};
161
162#define __EXCHANGE(xxx) stream.exchange(__STRING(xxx), m_##xxx)
163#define __TYPE_EXCHANGE(xxx) stream.exchange(__STRING(xxx), t.m_##xxx)
164
165
166void window::exchange(stream & stream)
167{
168
169 __EXCHANGE(iVisible); // expands... to: stream.exchange("iVisible", m_iVisible);
170 __EXCHANGE(strTitle); // expands... to: stream.exchange("strTitle", m_strTitle);
171 __EXCHANGE(addr); // expands... to: stream.exchange("addr", m_addr);
172 __EXCHANGE(pparticle); // expands... to: stream.exchange("pparticle", m_pobject);
173
174}
175
176
177class exchanger
178{
179
180 stream * m_pstream;
181
182 template
183 exchange(atom, value) read / write value
184 {
185 if (is_storing)
186 m_pstream->write(atom value)
187 else
188 m_pstream->read(atom, value)
189
190 }
191 template
192 exchange(value) read / write value
193 {
194 if (is_storing)
195 m_pstream->write(value)
196 else
197 m_pstream->read(value)
198
199 }
200
201
202 stream
203 {
204
205
206 read(atom, ::i8) throw not_implemented;
207 read(atom, ::i16) throw not_implemented;
208 read(atom, ::i32) throw not_implemented;
209 read(atom, ::i64) throw not_implemented;
210 read(atom, ::u8) throw not_implemented;
211 read(atom, ::u16) throw not_implemented;
212 read(atom, ::u32) throw not_implemented;
213 read(atom, ::u64) throw not_implemented;
214
215 read(::i8) throw not_implemented;
216 read(::i16) throw not_implemented;
217 read(::i32) throw not_implemented;
218 read(::i64) throw not_implemented;
219 read(::u8) throw not_implemented;
220 read(::u16) throw not_implemented;
221 read(::u32) throw not_implemented;
222 read(::u64) throw not_implemented;
223
224 write(atom, ::i8) throw not_implemented;
225 write(atom, ::i16) throw not_implemented;
226 write(atom, ::i32) throw not_implemented;
227 write(atom, ::i64) throw not_implemented;
228 write(atom, ::u8) throw not_implemented;
229 write(atom, ::u16) throw not_implemented;
230 write(atom, ::u32) throw not_implemented;
231 write(atom, ::u64) throw not_implemented;
232
233 write(::i8) throw not_implemented;
234 write(::i16) throw not_implemented;
235 write(::i32) throw not_implemented;
236 write(::i64) throw not_implemented;
237 write(::u8) throw not_implemented;
238 write(::u16) throw not_implemented;
239 write(::u32) throw not_implemented;
240 write(::u64) throw not_implemented;
241
242
243 }
244
245
246 binary_stream
247 {
248
249
250 read(atom, ::i8) read(::i8)
251 read(atom, ::i16) read(::i16)
252 read(atom, ::i32) read(::i32)
253 read(atom, ::i64) read(::i64)
254 read(atom, ::u8) read(::u8)
255 read(atom, ::u16) read(::u16)
256 read(atom, ::u32) read(::u32)
257 read(atom, ::u64) read(::u64)
258
259 read(::i8) m_pfile->read(::i8)
260 read(::i16) m_pfile->read(::i16)
261 read(::i32) m_pfile->read(::i32)
262 read(::i64) m_pfile->read(::i64)
263 read(::u8) m_pfile->read(::u8)
264 read(::u16) m_pfile->read(::u16)
265 read(::u32) m_pfile->read(::u32)
266 read(::u64) m_pfile->read(::u64)
267
268 write(atom, ::i8) write(::i8)
269 write(atom, ::i16) write(::i16)
270 write(atom, ::i32) write(::i32)
271 write(atom, ::i64) write(::i64)
272 write(atom, ::u8) write(::u8)
273 write(atom, ::u16) write(::u16)
274 write(atom, ::u32) write(::u32)
275 write(atom, ::u64) write(::u64)
276
277 write(::i8) m_pfile->write(::i8)
278 write(::i16) m_pfile->write(::i16)
279 write(::i32) m_pfile->write(::i32)
280 write(::i64) m_pfile->write(::i64)
281 write(::u8) m_pfile->write(::u8)
282 write(::u16) m_pfile->write(::u16)
283 write(::u32) m_pfile->write(::u32)
284 write(::u64) m_pfile->write(::u64)
285
286
287 }
288
289 text_stream
290 {
291
292
293 write(atom, ::i8) write(::i8)
294 write(atom, ::i16) write(::i16)
295 write(atom, ::i32) write(::i32)
296 write(atom, ::i64) write(::i64)
297 write(atom, ::u8) write(::u8)
298 write(atom, ::u16) write(::u16)
299 write(atom, ::u32) write(::u32)
300 write(atom, ::u64) write(::u64)
301
302 write(::i8) m_pfile->write(::i8)
303 write(::i16) m_pfile->write(::i16)
304 write(::i32) m_pfile->write(::i32)
305 write(::i64) m_pfile->write(::i64)
306 write(::u8) m_pfile->write(::u8)
307 write(::u16) m_pfile->write(::u16)
308 write(::u32) m_pfile->write(::u32)
309 write(::u64) m_pfile->write(::u64)
310
311
312 }
313
314
315 template < typename CONTAINER >
316 id_stream :
317 stream
318 {
319
320 read(atom, ::i8)::i8 = m_ppayload->operator[](atom);
321 read(atom, ::i16) ::i16 = m_ppayload->operator[](atom);
322 read(atom, ::i32) ::i32 = m_ppayload->operator[](atom);
323 read(atom, ::i64) ::i64 = m_ppayload->operator[](atom);
324 read(atom, ::u8) ::u8 = m_ppayload->operator[](atom);
325 read(atom, ::u16) ::u16 = m_ppayload->operator[](atom);
326 read(atom, ::u32) ::u32 = m_ppayload->operator[](atom);
327 read(atom, ::u64) ::u64 = m_ppayload->operator[](atom);
328
329 read(::i8) ::i8 = *m_ppayload
330 read(::i16) ::i16 = *m_ppayload
331 read(::i32) ::i32 = *m_ppayload
332 read(::i64) ::i64 = *m_ppayload
333 read(::u8) uch = *m_ppayload
334 read(::u16) ::u16 = *m_ppayload
335 read(::u32) ::u32 = *m_ppayload
336 read(::u64) ::u64 = *m_ppayload
337
338 write(atom, ::i8) write(::i8)
339 write(atom, ::i16) write(::i16)
340 write(atom, ::i32) write(::i32)
341 write(atom, ::i64) write(::i64)
342 write(atom, ::u8) write(::u8)
343 write(atom, ::u16) write(::u16)
344 write(atom, ::u32) write(::u32)
345 write(atom, ::u64) write(::u64)
346
347 write(::i8) m_pfile->write(::i8)
348 write(::i16) m_pfile->write(::i16)
349 write(::i32) m_pfile->write(::i32)
350 write(::i64) m_pfile->write(::i64)
351 write(::u8) m_pfile->write(::u8)
352 write(::u16) m_pfile->write(::u16)
353 write(::u32) m_pfile->write(::u32)
354 write(::u64) m_pfile->write(::u64)
355
356 }
357
358
359
360
361 stream & operator >> (stream & stream, matter & o)
362 {
363
364 exchange e(stream);
365
366 e.defer_set_loading();
367
368 e.exchange(s);
369
370 }
371
372 stream & operator >> (stream & s, matter & o)
373 {
374
375 o.exchange(stream);
376
377 }
378
379
380 window new_frame_window()
381 {
382 return allocateø frame_window();
383 }
Definition atom.h:237
Definition particle.h:95
Definition ___serialization_draft.h:93
Definition payload.h:54
Definition ___serialization_draft.h:42
Definition ___serialization_draft.h:150
Definition filesystem.h:16
Definition sockets.h:32