acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_impl_read_sz_stream.h
1//
2// Created by camilo on 23/12/2022 01:14 <3ThomasBorregaardSorensen!!
3//
4#pragma once
5
6
7//class read_sz_stream :
8// public PARTICLE_FLAGS
9//{
10//public:
11//
12//
13// const_char_pointer m_psz;
14// const_char_pointer m_pszBegin;
15
16
17inline read_sz_stream::read_sz_stream(const_char_pointer psz, const_char_pointer pszBegin = nullptr);
18inline read_sz_stream::read_sz_stream(const read_sz_stream& stream) = delete;
19inline read_sz_stream::~read_sz_stream();
20
21
22 // void destroy() ;
23
24 //void destroy() {}
25
26 //string as_string() const;
27
28
29 //FILE * get_file() { return m_pfile; }
30
31
32 //::file::file* get_file()
33 //{
34
35 // return m_pfile;
36
37 //}
38
39inline ::u64 read_sz_stream::read_natural(::i32 iRadix = 10)
40 {
41
42 return consume_natural(m_psz, m_pszBegin, iRadix);
43
44 }
45
46
47inline ::i64 read_sz_stream::read_integer(::i32 iRadix = 10)
48 {
49
50 return consume_integer(m_psz, m_pszBegin, iRadix);
51
52 }
53
54
55inline ::f64 read_sz_stream::read_floating()
56 {
57
58 return consume_floating(m_psz, m_pszBegin);
59
60
61 }
62
63
64inline ::string read_sz_stream::get_word(const_char_pointer pszBreakCharacters = " \n\t\r,;")
65 {
66
67 return read_find_first_character_in(scopedstrBreakCharacters);
68
69 }
70
71inline ::string read_sz_stream::read_find_first_character_in(const_char_pointer pszBreakCharacters)
72 {
73
74 auto size = string_find_first_character_in(m_psz, pszBreakCharacters);
75
76 ::string str(m_psz, size);
77
78 m_psz += size;
79
80 return ::transfer(str);
81
82 }
83
84
85 //void close() {}
86
87// text_stream& operator <<(bool b);
88// text_stream& operator <<(::i8 ch);
89// text_stream& operator <<(uchar uch);
90//#ifdef WINDOWS
91// text_stream& operator <<(unichar wch);
92//#endif
93// text_stream& operator <<(::i16 sh);
94// text_stream& operator <<(::u16 u);
95// text_stream& operator <<(::i32 i);
96// text_stream& operator <<(::u32 u);
97// text_stream& operator <<(::i64 i);
98// text_stream& operator <<(::u64 u);
99// text_stream& operator <<(::f32 f);
100// text_stream& operator <<(::f64 d);
101// // void write(const ::i32_point & point) ;
102// // void write(const ::i32_size & size) ;
103// // void write(const ::i32_rectangle &rectangle) ;
104//
105// text_stream& operator <<(const_char_pointer psz);
106// //text_stream & operator <<(const ::atom & atom) ;
107// text_stream& operator <<(const ::scoped_string & scopedstr);
108// //text_stream & operator <<(const ::property_set & set) ;
109// template < typename TYPE >
110// void network_payload_write(const TYPE& t);
111//
112// // void network_payload_write(const ::matter & matter);
113
114
115
116inline read_sz_stream& read_sz_stream::operator >>(bool& b)
117 {
118
119 auto strWord = get_word();
120
121 strWord.trim_left("\"'([{");
122
123 strWord.trim_right("\"')]}");
124
125 if (strWord.case_insensitive_equals("no")
126 || strWord.case_insensitive_equals("false")
127 || strWord.case_insensitive_equals("0"))
128 {
129
130 b = false;
131
132 }
133 else
134 {
135
136 b = true;
137
138 }
139
140 return *this;
141
142 }
143
144inline read_sz_stream& read_sz_stream::operator >>(::i8& ch)
145 {
146
147 ch = *m_psz;
148
149 if (!ch)
150 {
151
152 throw_exception(error_premature_end_of_file);
153
154 }
155
156 m_psz++;
157
158 return *this;
159
160 }
161
162
163inline read_sz_stream& read_sz_stream::operator >>(uchar& uch)
164 {
165
166 return operator >>((::i8&)uch);
167
168 }
169
170#ifdef WINDOWS
171inline read_sz_stream& read_sz_stream::operator >>(unichar& wch)
172 {
173
174 ::i32 len = 0;
175
176 auto iIndex = unicode_index_length(m_psz, len);
177
178 if (iIndex < 0)
179 {
180
181 throw_exception(error_premature_end_of_file);
182
183 }
184 else if (iIndex >= 65536)
185 {
186
187 wch = 65535; // (INVALID CHAR CODE)?
188
189 }
190
191 wch = iIndex;
192
193 m_psz += len;
194
195 return *this;
196
197 }
198
199#endif
200inline read_sz_stream& read_sz_stream::operator >>(::i8& i)
201 {
202
203 return operator >>((::i8&)i);
204
205 }
206
207
208inline read_sz_stream& read_sz_stream::operator >>(::i16& sh)
209 {
210
211 auto iRead = read_integer();
212
213 if (iRead < SHRT_MIN)
214 {
215
216 throw_exception(error_standard_int_overflow);
217
218 }
219 else if (iRead > SHRT_MAX)
220 {
221
222 throw_exception(error_standard_int_overflow);
223
224 }
225
226 sh = (::i16)iRead;
227
228 return *this;
229
230 }
231
232
233inline read_sz_stream& read_sz_stream::operator >>(::u16& u)
234 {
235
236 auto uRead = read_natural();
237
238 if (uRead > USHRT_MAX)
239 {
240
241 throw_exception(error_standard_int_overflow);
242
243 }
244
245 u = (::u16)uRead;
246
247 return *this;
248
249 }
250
251
252inline read_sz_stream& read_sz_stream::operator >>(::i32& i)
253 {
254
255 auto iRead = read_integer();
256
257 if (iRead < INT_MIN)
258 {
259
260 throw_exception(error_standard_int_overflow, "INT_MIN overflow: " + as_string(iRead));
261
262 }
263 else if (iRead > INT_MAX)
264 {
265
266 throw_exception(error_standard_int_overflow, "INT_MAX overflow: " + as_string(iRead));
267
268 }
269
270 i = (::i32)iRead;
271
272 return *this;
273
274 }
275
276
277inline read_sz_stream& read_sz_stream::operator >>(::u32& u)
278 {
279
280 auto uRead = read_natural();
281
282 if (uRead > UINT_MAX)
283 {
284
285 throw_exception(error_standard_int_overflow);
286
287 }
288
289 u = (::u32) uRead;
290
291 return *this;
292
293 }
294
295
296inline read_sz_stream& read_sz_stream::operator >>(::i64& i)
297 {
298
299 i = read_integer();
300
301 return *this;
302
303 }
304
305
306inline read_sz_stream& read_sz_stream::operator >>(::u64& u)
307 {
308
309 u = read_natural();
310
311 return *this;
312
313 }
314
315
316inline read_sz_stream& read_sz_stream::operator >>(::f32& f)
317 {
318
319 f = (::f32) read_floating();
320
321 return *this;
322
323 }
324
325
326inline read_sz_stream& operator >>(::f64& d)
327 {
328
329 d = read_floating();
330
331 return *this;
332
333 }
334
335
336inline read_sz_stream& read_sz_stream::operator >>(string& str)
337 {
338
339 str = get_word();
340
341 return *this;
342
343 }
344
345
348
349
350 template < typename TYPE >
351 inline read_sz_stream & read_sz_stream::read(TYPE& t)
352 {
353
354 *this = t;
355
356 return *this;
357
358 }
359
360
361//};
362
363
364#include "_impl_read_sz_stream.h"
Definition read_sz_stream.h:9
Definition ___serialization_draft.h:42