source: libcfa/src/iostream.hfa @ 94d2544

Last change on this file since 94d2544 was 94d2544, checked in by Peter A. Buhr <pabuhr@…>, 11 months ago

formatting, create macros OSTYPE_VOID, OSTYPE_VOID_IMPL. ISTYPE_VOID, ISTYPE_VOID_IMPL to create companion void print routine

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