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