Changeset 5407cdc for libcfa/src/iostream.hfa
- Timestamp:
- Apr 28, 2021, 4:56:50 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8d66610
- Parents:
- feacef9 (diff), b7fd2db6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/iostream.hfa (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.hfa
rfeacef9 r5407cdc 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue A ug 11 22:16:14 202013 // Update Count : 3 5012 // Last Modified On : Tue Apr 27 17:59:21 2021 13 // Update Count : 398 14 14 // 15 15 … … 22 22 23 23 24 trait ostream( ostype & ) {24 trait basic_ostream( ostype & ) { 25 25 // private 26 bool $sepPrt( ostype & ); // get separator state (on/off)27 void $sepReset( ostype & ); // set separator state to default state28 void $sepReset( ostype &, bool ); // set separator and default state29 const char * $sepGetCur( ostype & ); // get current separator string30 void $sepSetCur( ostype &, const char [] ); // set current separator string31 bool $getNL( ostype & ); // check newline32 void $setNL( ostype &, bool ); // saw newline33 bool $getANL( ostype & ); // get auto newline (on/off)34 bool $getPrt( ostype & ); // get fmt called in output cascade35 void $setPrt( ostype &, bool ); // set fmt called in output cascade26 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 36 36 // public 37 37 void sepOn( ostype & ); // turn separator state on … … 47 47 void sepSetTuple( ostype &, const char [] ); // set tuple separator to string (15 character maximum) 48 48 49 void ends( ostype & os ); // end of output statement 50 int fail( ostype & ); 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 ) ) { 51 54 int flush( ostype & ); 52 void open( ostype & os, const char name[], const char mode[] ); 53 void close( ostype & os ); 55 bool fail( ostype & ); // operation failed? 56 void open( ostype &, const char name[], const char mode[] ); 57 void close( ostype & ); 54 58 ostype & write( ostype &, const char [], size_t ); 55 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));59 void acquire( ostype & ); // concurrent access 56 60 }; // ostream 57 61 … … 66 70 // implement writable for intrinsic types 67 71 68 forall( ostype & | ostream( ostype ) ) {72 forall( ostype & | basic_ostream( ostype ) ) { 69 73 ostype & ?|?( ostype &, bool ); 70 74 void ?|?( ostype &, bool ); … … 93 97 ostype & ?|?( ostype &, unsigned long long int ); 94 98 void ?|?( ostype &, unsigned long long int ); 95 #if defined( __SIZEOF_INT128__ )99 #if defined( __SIZEOF_INT128__ ) 96 100 ostype & ?|?( ostype &, int128 ); 97 101 void ?|?( ostype &, int128 ); 98 102 ostype & ?|?( ostype &, unsigned int128 ); 99 103 void ?|?( ostype &, unsigned int128 ); 100 #endif // __SIZEOF_INT128__104 #endif // __SIZEOF_INT128__ 101 105 102 106 ostype & ?|?( ostype &, float ); … … 117 121 void ?|?( ostype &, const char [] ); 118 122 // ostype & ?|?( ostype &, const char16_t * ); 119 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous123 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous 120 124 // ostype & ?|?( ostype &, const char32_t * ); 121 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )125 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) 122 126 // ostype & ?|?( ostype &, const wchar_t * ); 123 127 ostype & ?|?( ostype &, const void * ); … … 139 143 } // distribution 140 144 145 forall( ostype & | ostream( ostype ) ) { 146 ostype & acquire( ostype & ); 147 } // distribution 148 141 149 // tuples 142 150 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { … … 156 164 struct _Ostream_Manip { 157 165 T val; // polymorphic base-type 158 unsigned int wd, pc; // width, precision166 int wd, pc; // width, precision: signed for computations 159 167 char base; // numeric base / floating-point style 160 168 union { 161 169 unsigned char all; 162 170 struct { 171 unsigned char eng:1; // engineering notation 163 172 unsigned char neg:1; // val is negative 164 173 unsigned char pc:1; // precision specified … … 183 192 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \ 184 193 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \ 185 _Ostream_Manip(T) wd( unsigned int w, unsigned charpc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \194 _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \ 186 195 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 187 _Ostream_Manip(T) & wd( unsigned int w, unsigned charpc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \196 _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; } \ 188 197 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 189 198 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \ … … 193 202 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 194 203 } /* distribution */ \ 195 forall( ostype & | ostream( ostype ) ) { \204 forall( ostype & | basic_ostream( ostype ) ) { \ 196 205 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 197 206 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 220 229 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \ 221 230 _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \ 222 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'f', { .all : 0 } }; } \ 223 _Ostream_Manip(T) wd( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \ 224 _Ostream_Manip(T) ws( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \ 225 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 226 _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; } \ 231 _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.eng : true } }; } \ 232 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'g', { .all : 0 } }; } \ 233 _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \ 234 _Ostream_Manip(T) ws( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \ 235 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; return fmt; } \ 236 _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; } \ 237 _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; } \ 227 238 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 228 239 _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \ … … 233 244 _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \ 234 245 _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 246 _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \ 247 _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 235 248 } /* distribution */ \ 236 forall( ostype & | ostream( ostype ) ) { \249 forall( ostype & | basic_ostream( ostype ) ) { \ 237 250 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 238 251 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 254 267 _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 255 268 } // distribution 256 forall( ostype & | ostream( ostype ) ) {269 forall( ostype & | basic_ostream( ostype ) ) { 257 270 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 258 271 void ?|?( ostype & os, _Ostream_Manip(char) f ); … … 266 279 _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; } 267 280 _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; } 268 _Ostream_Manip(const char *) wd( unsigned int w, unsigned charpc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }281 _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 } }; } 269 282 _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; } 270 _Ostream_Manip(const char *) & wd( unsigned int w, unsigned charpc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }283 _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; } 271 284 _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; } 272 285 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 273 286 } // distribution 274 forall( ostype & | ostream( ostype ) ) {287 forall( ostype & | basic_ostream( ostype ) ) { 275 288 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 276 289 void ?|?( ostype & os, _Ostream_Manip(const char *) f ); … … 281 294 282 295 283 trait istream( istype & ) { 296 trait basic_istream( istype & ) { 297 bool getANL( istype & ); // get scan newline (on/off) 284 298 void nlOn( istype & ); // read newline 285 299 void nlOff( istype & ); // scan newline 286 bool getANL( istype & ); // get scan newline (on/off) 287 int fail( istype & ); 300 301 void ends( istype & os ); // end of output statement 302 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 303 istype & ungetc( istype &, char ); 288 304 int eof( istype & ); 305 }; // basic_istream 306 307 trait istream( istype & | basic_istream( istype ) ) { 308 bool fail( istype & ); 289 309 void open( istype & is, const char name[] ); 290 310 void close( istype & is ); 291 311 istype & read( istype &, char *, size_t ); 292 istype & ungetc( istype &, char ); 293 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 312 void acquire( istype & ); // concurrent access 294 313 }; // istream 295 314 … … 298 317 }; // readable 299 318 300 forall( istype & | istream( istype ) ) {319 forall( istype & | basic_istream( istype ) ) { 301 320 istype & ?|?( istype &, bool & ); 321 void ?|?( istype &, bool & ); 302 322 303 323 istype & ?|?( istype &, char & ); 324 void ?|?( istype &, char & ); 304 325 istype & ?|?( istype &, signed char & ); 326 void ?|?( istype &, signed char & ); 305 327 istype & ?|?( istype &, unsigned char & ); 328 void ?|?( istype &, unsigned char & ); 306 329 307 330 istype & ?|?( istype &, short int & ); 331 void ?|?( istype &, short int & ); 308 332 istype & ?|?( istype &, unsigned short int & ); 333 void ?|?( istype &, unsigned short int & ); 309 334 istype & ?|?( istype &, int & ); 335 void ?|?( istype &, int & ); 310 336 istype & ?|?( istype &, unsigned int & ); 337 void ?|?( istype &, unsigned int & ); 311 338 istype & ?|?( istype &, long int & ); 339 void ?|?( istype &, long int & ); 312 340 istype & ?|?( istype &, unsigned long int & ); 341 void ?|?( istype &, unsigned long int & ); 313 342 istype & ?|?( istype &, long long int & ); 343 void ?|?( istype &, long long int & ); 314 344 istype & ?|?( istype &, unsigned long long int & ); 315 #if defined( __SIZEOF_INT128__ ) 345 void ?|?( istype &, unsigned long long int & ); 346 #if defined( __SIZEOF_INT128__ ) 316 347 istype & ?|?( istype &, int128 & ); 348 void ?|?( istype &, int128 & ); 317 349 istype & ?|?( istype &, unsigned int128 & ); 318 #endif // __SIZEOF_INT128__ 350 void ?|?( istype &, unsigned int128 & ); 351 #endif // __SIZEOF_INT128__ 319 352 320 353 istype & ?|?( istype &, float & ); 354 void ?|?( istype &, float & ); 321 355 istype & ?|?( istype &, double & ); 356 void ?|?( istype &, double & ); 322 357 istype & ?|?( istype &, long double & ); 358 void ?|?( istype &, long double & ); 323 359 324 360 istype & ?|?( istype &, float _Complex & ); 361 void ?|?( istype &, float _Complex & ); 325 362 istype & ?|?( istype &, double _Complex & ); 363 void ?|?( istype &, double _Complex & ); 326 364 istype & ?|?( istype &, long double _Complex & ); 365 void ?|?( istype &, long double _Complex & ); 327 366 328 367 // istype & ?|?( istype &, const char [] ); 329 istype & ?|?( istype &, char * ); 368 istype & ?|?( istype &, char [] ); 369 void ?|?( istype &, char [] ); 330 370 331 371 // manipulators 332 372 istype & ?|?( istype &, istype & (*)( istype & ) ); 373 void ?|?( istype &, istype & (*)( istype & ) ); 333 374 istype & nl( istype & is ); 334 375 istype & nlOn( istype & ); 335 376 istype & nlOff( istype & ); 377 } // distribution 378 379 forall( istype & | istream( istype ) ) { 380 istype & acquire( istype & ); 336 381 } // distribution 337 382 … … 352 397 353 398 static inline { 399 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; } 354 400 _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; } 355 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }356 401 _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; } 357 402 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } … … 363 408 _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; } 364 409 } // distribution 365 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f ); 410 forall( istype & | basic_istream( istype ) ) { 411 istype & ?|?( istype & is, _Istream_Cstr f ); 412 void ?|?( istype & is, _Istream_Cstr f ); 413 } 366 414 367 415 struct _Istream_Char { … … 373 421 _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; } 374 422 } // distribution 375 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f ); 423 forall( istype & | basic_istream( istype ) ) { 424 istype & ?|?( istype & is, _Istream_Char f ); 425 void ?|?( istype & is, _Istream_Char f ); 426 } 376 427 377 428 forall( T & | sized( T ) ) … … 389 440 _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 390 441 } /* distribution */ \ 391 forall( istype & | istream( istype ) ) { \442 forall( istype & | basic_istream( istype ) ) { \ 392 443 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 444 void ?|?( istype & is, _Istream_Manip(T) f ); \ 393 445 } // ?|? 394 446
Note:
See TracChangeset
for help on using the changeset viewer.