acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
write_text_stream.h
1//
2// Created by camilo on 23/12/2022. <3ThomasBorregaardSorensen!!
3//
4#pragma once
5
6
7#include "acme/filesystem/file/print_formatting.h"
8#include "acme/prototype/prototype/pointer.h"
9#include "acme/prototype/string/c/encoding.h"
10
11
12struct CLASS_DECL_ACME write_text_stream_struct
13{
14
15
16 ::i8 m_chSeparator = ' ';
17#ifdef WINDOWS
18 const_char_pointer m_pszEolSeparator = "\r\n";
19#else
20 const_char_pointer m_pszEolSeparator = "\n";
21#endif
22 print_formatting * m_pprintingformat;
23
24 write_text_stream_struct();
25 write_text_stream_struct(const write_text_stream_struct & writetextstreamstruct) = default;
26 write_text_stream_struct(write_text_stream_struct && writetextstreamstruct) = default;
27
28
29 void set_width(::i32 width) { m_pprintingformat->m_width = width; }
30
31 void set_precision(::i32 precision) { m_pprintingformat->m_precision = precision; }
32
33
34};
35
36
38
39
41class CLASS_DECL_ACME write_text_stream :
42 virtual public write_text_stream_struct
43{
44public:
45
46
47 ::file_pointer m_pfile;
48
49
50 write_text_stream();
51 write_text_stream(const ::file_pointer & pfile);
52 write_text_stream(::file_pointer && pfile);
53 write_text_stream(const write_text_stream & stream);
54 write_text_stream(write_text_stream && stream);
55 write_text_stream(const ::file_pointer & pfile, write_text_stream_struct && streamstruct);
56 virtual ~write_text_stream();
57
58
59 // void destroy() ;
60
61 //void destroy() {}
62
63 //string as_string() const;
64
65
66 //FILE * get_file() { return m_pfile; }
67
68
69 //::file::file* get_file()
70 //{
71
72 // return m_pfile;
73
74 //}
75
76 //template < prototype_integral INTEGRAL >
77 //void number_read(TYPE& t)
78 //{
79
80 // const ::i8 endptr = nullptr;
81
82 // auto hn = strtoull(m_str, &endptr, 10);
83
84 // if (!endptr)
85 // {
86
87 // set_fail_flag();
88
89 // }
90 // else
91 // {
92
93 //
94
95 // }
96
97 // ::copy(t, str);
98
99 //}
100
101 inline ::file::fmtflags & fmtflags() { return m_pprintingformat->m_fmtflags; }
102 inline ::file::fmtflags fmtflags() const { return m_pprintingformat->m_fmtflags; }
103
104
105 void print(const ::range < const ansi_character * > & str);
106 void print(::ansi_character ansicharacter) { write(&ansicharacter, 1); }
107 void print(::wd16_character wd16character) { ::i8 sz[8]; write((const_char_pointer )&sz, wd16_to_ansi(sz, &wd16character, 1)); }
108 void print(::wd32_character wd32character) { ::i8 sz[8]; write((const_char_pointer )& sz, wd32_to_ansi(sz, &wd32character, 1)); }
109
110
111 template < prototype_number NUMBER >
112 void write_number(NUMBER number);
113
114 template < prototype_number NUMBER >
115 void write_number(NUMBER number, const_char_pointer pszFormat);
116
117 /*template < typename TYPE >
118 void number_exchange(TYPE& t)
119 {
120
121 has_loading_flag() ? number_read(t) : number_write(t);
122
123 }*/
124
125
126 //template < typename TYPE >
127 //void string_read(TYPE& t)
128 //{
129
130 // string str = read_string();
131
132 // ::from_string(t, str);
133
134 //}
135
136
137 //template < typename TYPE >
138 //void string_write(const TYPE& t)
139 //{
140
141 // string str;
142
143 // str = as_string(t);
144
145 // print(str);
146
147 //}
148
149
150 //template < typename TYPE >
151 //void string_exchange(TYPE& t)
152 //{
153
154 // has_loading_flag() ? string_read(t) : string_write(t);
155
156 //}
157
158
159 //template < typename TYPE >
160 //void network_payload_exchange(TYPE& t);
161
162
163 /*template < typename TYPE >
164 void write_only(TYPE & t) { is_loading() ? throw_exception(error_io) : operator <<(t); }
165
166 template < typename TYPE >
167 void exchange(const ::atom & atom, TYPE & t) { ::__string_exchange(*this, t); }*/
168
169 void append_format(const_char_pointer pszFormat, ...);
170 // {
171 //
172 // ::string strText;
173 //
174 // ASSERT(is_string_ok(scopedstrFormat));
175 //
176 // va_list argList;
177 //
178 // va_start(argList, pszFormat);
179 //
180 // strText.formatf_arguments(scopedstrFormat, argList);
181 //
182 // va_end(argList);
183 //
184 // print(strText);
185 //
186 // }
187
188
189 //bool is_stream_null();
190 //bool is_stream_set();
191
192 //void close() {}
193
194 void new_line();
195 // {
196 //
197 // if (m_fmtflags & ::file::separated)
198 // {
199 //
200 // m_pfile->unget_if(m_chSeparator);
201 //
202 // }
203 //
204 // print(m_pszEolSeparator);
205 //
206 // }
207
208
209 write_text_stream & operator <<(::file::fmtflags e)
210 {
211
212 m_pprintingformat->set_format_flags(e);
213
214 return *this;
215
216 }
217
218
219
220 template < typename ENUM >
221 write_text_stream& operator <<(const enumeration< ENUM >& e)
222 {
223
224 return *this << e.m_eenum;
225
226 }
227
228
229 write_text_stream & operator <<(bool b);
230 // {
231 //
232 // if(b)
233 // {
234 //
235 // print("1");
236 //
237 // }
238 // else
239 // {
240 //
241 // print("0");
242 //
243 // }
244 //
245 // if (m_fmtflags & ::file::separated)
246 // {
247 //
248 // print(m_chSeparator);
249 //
250 // }
251 //
252 // return *this;
253 //
254 // }
255
256
257 write_text_stream & operator <<(::i8 ch);
258 // {
259 //
260 // write(&ch, 1);
261 //
262 // if (m_fmtflags & ::file::separated)
263 // {
264 //
265 // print(m_chSeparator);
266 //
267 // }
268 //
269 // return *this;
270 //
271 // }
272
273 write_text_stream & operator <<(enum_start_reference);
274 // {
275 //
276 // return *this;
277 //
278 // }
279
280
281 write_text_stream & operator <<(uchar uch);
282 // {
283 //
284 // write(&uch, 1);
285 //
286 // if (m_fmtflags & ::file::separated)
287 // {
288 //
289 // print(m_chSeparator);
290 //
291 // }
292 //
293 // return *this;
294 //
295 // }
296
297
298#ifdef WINDOWS
299
300
301 write_text_stream & operator <<(unichar wch);
302 // {
303 //
304 // ::i8 sz[10];
305 //
306 // wd16_to_ansi(sz, &wch, 1);
307 //
308 // print(sz);
309 //
310 // if (m_fmtflags & ::file::separated)
311 // {
312 //
313 // print(m_chSeparator);
314 //
315 // }
316 //
317 // return *this;
318 //
319 // }
320
321
322#endif
323
324 template < prototype_signed_not_8bit SIGNED >
325 write_text_stream & operator <<(SIGNED i);
326 // {
327 //
328 // write_number(i);
329 //
330 // if (m_fmtflags & ::file::separated)
331 // {
332 //
333 // print(m_chSeparator);
334 //
335 // }
336 //
337 // return *this;
338 //
339 // }
340
341
342 template < prototype_unsigned_not_8bit UNSIGNED >
343 write_text_stream & operator <<(UNSIGNED u);
344 // {
345 //
346 // write_number(u);
347 //
348 // if (m_fmtflags & ::file::separated)
349 // {
350 //
351 // print(m_chSeparator);
352 //
353 // }
354 //
355 // return *this;
356 //
357 // }
358
359 template < typename T >
360 void print_string_copy(const T & t);
361 // {
362 //
363 // ::string str;
364 //
365 // ::copy(str, t);
366 //
367 // print(str);
368 //
369 // }
370
371 // {
372 //
373 // print_string_copy(integralbyte);
374 //
375 // if (m_fmtflags & ::file::separated)
376 // {
377 //
378 // print(m_chSeparator);
379 //
380 // }
381 //
382 // return *this;
383 //
384 // }
385
386 //write_text_stream& operator <<(::i32 i)
387 //{
388
389 // write_integer(i);
390
391 // print(m_chSeparator);
392
393 // return *this;
394
395 //}
396
397
398 //write_text_stream& operator <<(::u32 u)
399 //{
400
401 // write_natural(u);
402
403 // print(m_chSeparator);
404
405 // return *this;
406
407 //}
408
409
410 //write_text_stream& operator <<(::i64 i)
411 //{
412
413 // write_integer(i);
414
415 // print(m_chSeparator);
416
417 // return *this;
418
419 //}
420
421
422 //write_text_stream& operator <<(::u64 u)
423 //{
424
425 // write_natural(u);
426
427 // print(m_chSeparator);
428
429 // return *this;
430
431 //}
432
433
434 template < prototype_floating FLOATING >
435 write_text_stream & operator <<(FLOATING f);
436 // {
437 //
438 // write_number(f);
439 //
440 // if (m_fmtflags & ::file::separated)
441 // {
442 //
443 // print(m_chSeparator);
444 //
445 // }
446 //
447 // return *this;
448 //
449 // }
450
451 //#ifdef _MSC_VER
452 //
453 // write_text_stream& operator <<(long l)
454 // {
455 //
456 // write_integer(l);
457 //
458 // print(m_chSeparator);
459 //
460 // return *this;
461 //
462 // }
463 //
464 //#endif
465 //
466 //
467 // write_text_stream& operator <<(::f64 d)
468 // {
469 //
470 // write_floating(d);
471 //
472 // print(m_chSeparator);
473 //
474 // return *this;
475 //
476 // }
477 //
478
479 // void write(const ::i32_point & point) ;
480 // void write(const ::i32_size & size) ;
481 // void write(const ::i32_rectangle &rectangle) ;
482
483 write_text_stream & operator <<(const_char_pointer psz);
484 // {
485 //
486 // if (m_fmtflags & ::file::network_payload)
487 // {
488 //
489 // print("\"");
490 //
491 // }
492 //
493 // print(scopedstr);
494 //
495 // if (m_fmtflags & ::file::network_payload)
496 // {
497 //
498 // print("\"");
499 //
500 // }
501 //
502 // if (m_fmtflags & ::file::separated)
503 // {
504 //
505 // print(m_chSeparator);
506 //
507 // }
508 //
509 // return *this;
510 //
511 // }
512
513 write_text_stream & operator <<(const ::range < const_char_pointer >& range);
514 // {
515 //
516 // return this->operator <<((const ::scoped_string &)str);
517 //
518 // }
519
520
521 write_text_stream& operator <<(const ::platform::type & type)
522 {
523
524 return *this << type.name();
525
526 }
527
528 //text_stream & operator <<(const ::atom & atom) ;
529 write_text_stream & operator <<(const ::scoped_string & scopedstr);
530 //template < typename ITERATOR_TYPE2, ::i32 t_size>
531 //write_text_stream& operator <<(const ::const_string_range_static_array < ITERATOR_TYPE2, t_size >& a)
532 //{
533
534 // return this->operator <<((const ::string&)a);
535
536 //}
537 // {
538 //
539 // if (m_fmtflags & ::file::network_payload)
540 // {
541 //
542 // print("\"");
543 //
544 // }
545 //
546 // print(scopedstr);
547 //
548 // if (m_fmtflags & ::file::network_payload)
549 // {
550 //
551 // print("\"");
552 //
553 // }
554 //
555 // if (m_fmtflags & ::file::separated)
556 // {
557 //
558 // print(m_chSeparator);
559 //
560 // }
561 //
562 // return *this;
563 //
564 // }
565
566
567 template < prototype_character CHARACTER2, character_count sizeMaximumLength >
568 write_text_stream & operator <<(const ::inline_string < CHARACTER2, sizeMaximumLength > & inlinestring);
569 // {
570 //
571 // if (m_fmtflags & ::file::network_payload)
572 // {
573 //
574 // print("\"");
575 //
576 // }
577 //
578 // write(inlinestring.data(), inlinestring.size());
579 //
580 // if (m_fmtflags & ::file::network_payload)
581 // {
582 //
583 // print("\"");
584 //
585 // }
586 //
587 // if (m_fmtflags & ::file::separated)
588 // {
589 //
590 // print(m_chSeparator);
591 //
592 // }
593 //
594 // return *this;
595 //
596 // }
597 //text_stream & operator <<(const ::property_set & set) ;
598 template < typename TYPE >
599 write_text_stream & write(const TYPE & t);
600 // {
601 //
602 // return *this << t;
603 //
604 // }
605
606 // void network_payload_write(const ::matter & matter);
607
608
609 void raw_print(const ::scoped_string & scopedstr);
610 // {
611 //
612 // print(str);
613 //
614 // }
615
616
617 //void print_number(const ::scoped_string & scopedstr)
618 //{
619
620 // print_number(str);
621
622 //}
623
624 //::string get_location() const;
625
626 //::filesize get_position() const ;
627 void write(const void * psz, character_count s);
628
629 //void print(const ::scoped_string & scopedstr);
630
631// {
632//
633// m_pfile->write(scopedstr, s);
634//
635// }
636
637 //operator void* () { return this; }
638
639// text_stream& operator >>(bool& b);
640// text_stream& operator >>(::i8& ch);
641// text_stream& operator >>(uchar& uch);
642//#ifdef WINDOWS
643// text_stream& operator >>(unichar& wch);
644//#endif
645// text_stream& operator >>(::i8& i);
646// text_stream& operator >>(::i16& sh);
647// text_stream& operator >>(::u16& u);
648// text_stream& operator >>(::i32& i);
649// text_stream& operator >>(::u32& u);
650// text_stream& operator >>(::i64& i);
651// text_stream& operator >>(::u64& u);
652// text_stream& operator >>(::f32& f);
653// text_stream& operator >>(::f64& d);
654// text_stream& operator >>(string& str);
655// //text_stream & operator >>(::property_set & set) ;
656// //text_stream & operator >>(::atom & atom) ;
657//
658// template < typename TYPE >
659// void network_payload_read(TYPE& matter);
660//
661
662};
663
664
665
666
667
668template < prototype_number NUMBER >
669inline void write_text_stream::write_number(NUMBER number)
670{
671
672 print(as_string(number));
673
674}
675
676
677template < prototype_number NUMBER >
678inline void write_text_stream::write_number(NUMBER number, const_char_pointer pszFormat)
679{
680
681 print(as_string(number, pszFormat));
682
683}
684
685
686template < prototype_signed_not_8bit SIGNED >
687inline write_text_stream & write_text_stream::operator <<(SIGNED i)
688{
689
690 write_number(i);
691
692 if (this->fmtflags() & ::file::separated)
693 {
694
695 print(m_chSeparator);
696
697 }
698
699 return *this;
700
701}
702
703
704// // template < typename FILE >
705template < prototype_unsigned_not_8bit UNSIGNED >
706inline write_text_stream & write_text_stream::operator <<(UNSIGNED u)
707{
708
709 write_number(u);
710
711 if (this->fmtflags() & ::file::separated)
712 {
713
714 print(m_chSeparator);
715
716 }
717
718 return *this;
719
720}
721
722
723
724
725
726// // template < typename FILE >
727template < prototype_floating FLOATING >
728inline write_text_stream & write_text_stream::operator <<(FLOATING f)
729{
730
731 string strFormat;
732
733 strFormat.formatf("%%0%d.%df", m_pprintingformat->m_width, m_pprintingformat->m_precision);
734
735 // ::i8 szFormat[32];
736 //
737 // snprintf(szFormat, sizeof(szFormat), );
738
739 write_number(f, strFormat);
740
741 if (this->fmtflags() & ::file::separated)
742 {
743
744 print(m_chSeparator);
745
746 }
747
748 return *this;
749
750}
751
752
753
754
755
756// // template < typename FILE >
757template < typename TYPE >
758inline write_text_stream & write_text_stream::write(const TYPE & t)
759{
760
761 return *this << t;
762
763}
Definition enumeration.h:219
Definition print_formatting.h:6
Definition range.h:223
Definition ___serialization_draft.h:42
Definition string_buffer.h:10
Definition write_text_stream.h:43