acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
text_stream.h
1#pragma once
2
3
4#include "string_buffer.h"
5#include "stream.h"
6
7
8
9
10
11inline ::string ellipsis(const_char_pointer psz, character_count len);
12inline ::u64 consume_natural(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix = 10);
13inline ::i64 consume_integer(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix = 10);
14inline ::f64 consume_floating(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix = 10);
15
16
17#include "write_text_stream.h"
18
19#include "read_sz_stream.h"
20
21
22//using std_string_stream = ::write_text_stream;
23
24
25class CLASS_DECL_ACME string_reference_stream :
26 public write_text_stream,
27 public string_reference_buffer
28{
29public:
30
31
32 string_reference_stream(::string& str) : string_reference_buffer(str) { m_pfile = this; }
33
34
35};
36
37
38
39
40
41
43//inline text_stream < FILE >::text_stream(const stream_base& stream)
44//{
45//
46// m_pfile = dynamic_cast <FILE*>(((stream_base&)stream).get_file());
47//
48// if (!m_pfile)
49// {
50//
51// throw_exception(error_wrong_type);
52//
53// }
54//
55// if (stream.nok())
56// {
57// set_nok();
58// }
59// else
60// {
61//
62// set_ok_flag();
63//
64// }
65//
66// if (stream.has_storing_flag())
67// {
68//
69// defer_set_storing_flag();
70//
71// }
72//}
73
74
76//inline write_text_stream < FILE >::~write_text_stream()
77//{
78//
79//
80//}
81
82
84//inline string write_text_stream < FILE >::read_string()
85//{
86//
87// string str;
88//
89// m_pfile->read_string(str);
90//
91// return str;
92//
93//}
94
95
97//bool text_stream < FILE >::is_stream_null()
98//{
99//
100// return !m_pfile;
101//
102//}
103//
104//
106//void text_stream < FILE >::destroy()
107//{
108//
109// m_pfile.release();
110//
111// ///* auto estatus = */ stream::destroy();
112//
113// /* return estatus; */
114//
115//}
116
117
119//string text_stream < FILE >::as_string() const
120//{
121//
122// return m_pfile->as_string();
123//
124//}
125
126
128//bool text_stream < FILE >::is_stream_set()
129//{
130//
131// return m_pfile;
132//
133//}
134
135
137//text_stream < FILE>& text_stream < FILE >::operator >>(::i8& ch)
138//{
139//
140// m_gcount = m_pfile->read(&ch, 1);
141//
142// if (m_gcount <= 0)
143// {
144//
145// throw_exception(error_io);
146//
147// }
148//
149// return *this;
150//
151//}
152
153
155//void text_stream < FILE >::close()
156//{
157//
158// m_pfile->close();
159//
160//}
161
162
164//text_stream < FILE >& text_stream < FILE >::operator <<(bool b)
165//{
166//
167// if (b)
168// {
169//
170// raw_print("true");
171//
172// }
173// else
174// {
175//
176// raw_print("false");
177//
178// }
179//
180// return *this;
181//
182//}
183//
184//
186//text_stream < FILE >& text_stream < FILE >::operator <<(::i8 ch)
187//{
188//
189// m_pfile->write(&ch, sizeof(ch)); // treat as ::i8 - character
190//
191// return *this;
192//
193//}
194
195
197//text_stream < FILE >& text_stream < FILE >::operator <<(uchar uch)
198//{
199//
200// operator <<((::u32)uch);
201//
202// return *this;
203//
204//}
205//
206//
208//text_stream < FILE >& text_stream < FILE >::operator <<(::i16 i)
209//{
210//
211// operator <<((::i32)i);
212//
213// return *this;
214//
215//}
216//
217//
219//text_stream < FILE >& text_stream < FILE >::operator <<(::u16 u)
220//{
221//
222// operator <<((::u32)u);
223//
224// return *this;
225//
226//}
227//
228//
229//#ifdef WINDOWS
230//
232//text_stream < FILE >& text_stream < FILE >::operator <<(unichar wch)
233//{
234//
235// raw_print(unicode_to_utf8(wch));
236//
237// return *this;
238//
239//}
240//
241//#endif
242//
243//
245//void text_stream < FILE >::print_number(const ::scoped_string & scopedstr)
246//{
247//
248// auto estrflag = this->m_estrflag;
249//
250// if (estrflag & str_flag_ifnumberparenthesize)
251// {
252//
253// raw_print("(");
254//
255// }
256//
257// raw_print(str);
258//
259// if (estrflag & str_flag_ifnumberparenthesize)
260// {
261//
262// raw_print(")");
263//
264// }
265//
266// if (estrflag & str_flag_ifnumberspace)
267// {
268//
269// raw_print(" ");
270//
271// }
272//
273//}
274
275
277//text_stream < FILE >& text_stream < FILE >::operator <<(::i32 i)
278//{
279//
280// print_number(as_string(i));
281//
282// return *this;
283//
284//}
285//
286//
288//text_stream < FILE >& text_stream < FILE >::operator <<(::u32 u)
289//{
290//
291// print_number(as_string(u));
292//
293// return *this;
294//
295//}
296//
297//
299//text_stream < FILE >& text_stream < FILE >::operator <<(::i64 i)
300//{
301//
302// print_number(as_string(i));
303//
304// return *this;
305//
306//}
307//
308//
310//text_stream < FILE >& text_stream < FILE >::operator <<(::u64 u)
311//{
312//
313// print_number(as_string(u));
314//
315// return *this;
316//
317//}
318//
319//
321//text_stream < FILE >& text_stream < FILE >::operator <<(::f32 f)
322//{
323//
324// string str;
325//
326// str.formatf("%f", f);
327//
328// print_number(str);
329//
330// return *this;
331//
332//}
333//
334//
336//text_stream < FILE >& text_stream < FILE >::operator <<(::f64 d)
337//{
338//
339// string str;
340//
341// str.formatf("%f", d);
342//
343// print_number(as_string(d));
344//
345// return *this;
346//
347//}
348
349
350//text_stream & text_stream < FILE >::operator <<(const ::i32_rectangle &rectangle)
351//{
352//
353// this->m_estrflag = (e_str_flag)((::i32)this->m_estrflag & ~(::i32)str_flag_ifnumberparenthesizeandspace);
354//
355// *this << prectangle->left << prectangle->top << prectangle->right << prectangle->bottom;
356//
357//}
358//
359//
360//text_stream & text_stream < FILE >::operator <<(const ::i32_size & psize)
361//{
362//
363// this->m_estrflag = (e_str_flag)((::i32)this->m_estrflag & ~(::i32)str_flag_ifnumberparenthesizeandspace);
364//
365// *this << psize->cx << psize->cy;
366//
367//}
368//
369//
370//
371//text_stream & text_stream < FILE >::operator <<(const ::i32_point * ppoint)
372//{
373//
374// this->m_estrflag = (e_str_flag)((::i32)this->m_estrflag & ~(::i32)str_flag_ifnumberparenthesizeandspace);
375//
376// *this << ppoint->x << ppoint->y;
377//
378//}
379
380
382//text_stream < FILE >& text_stream < FILE >::operator <<(const_char_pointer psz)
383//{
384//
385// if (::is_null(scopedstr))
386// {
387//
388// throw_exception(error_io);
389//
390// }
391// else
392// {
393//
394// write(scopedstr, strlen(scopedstr));
395//
396// }
397//
398// return *this;
399//
400//}
401//
402//
403//
405//text_stream < FILE >& text_stream < FILE >::operator <<(const ::scoped_string & scopedstr)
406//{
407//
408// operator <<(str.c_str());
409//
410// return *this;
411//
412//}
414//void text_stream < FILE >::raw_print(const ::scoped_string & scopedstr)
415//{
416//
417// write(str.c_str(), str.size());
418//
419// this->m_estrflag = (e_str_flag)((::i32)this->m_estrflag & ~(::i32)str_flag_ifnumberparenthesize);
420//
421//}
422//
423//
425//text_stream < FILE >& text_stream < FILE >::operator >>(bool& b)
426//{
427//
428// m_pfile->read(&b, sizeof(b));
429//
430// return *this;
431//
432//}
433//
441//
442//
444//text_stream < FILE >& text_stream < FILE >::operator >>(::i8& ch)
445//{
446//
447// m_gcount = m_pfile->read(&ch, sizeof(ch));
448//
449// if (m_gcount <= 0)
450// {
451//
452// throw_exception(error_io);
453//
454// }
455//
456// return *this;
457//
458//}
459//
460//
462//text_stream < FILE >& text_stream < FILE >::operator >>(uchar& uch)
463//{
464//
465// m_pfile->read(&uch, sizeof(uch));
466//
467// return *this;
468//
469//}
470//
471//
472//#ifdef WINDOWS
473//
475//text_stream < FILE >& text_stream < FILE >::operator >>(unichar& wch)
476//{
477//
478// m_pfile->read(&wch, sizeof(wch));
479//
480// return *this;
481//
482//}
483//
484//
485//#endif
486//
487//
489//text_stream < FILE >& text_stream < FILE >::operator >>(::i16& sh)
490//{
491//
492// m_pfile->read(&sh, sizeof(sh));
493//
494// return *this;
495//
496//}
497//
498//
500//text_stream < FILE >& text_stream < FILE >::operator >>(::u16& u)
501//{
502//
503// m_pfile->read(&u, sizeof(u));
504//
505// return *this;
506//
507//}
508//
509//
511//text_stream < FILE >& text_stream < FILE >::operator >>(::i32& i)
512//{
513//
514// number_read(i);
515//
516// return *this;
517//
518//}
519//
520//
522//text_stream < FILE >& text_stream < FILE >::operator >>(::u32& u)
523//{
524//
525// number_read(u);
526//
527// return *this;
528//
529//}
530//
531//
533//text_stream < FILE >& text_stream < FILE >::operator >>(::i64& i)
534//{
535//
536// number_read(i);
537//
538// return *this;
539//
540//}
541//
542//
544//text_stream < FILE >& text_stream < FILE >::operator >>(::u64& u)
545//{
546//
547// number_read(u);
548//
549// return *this;
550//
551//}
552//
553//
555//text_stream < FILE >& text_stream < FILE >::operator >>(::f32& f)
556//{
557//
558// number_read(f);
559//
560// return *this;
561//
562//}
563//
564//
566//text_stream < FILE >& text_stream < FILE >::operator >>(::f64& d)
567//{
568//
569// number_read(d);
570//
571// return *this;
572//
573//}
574//
599//
600//
602//text_stream < FILE >& text_stream < FILE >::operator >>(string& str)
603//{
604//
605// str.empty();
606//
607// ::i8 ch = 0;
608//
609// while (true)
610// {
611//
612// operator >>(ch);
613//
614// if (ch == '\0')
615// {
616//
617// break;
618//
619// }
620//
621// if (m_gcount <= 0)
622// {
623//
624// break;
625//
626// }
627//
628// if (ch == '\n')
629// {
630//
631// break;
632//
633// }
634//
635// str += ch;
636//
637// }
638//
639// return *this;
640//
641//}
642//
643//
654//
655//
669//
670//
672//inline string text_stream < FILE >::get_location() const
673//{
674//
675// return "<unknown text_stream_base locationd>";
676//
677//}
678//
679//
687//
688//
690//inline void text_stream < FILE >::write(const void* psz, character_count s)
691//{
692//
693// m_pfile->write(scopedstr, s);
694//
695//}
696//
697//
732//
733
734
735//
737//inline auto __write_text_stream(FILE* pfile)
738//{
739//
740// return write_text_stream < FILE >(pfile);
741//
742//}
743
744//
746//inline auto __text_stream(const ::pointer<FILE>& pfile)
747//{
748//
749// return __text_stream(pfile.m_p);
750//
751//}
752
753
754inline read_sz_stream::read_sz_stream(const_char_pointer psz, const_char_pointer pszBegin) :
755 m_psz(psz),
756 m_pszBegin(!pszBegin ? psz : pszBegin)
757{
758
759
760}
761
762
763inline read_sz_stream::~read_sz_stream()
764{
765
766
767}
768
769
770