source: libcfa/src/iostream.hfa @ d0cfcbe1

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

change setter routines in basic_i/ostream to return previous state

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