source: libcfa/src/iostream.hfa@ fb4b283

Last change on this file since fb4b283 was f5d9c37, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago

harmonize separator manipulators names with newline names: change from sep, sepTuple, sepEnable, sepDisable, sepOn, sepOff to sepVal, sepTupleVal, sepOn, sepOff, sep, nosep; fix bug printing null string with WD so no separator

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