source: libcfa/src/iostream.hfa @ 5ad2c6c7

Last change on this file since 5ad2c6c7 was 5ad2c6c7, checked in by Peter A. Buhr <pabuhr@…>, 12 months ago

update reading C strings with size check

  • Property mode set to 100644
File size: 21.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// iostream.hfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Aug 24 11:35:02 2023
13// Update Count     : 530
14//
15
16#pragma once
17
18#include "iterator.hfa"
19#include "Exception.hfa"
20
21// *********************************** ostream ***********************************
22
23
24forall( ostype & )
25trait basic_ostream {
26        // private
27        bool sepPrt$( ostype & );                                                       // get separator state (on/off)
28        void sepReset$( ostype & );                                                     // set separator state to default state
29        void sepReset$( ostype &, bool );                                       // set separator and default state
30        const char * sepGetCur$( ostype & );                            // get current separator string
31        void sepSetCur$( ostype &, const char [] );                     // set current separator string
32        bool getNL$( ostype & );                                                        // get newline
33        bool setNL$( ostype &, bool );                                          // set newline
34        bool getANL$( ostype & );                                                       // get auto newline (on/off)
35        bool setANL$( ostype &, bool );                                         // set auto newline (on/off), and return previous state
36        bool getPrt$( ostype & );                                                       // get fmt called in output cascade
37        bool setPrt$( ostype &, bool );                                         // set fmt called in output cascade
38        // public
39        void nlOn( ostype & );                                                          // turn auto-newline state on
40        void nlOff( ostype & );                                                         // turn auto-newline state off
41
42        void sep( ostype & );                                                           // turn separator state on
43        void nosep( ostype & );                                                         // turn separator state off
44        bool sepOn( ostype & );                                                         // set default state to on, and return previous state
45        bool sepOff( ostype & );                                                        // set default state to off, and return previous state
46        const char * sepGet( ostype & );                                        // get separator string
47        void sepSet( ostype &, const char [] );                         // set separator to string (15 character maximum)
48        const char * sepGetTuple( ostype & );                           // get tuple separator string
49        void sepSetTuple( ostype &, const char [] );            // set tuple separator to string (15 character maximum)
50
51        void ends( ostype & );                                                          // end of output statement
52        int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
53}; // basic_ostream
54
55forall( ostype & | basic_ostream( ostype ) )
56trait ostream {
57        bool fail( ostype & );                                                          // operation failed?
58        void clear( ostype & );
59        int flush( ostype & );
60        void open( ostype &, const char name[], const char mode[] );
61        void close( ostype & );
62        ostype & write( ostype &, const char [], size_t );
63}; // ostream
64
65// forall( T )
66// trait writeable {
67//      forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype &, T );
68// }; // writeable
69
70forall( T, ostype & | ostream( ostype ) )
71trait writeable {
72        ostype & ?|?( ostype &, T );
73}; // writeable
74
75// implement writable for intrinsic types
76
77#define OSTYPE_VOID( T ) void ?|?( ostype &, T )
78#define OSTYPE_VOID_IMPL( T ) \
79        void ?|?( ostype & os, T t ) { \
80                (ostype &)(os | t); ends( os ); \
81        } // ?|?
82
83forall( ostype & | basic_ostream( ostype ) ) {
84        ostype & ?|?( ostype &, bool );
85        OSTYPE_VOID( bool );
86
87        ostype & ?|?( ostype &, char );
88        OSTYPE_VOID( char );
89        ostype & ?|?( ostype &, signed char );
90        OSTYPE_VOID( signed char );
91        ostype & ?|?( ostype &, unsigned char );
92        OSTYPE_VOID( unsigned char );
93
94        ostype & ?|?( ostype &, short int );
95        OSTYPE_VOID( short int );
96        ostype & ?|?( ostype &, unsigned short int );
97        OSTYPE_VOID( unsigned short int );
98        ostype & ?|?( ostype &, int );
99        OSTYPE_VOID( int );
100        ostype & ?|?( ostype &, unsigned int );
101        OSTYPE_VOID( unsigned int );
102        ostype & ?|?( ostype &, long int );
103        OSTYPE_VOID( long int );
104        ostype & ?|?( ostype &, long long int );
105        OSTYPE_VOID( long long int );
106        ostype & ?|?( ostype &, unsigned long int );
107        OSTYPE_VOID( unsigned long int );
108        ostype & ?|?( ostype &, unsigned long long int );
109        OSTYPE_VOID( unsigned long long int );
110        #if defined( __SIZEOF_INT128__ )
111        ostype & ?|?( ostype &, int128 );
112        OSTYPE_VOID( int128 );
113        ostype & ?|?( ostype &, unsigned int128 );
114        OSTYPE_VOID( unsigned int128 );
115        #endif // __SIZEOF_INT128__
116
117        ostype & ?|?( ostype &, float );
118        OSTYPE_VOID( float );
119        ostype & ?|?( ostype &, double );
120        OSTYPE_VOID( double );
121        ostype & ?|?( ostype &, long double );
122        OSTYPE_VOID( long double );
123
124        ostype & ?|?( ostype &, float _Complex );
125        OSTYPE_VOID( float _Complex );
126        ostype & ?|?( ostype &, double _Complex );
127        OSTYPE_VOID( double _Complex );
128        ostype & ?|?( ostype &, long double _Complex );
129        OSTYPE_VOID( long double _Complex );
130
131        ostype & ?|?( ostype &, const char [] );
132        OSTYPE_VOID( const char [] );
133        // ostype & ?|?( ostype &, const char16_t [] );
134        #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
135        // ostype & ?|?( ostype &, const char32_t [] );
136        #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
137        // ostype & ?|?( ostype &, const wchar_t [] );
138        ostype & ?|?( ostype &, const void * );
139        OSTYPE_VOID( const void * );
140
141        // FIX-ME: does not work so using macros
142        // forall( T | { ostype & ?|?( ostype &, T ); } )
143        // void ?|?( ostype & os, T );
144
145        // manipulators
146        ostype & ?|?( ostype &, ostype & (*)( ostype & ) );
147        OSTYPE_VOID( ostype & (*)( ostype & ) );
148
149        ostype & nl( ostype & );
150        ostype & nonl( ostype & );
151        ostype & nlOn( ostype & );
152        ostype & nlOff( ostype & );
153
154        ostype & sepVal( ostype & );
155        ostype & sepTupleVal( ostype & );
156        ostype & sep( ostype & );
157        ostype & nosep( ostype & );
158        ostype & sepOn( ostype & );
159        ostype & sepOff( ostype & );
160} // distribution
161
162// tuples
163forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
164        ostype & ?|?( ostype & os, T arg, Params rest );
165        void ?|?( ostype & os, T arg, Params rest );
166} // distribution
167
168// writes the range [begin, end) to the given stream
169forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) {
170        void write( iterator_type begin, iterator_type end, ostype & os );
171        void write_reverse( iterator_type begin, iterator_type end, ostype & os );
172} // distribution
173
174// *********************************** manipulators ***********************************
175
176struct _Ostream_Flags {
177        unsigned char eng:1;                                                            // engineering notation
178        unsigned char neg:1;                                                            // val is negative
179        unsigned char pc:1;                                                                     // precision specified
180        unsigned char left:1;                                                           // left justify
181        unsigned char nobsdp:1;                                                         // base prefix / decimal point
182        unsigned char sign:1;                                                           // plus / minus sign
183        unsigned char pad0:1;                                                           // zero pad
184};
185
186forall( T )
187struct _Ostream_Manip {
188        T val;                                                                                          // polymorphic base-type
189        int wd, pc;                                                                                     // width, precision: signed for computations
190        char base;                                                                                      // numeric base / floating-point style
191        union {
192                unsigned char all;
193                _Ostream_Flags flags;
194        };
195}; // _Ostream_Manip
196
197// *********************************** integral ***********************************
198
199// See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular
200// subobject overriding any previously listed initializer for the same subobject; ***all subobjects that are not
201// initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.***
202
203#define INTEGRAL_FMT_DECL( T, CODE ) \
204static inline { \
205        _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \
206        _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'o', { .all : 0 } }; } \
207        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \
208        _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \
209        _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \
210        _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
211        _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
212        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
213        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \
214        _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
215        _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
216        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \
217        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
218} /* distribution */ \
219forall( ostype & | basic_ostream( ostype ) ) { \
220        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
221        OSTYPE_VOID( _Ostream_Manip(T) ); \
222} // ?|?
223
224INTEGRAL_FMT_DECL( signed char, 'd' )
225INTEGRAL_FMT_DECL( unsigned char, 'u' )
226INTEGRAL_FMT_DECL( signed short int, 'd' )
227INTEGRAL_FMT_DECL( unsigned short int, 'u' )
228INTEGRAL_FMT_DECL( signed int, 'd' )
229INTEGRAL_FMT_DECL( unsigned int, 'u' )
230INTEGRAL_FMT_DECL( signed long int, 'd' )
231INTEGRAL_FMT_DECL( unsigned long int, 'u' )
232INTEGRAL_FMT_DECL( signed long long int, 'd' )
233INTEGRAL_FMT_DECL( unsigned long long int, 'u' )
234#if defined( __SIZEOF_INT128__ )
235INTEGRAL_FMT_DECL( int128, 'd' )
236INTEGRAL_FMT_DECL( unsigned int128, 'u' )
237#endif // __SIZEOF_INT128__
238
239// *********************************** floating point ***********************************
240
241// Default suffix for values with no fraction is "."
242#define FLOATING_POINT_FMT_DECL( T ) \
243static inline { \
244        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \
245        _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \
246        _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.eng : true } }; } \
247        _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'g', { .all : 0 } }; } \
248        _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
249        _Ostream_Manip(T) ws( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
250        _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; return fmt; } \
251        _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
252        _Ostream_Manip(T) & ws( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
253        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
254        _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \
255        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \
256        _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
257        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.sign : true } }; } \
258        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
259        _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
260        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
261        _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
262        _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
263} /* distribution */ \
264forall( ostype & | basic_ostream( ostype ) ) { \
265        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
266        OSTYPE_VOID( _Ostream_Manip(T) ); \
267} // ?|?
268
269FLOATING_POINT_FMT_DECL( double )
270FLOATING_POINT_FMT_DECL( long double )
271
272// *********************************** character ***********************************
273
274static inline {
275        _Ostream_Manip(char) bin( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'b', { .all : 0 } }; }
276        _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'o', { .all : 0 } }; }
277        _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'x', { .all : 0 } }; }
278        _Ostream_Manip(char) wd( unsigned int w, char c ) { return (_Ostream_Manip(char))@{ c, w, 0, 'c', { .all : 0 } }; }
279        _Ostream_Manip(char) & wd( unsigned int w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; }
280        _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; }
281        _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
282        _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
283} // distribution
284forall( ostype & | basic_ostream( ostype ) ) {
285        ostype & ?|?( ostype & os, _Ostream_Manip(char) f );
286        OSTYPE_VOID( _Ostream_Manip(char) ); \
287} // ?|?
288
289// *********************************** C string ***********************************
290
291static inline {
292        _Ostream_Manip(const char *) bin( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'b', { .all : 0 } }; }
293        _Ostream_Manip(const char *) oct( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'o', { .all : 0 } }; }
294        _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; }
295        _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; }
296        _Ostream_Manip(const char *) wd( unsigned int w, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }
297        _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
298        _Ostream_Manip(const char *) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
299        _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; }
300        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
301} // distribution
302forall( ostype & | basic_ostream( ostype ) ) {
303        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f );
304        OSTYPE_VOID( _Ostream_Manip(const char *) ); \
305} // ?|?
306
307
308// *********************************** istream ***********************************
309
310
311#define ISTYPE_VOID( T ) void ?|?( istype &, T )
312#define ISTYPE_VOID_IMPL( T ) \
313        void ?|?( istype & is, T t ) { \
314                (istype &)(is | t); ends( is ); \
315        } // ?|?
316
317forall( istype & )
318trait basic_istream {
319        // private
320        bool getANL$( istype & );                                                       // get scan newline (on/off)
321        bool setANL$( istype &, bool );                                         // set scan newline (on/off)
322        // public
323        void nlOn( istype & );                                                          // read newline
324        void nlOff( istype & );                                                         // scan newline
325        void ends( istype & os );                                                       // end of output statement
326        int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
327        istype & ungetc( istype &, char );
328        bool eof( istype & );
329}; // basic_istream
330
331forall( istype & | basic_istream( istype ) )
332trait istream {
333        bool fail( istype & );
334        void clear( istype & );
335        void open( istype & is, const char name[] );
336        void close( istype & is );
337        istype & read( istype &, char [], size_t );
338}; // istream
339
340forall( T )
341trait readable {
342        forall( istype & | istream( istype ) ) istype & ?|?( istype &, T );
343}; // readable
344
345forall( istype & | basic_istream( istype ) ) {
346        istype & ?|?( istype &, bool & );
347        ISTYPE_VOID( bool & );
348
349        istype & ?|?( istype &, char & );
350        ISTYPE_VOID( char & );
351        istype & ?|?( istype &, signed char & );
352        ISTYPE_VOID( signed char & );
353        istype & ?|?( istype &, unsigned char & );
354        ISTYPE_VOID( unsigned char & );
355
356        istype & ?|?( istype &, short int & );
357        ISTYPE_VOID( short int & );
358        istype & ?|?( istype &, unsigned short int & );
359        ISTYPE_VOID( unsigned short int & );
360        istype & ?|?( istype &, int & );
361        ISTYPE_VOID( int & );
362        istype & ?|?( istype &, unsigned int & );
363        ISTYPE_VOID( unsigned int & );
364        istype & ?|?( istype &, long int & );
365        ISTYPE_VOID( long int & );
366        istype & ?|?( istype &, unsigned long int & );
367        ISTYPE_VOID( unsigned long int & );
368        istype & ?|?( istype &, long long int & );
369        ISTYPE_VOID( long long int & );
370        istype & ?|?( istype &, unsigned long long int & );
371        ISTYPE_VOID( unsigned long long int & );
372        #if defined( __SIZEOF_INT128__ )
373        istype & ?|?( istype &, int128 & );
374        ISTYPE_VOID( int128 & );
375        istype & ?|?( istype &, unsigned int128 & );
376        ISTYPE_VOID( unsigned int128 & );
377        #endif // __SIZEOF_INT128__
378
379        istype & ?|?( istype &, float & );
380        ISTYPE_VOID( float & );
381        istype & ?|?( istype &, double & );
382        ISTYPE_VOID( double & );
383        istype & ?|?( istype &, long double & );
384        ISTYPE_VOID( long double & );
385
386        istype & ?|?( istype &, float _Complex & );
387        ISTYPE_VOID( float _Complex & );
388        istype & ?|?( istype &, double _Complex & );
389        ISTYPE_VOID( double _Complex & );
390        istype & ?|?( istype &, long double _Complex & );
391        ISTYPE_VOID( long double _Complex & );
392
393//      istype & ?|?( istype &, const char [] );
394//      istype & ?|?( istype &, char [] );
395//      ISTYPE_VOID( char [] );
396
397        // manipulators
398        istype & ?|?( istype &, istype & (*)( istype & ) );
399        ISTYPE_VOID( istype & (*)( istype & ) );
400        istype & nl( istype & is );
401        istype & nlOn( istype & );
402        istype & nlOff( istype & );
403} // distribution
404
405
406// *********************************** exceptions ***********************************
407
408
409ExceptionDecl( cstring_length );
410
411
412// *********************************** manipulators ***********************************
413
414struct _Istream_Cstr {
415        char * s;
416        union {
417                const char * scanset;
418                char delimit;
419        };
420        int wd;                                                                                         // width
421        union {
422                unsigned char all;
423                struct {
424                        unsigned char ignore:1;                                         // do not change input argument
425                        unsigned char inex:1;                                           // include/exclude characters in scanset
426                        unsigned char delimit:1;                                        // delimit character
427                        unsigned char rwd:1;                                            // read width
428                } flags;
429        };
430}; // _Istream_Cstr
431
432static inline {
433        // width must include room for null terminator
434        _Istream_Cstr wdi( unsigned int wd, char s[] ) { return (_Istream_Cstr)@{ s, {0p}, wd, {.all : 0} }; }
435        // read width does not include null terminator
436        _Istream_Cstr wdi( unsigned int wd, unsigned int rwd, char s[] ) {
437                if ( wd <= rwd ) throw (cstring_length){ &cstring_length_vt };
438                return (_Istream_Cstr)@{ s, {0p}, rwd, {.flags.rwd : true} };
439        }
440        _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, {scanset}, -1, {.all : 0} }; }
441        _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr){ 0p, {0p}, wd, {.all : 0} }; }
442        _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) { fmt.delimit = delimit; fmt.flags.delimit = true; return fmt; }
443        _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
444        _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
445        _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, {0p}, -1, {.flags.ignore : true} }; }
446        _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; }
447} // distribution
448forall( istype & | basic_istream( istype ) ) {
449        istype & ?|?( istype & is, _Istream_Cstr f );
450        ISTYPE_VOID( _Istream_Cstr );
451}
452
453struct _Istream_Char {
454        bool ignore;                                                                            // do not change input argument
455}; // _Istream_Char
456
457static inline {
458        _Istream_Char ignore( const char ) { return (_Istream_Char)@{ true }; }
459        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
460} // distribution
461forall( istype & | basic_istream( istype ) ) {
462        istype & ?|?( istype & is, _Istream_Char f );
463        ISTYPE_VOID( _Istream_Char );
464}
465
466forall( T & | sized( T ) )
467struct _Istream_Manip {
468        T & val;                                                                                        // polymorphic base-type
469        int wd;                                                                                         // width
470        bool ignore;                                                                            // do not change input argument
471}; // _Istream_Manip
472
473#define INPUT_FMT_DECL( T ) \
474static inline { \
475        _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \
476        _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
477        _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ val, wd, false }; } \
478        _Istream_Manip(T) & wdi( unsigned int wd, _Istream_Manip(T) & fmt ) { fmt.wd = wd; return fmt; } \
479} /* distribution */ \
480forall( istype & | basic_istream( istype ) ) { \
481        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
482        ISTYPE_VOID( _Istream_Manip(T) ); \
483} // ?|?
484
485INPUT_FMT_DECL( signed char )
486INPUT_FMT_DECL( unsigned char )
487INPUT_FMT_DECL( signed short int )
488INPUT_FMT_DECL( unsigned short int )
489INPUT_FMT_DECL( signed int )
490INPUT_FMT_DECL( unsigned int )
491INPUT_FMT_DECL( signed long int )
492INPUT_FMT_DECL( unsigned long int )
493INPUT_FMT_DECL( signed long long int )
494INPUT_FMT_DECL( unsigned long long int )
495
496INPUT_FMT_DECL( float )
497INPUT_FMT_DECL( double )
498INPUT_FMT_DECL( long double )
499
500INPUT_FMT_DECL( float _Complex )
501INPUT_FMT_DECL( double _Complex )
502INPUT_FMT_DECL( long double _Complex )
503
504
505// *********************************** time ***********************************
506
507
508#include <time_t.hfa>                                                                   // Duration (constructors) / Time (constructors)
509
510forall( ostype & | ostream( ostype ) ) {
511        ostype & ?|?( ostype & os, Duration dur );
512        OSTYPE_VOID( Duration );
513        ostype & ?|?( ostype & os, Time time );
514        OSTYPE_VOID( Time );
515} // distribution
516
517// Local Variables: //
518// tab-width: 4 //
519// End: //
Note: See TracBrowser for help on using the repository browser.