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