Changeset 2a301ff for libcfa/src/iostream.hfa
- Timestamp:
- Aug 31, 2023, 11:31:15 PM (2 years ago)
- Branches:
- master
- Children:
- 950c58e
- Parents:
- 92355883 (diff), 686912c (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) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.hfa
r92355883 r2a301ff 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 15 22:34:31202313 // Update Count : 41112 // Last Modified On : Thu Aug 31 10:55:35 2023 13 // Update Count : 544 14 14 // 15 15 … … 17 17 18 18 #include "iterator.hfa" 19 19 #include "Exception.hfa" 20 20 21 21 // *********************************** ostream *********************************** 22 23 22 24 23 forall( ostype & ) … … 30 29 const char * sepGetCur$( ostype & ); // get current separator string 31 30 void sepSetCur$( ostype &, const char [] ); // set current separator string 32 bool getNL$( ostype & ); // checknewline33 void setNL$( ostype &, bool ); // sawnewline31 bool getNL$( ostype & ); // get newline 32 bool setNL$( ostype &, bool ); // set newline 34 33 bool getANL$( ostype & ); // get auto newline (on/off) 34 bool setANL$( ostype &, bool ); // set auto newline (on/off), and return previous state 35 35 bool getPrt$( ostype & ); // get fmt called in output cascade 36 voidsetPrt$( ostype &, bool ); // set fmt called in output cascade36 bool setPrt$( ostype &, bool ); // set fmt called in output cascade 37 37 // public 38 void sepOn( ostype & ); // turn separator state on39 void sepOff( ostype & ); // turn separator state off40 bool sepDisable( ostype & ); // set default state to off, and return previous state41 bool sepEnable( ostype & ); // set default state to on, and return previous state42 38 void nlOn( ostype & ); // turn auto-newline state on 43 39 void nlOff( ostype & ); // turn auto-newline state off 44 40 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 45 45 const char * sepGet( ostype & ); // get separator string 46 46 void sepSet( ostype &, const char [] ); // set separator to string (15 character maximum) … … 74 74 // implement writable for intrinsic types 75 75 76 #define OSTYPE_VOID( T ) void ?|?( ostype &, T ) 77 #define OSTYPE_VOID_IMPL( T ) \ 78 void ?|?( ostype & os, T t ) { \ 79 (ostype &)(os | t); ends( os ); \ 80 } // ?|? 81 76 82 forall( ostype & | basic_ostream( ostype ) ) { 77 83 ostype & ?|?( ostype &, bool ); 78 void ?|?( ostype &,bool );84 OSTYPE_VOID( bool ); 79 85 80 86 ostype & ?|?( ostype &, char ); 81 void ?|?( ostype &,char );87 OSTYPE_VOID( char ); 82 88 ostype & ?|?( ostype &, signed char ); 83 void ?|?( ostype &,signed char );89 OSTYPE_VOID( signed char ); 84 90 ostype & ?|?( ostype &, unsigned char ); 85 void ?|?( ostype &,unsigned char );91 OSTYPE_VOID( unsigned char ); 86 92 87 93 ostype & ?|?( ostype &, short int ); 88 void ?|?( ostype &,short int );94 OSTYPE_VOID( short int ); 89 95 ostype & ?|?( ostype &, unsigned short int ); 90 void ?|?( ostype &,unsigned short int );96 OSTYPE_VOID( unsigned short int ); 91 97 ostype & ?|?( ostype &, int ); 92 void ?|?( ostype &,int );98 OSTYPE_VOID( int ); 93 99 ostype & ?|?( ostype &, unsigned int ); 94 void ?|?( ostype &,unsigned int );100 OSTYPE_VOID( unsigned int ); 95 101 ostype & ?|?( ostype &, long int ); 96 void ?|?( ostype &,long int );102 OSTYPE_VOID( long int ); 97 103 ostype & ?|?( ostype &, long long int ); 98 void ?|?( ostype &,long long int );104 OSTYPE_VOID( long long int ); 99 105 ostype & ?|?( ostype &, unsigned long int ); 100 void ?|?( ostype &,unsigned long int );106 OSTYPE_VOID( unsigned long int ); 101 107 ostype & ?|?( ostype &, unsigned long long int ); 102 void ?|?( ostype &,unsigned long long int );108 OSTYPE_VOID( unsigned long long int ); 103 109 #if defined( __SIZEOF_INT128__ ) 104 110 ostype & ?|?( ostype &, int128 ); 105 void ?|?( ostype &,int128 );111 OSTYPE_VOID( int128 ); 106 112 ostype & ?|?( ostype &, unsigned int128 ); 107 void ?|?( ostype &,unsigned int128 );113 OSTYPE_VOID( unsigned int128 ); 108 114 #endif // __SIZEOF_INT128__ 109 115 110 116 ostype & ?|?( ostype &, float ); 111 void ?|?( ostype &,float );117 OSTYPE_VOID( float ); 112 118 ostype & ?|?( ostype &, double ); 113 void ?|?( ostype &,double );119 OSTYPE_VOID( double ); 114 120 ostype & ?|?( ostype &, long double ); 115 void ?|?( ostype &,long double );121 OSTYPE_VOID( long double ); 116 122 117 123 ostype & ?|?( ostype &, float _Complex ); 118 void ?|?( ostype &,float _Complex );124 OSTYPE_VOID( float _Complex ); 119 125 ostype & ?|?( ostype &, double _Complex ); 120 void ?|?( ostype &,double _Complex );126 OSTYPE_VOID( double _Complex ); 121 127 ostype & ?|?( ostype &, long double _Complex ); 122 void ?|?( ostype &,long double _Complex );128 OSTYPE_VOID( long double _Complex ); 123 129 124 130 ostype & ?|?( ostype &, const char [] ); 125 void ?|?( ostype &,const char [] );126 // ostype & ?|?( ostype &, const char16_t *);131 OSTYPE_VOID( const char [] ); 132 // ostype & ?|?( ostype &, const char16_t [] ); 127 133 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous 128 // ostype & ?|?( ostype &, const char32_t *);134 // ostype & ?|?( ostype &, const char32_t [] ); 129 135 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) 130 // ostype & ?|?( ostype &, const wchar_t *);136 // ostype & ?|?( ostype &, const wchar_t [] ); 131 137 ostype & ?|?( ostype &, const void * ); 132 void ?|?( ostype &, const void * ); 138 OSTYPE_VOID( const void * ); 139 140 // FIX-ME: does not work so using macros 141 // forall( T | { ostype & ?|?( ostype &, T ); } ) 142 // void ?|?( ostype & os, T ); 133 143 134 144 // manipulators 135 145 ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); 136 void ?|?( ostype &, ostype & (*)( ostype & ) ); 146 OSTYPE_VOID( ostype & (*)( ostype & ) ); 147 137 148 ostype & nl( ostype & ); 138 149 ostype & nonl( ostype & ); 150 ostype & nlOn( ostype & ); 151 ostype & nlOff( ostype & ); 152 153 ostype & sepVal( ostype & ); 154 ostype & sepTupleVal( ostype & ); 139 155 ostype & sep( ostype & ); 140 ostype & sepTuple( ostype & );156 ostype & nosep( ostype & ); 141 157 ostype & sepOn( ostype & ); 142 158 ostype & sepOff( ostype & ); 143 ostype & sepDisable( ostype & );144 ostype & sepEnable( ostype & );145 ostype & nlOn( ostype & );146 ostype & nlOff( ostype & );147 159 } // distribution 148 160 … … 188 200 // initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.*** 189 201 190 #define I ntegralFMTDecl( T, CODE ) \202 #define INTEGRAL_FMT_DECL( T, CODE ) \ 191 203 static inline { \ 192 204 _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \ … … 206 218 forall( ostype & | basic_ostream( ostype ) ) { \ 207 219 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 208 void ?|?( ostype & os, _Ostream_Manip(T) f); \220 OSTYPE_VOID( _Ostream_Manip(T) ); \ 209 221 } // ?|? 210 222 211 I ntegralFMTDecl( signed char, 'd' )212 I ntegralFMTDecl( unsigned char, 'u' )213 I ntegralFMTDecl( signed short int, 'd' )214 I ntegralFMTDecl( unsigned short int, 'u' )215 I ntegralFMTDecl( signed int, 'd' )216 I ntegralFMTDecl( unsigned int, 'u' )217 I ntegralFMTDecl( signed long int, 'd' )218 I ntegralFMTDecl( unsigned long int, 'u' )219 I ntegralFMTDecl( signed long long int, 'd' )220 I ntegralFMTDecl( unsigned long long int, 'u' )223 INTEGRAL_FMT_DECL( signed char, 'd' ) 224 INTEGRAL_FMT_DECL( unsigned char, 'u' ) 225 INTEGRAL_FMT_DECL( signed short int, 'd' ) 226 INTEGRAL_FMT_DECL( unsigned short int, 'u' ) 227 INTEGRAL_FMT_DECL( signed int, 'd' ) 228 INTEGRAL_FMT_DECL( unsigned int, 'u' ) 229 INTEGRAL_FMT_DECL( signed long int, 'd' ) 230 INTEGRAL_FMT_DECL( unsigned long int, 'u' ) 231 INTEGRAL_FMT_DECL( signed long long int, 'd' ) 232 INTEGRAL_FMT_DECL( unsigned long long int, 'u' ) 221 233 #if defined( __SIZEOF_INT128__ ) 222 I ntegralFMTDecl( int128, 'd' )223 I ntegralFMTDecl( unsigned int128, 'u' )234 INTEGRAL_FMT_DECL( int128, 'd' ) 235 INTEGRAL_FMT_DECL( unsigned int128, 'u' ) 224 236 #endif // __SIZEOF_INT128__ 225 237 … … 227 239 228 240 // Default suffix for values with no fraction is "." 229 #define F loatingPointFMTDecl( T ) \241 #define FLOATING_POINT_FMT_DECL( T ) \ 230 242 static inline { \ 231 243 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \ … … 251 263 forall( ostype & | basic_ostream( ostype ) ) { \ 252 264 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 253 void ?|?( ostype & os, _Ostream_Manip(T) f); \265 OSTYPE_VOID( _Ostream_Manip(T) ); \ 254 266 } // ?|? 255 267 256 F loatingPointFMTDecl( double )257 F loatingPointFMTDecl( long double )268 FLOATING_POINT_FMT_DECL( double ) 269 FLOATING_POINT_FMT_DECL( long double ) 258 270 259 271 // *********************************** character *********************************** … … 271 283 forall( ostype & | basic_ostream( ostype ) ) { 272 284 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 273 void ?|?( ostype & os, _Ostream_Manip(char) f );285 OSTYPE_VOID( _Ostream_Manip(char) ); \ 274 286 } // ?|? 275 287 … … 289 301 forall( ostype & | basic_ostream( ostype ) ) { 290 302 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 291 void ?|?( ostype & os, _Ostream_Manip(const char *) f );303 OSTYPE_VOID( _Ostream_Manip(const char *) ); \ 292 304 } // ?|? 293 305 294 295 306 // *********************************** istream *********************************** 296 307 308 #define ISTYPE_VOID( T ) void ?|?( istype &, T ) 309 #define ISTYPE_VOID_IMPL( T ) \ 310 void ?|?( istype & is, T t ) { \ 311 (istype &)(is | t); ends( is ); \ 312 } // ?|? 297 313 298 314 forall( istype & ) … … 300 316 // private 301 317 bool getANL$( istype & ); // get scan newline (on/off) 318 bool setANL$( istype &, bool ); // set scan newline (on/off) 302 319 // public 303 320 void nlOn( istype & ); // read newline … … 325 342 forall( istype & | basic_istream( istype ) ) { 326 343 istype & ?|?( istype &, bool & ); 327 void ?|?( istype &,bool & );344 ISTYPE_VOID( bool & ); 328 345 329 346 istype & ?|?( istype &, char & ); 330 void ?|?( istype &,char & );347 ISTYPE_VOID( char & ); 331 348 istype & ?|?( istype &, signed char & ); 332 void ?|?( istype &,signed char & );349 ISTYPE_VOID( signed char & ); 333 350 istype & ?|?( istype &, unsigned char & ); 334 void ?|?( istype &,unsigned char & );351 ISTYPE_VOID( unsigned char & ); 335 352 336 353 istype & ?|?( istype &, short int & ); 337 void ?|?( istype &,short int & );354 ISTYPE_VOID( short int & ); 338 355 istype & ?|?( istype &, unsigned short int & ); 339 void ?|?( istype &,unsigned short int & );356 ISTYPE_VOID( unsigned short int & ); 340 357 istype & ?|?( istype &, int & ); 341 void ?|?( istype &,int & );358 ISTYPE_VOID( int & ); 342 359 istype & ?|?( istype &, unsigned int & ); 343 void ?|?( istype &,unsigned int & );360 ISTYPE_VOID( unsigned int & ); 344 361 istype & ?|?( istype &, long int & ); 345 void ?|?( istype &,long int & );362 ISTYPE_VOID( long int & ); 346 363 istype & ?|?( istype &, unsigned long int & ); 347 void ?|?( istype &,unsigned long int & );364 ISTYPE_VOID( unsigned long int & ); 348 365 istype & ?|?( istype &, long long int & ); 349 void ?|?( istype &,long long int & );366 ISTYPE_VOID( long long int & ); 350 367 istype & ?|?( istype &, unsigned long long int & ); 351 void ?|?( istype &,unsigned long long int & );368 ISTYPE_VOID( unsigned long long int & ); 352 369 #if defined( __SIZEOF_INT128__ ) 353 370 istype & ?|?( istype &, int128 & ); 354 void ?|?( istype &,int128 & );371 ISTYPE_VOID( int128 & ); 355 372 istype & ?|?( istype &, unsigned int128 & ); 356 void ?|?( istype &,unsigned int128 & );373 ISTYPE_VOID( unsigned int128 & ); 357 374 #endif // __SIZEOF_INT128__ 358 375 359 376 istype & ?|?( istype &, float & ); 360 void ?|?( istype &,float & );377 ISTYPE_VOID( float & ); 361 378 istype & ?|?( istype &, double & ); 362 void ?|?( istype &,double & );379 ISTYPE_VOID( double & ); 363 380 istype & ?|?( istype &, long double & ); 364 void ?|?( istype &,long double & );381 ISTYPE_VOID( long double & ); 365 382 366 383 istype & ?|?( istype &, float _Complex & ); 367 void ?|?( istype &,float _Complex & );384 ISTYPE_VOID( float _Complex & ); 368 385 istype & ?|?( istype &, double _Complex & ); 369 void ?|?( istype &,double _Complex & );386 ISTYPE_VOID( double _Complex & ); 370 387 istype & ?|?( istype &, long double _Complex & ); 371 void ?|?( istype &,long double _Complex & );388 ISTYPE_VOID( long double _Complex & ); 372 389 373 390 // istype & ?|?( istype &, const char [] ); 374 istype & ?|?( istype &, char [] );375 void ?|?( istype &,char [] );391 // istype & ?|?( istype &, char [] ); 392 // ISTYPE_VOID( char [] ); 376 393 377 394 // manipulators 378 395 istype & ?|?( istype &, istype & (*)( istype & ) ); 379 void ?|?( istype &,istype & (*)( istype & ) );396 ISTYPE_VOID( istype & (*)( istype & ) ); 380 397 istype & nl( istype & is ); 381 398 istype & nlOn( istype & ); … … 383 400 } // distribution 384 401 402 // *********************************** exceptions *********************************** 403 404 ExceptionDecl( cstring_length ); 405 385 406 // *********************************** manipulators *********************************** 386 407 387 struct _Istream_Cstr { 388 char * s; 389 const char * scanset; 408 struct _Istream_str_base { 409 union { 410 const char * scanset; 411 char delimit[2]; 412 }; 390 413 int wd; // width 391 414 union { … … 394 417 unsigned char ignore:1; // do not change input argument 395 418 unsigned char inex:1; // include/exclude characters in scanset 419 unsigned char delimit:1; // delimit character 420 unsigned char rwd:1; // read width 396 421 } flags; 397 422 }; 423 }; // _Istream_str_base 424 425 struct _Istream_Cstr { 426 char * s; 427 inline _Istream_str_base; 398 428 }; // _Istream_Cstr 399 429 400 430 static inline { 401 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; } 402 _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; } 403 _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; } 431 // width must include room for null terminator 432 _Istream_Cstr wdi( unsigned int wd, char s[] ) { return (_Istream_Cstr)@{ s, { {0p}, wd, {.all : 0} } }; } 433 // read width does not include null terminator 434 _Istream_Cstr wdi( unsigned int wd, unsigned int rwd, char s[] ) { 435 if ( wd <= rwd ) throw (cstring_length){ &cstring_length_vt }; 436 return (_Istream_Cstr)@{ s, { {0p}, rwd, {.flags.rwd : true} } }; 437 } 438 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr)@{ 0p, { {scanset}, -1, {.all : 0} } }; } 439 _Istream_Cstr skip( unsigned int wd ) { return (_Istream_Cstr)@{ 0p, { {0p}, wd, {.all : 0} } }; } 440 _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimit = '\n' ) { 441 fmt.delimit[0] = delimit; fmt.delimit[1] = '\0'; fmt.flags.delimit = true; fmt.flags.inex = true; return fmt; } 404 442 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } 405 _Istream_Cstr excl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; }406 443 _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; } 407 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, 0p, -1, { .flags.ignore : true} }; }444 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, { {0p}, -1, {.flags.ignore : true} } }; } 408 445 _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; } 409 _Istream_Cstr wdi( unsigned int w, char s[] ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; }410 _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }411 446 } // distribution 412 447 forall( istype & | basic_istream( istype ) ) { 413 448 istype & ?|?( istype & is, _Istream_Cstr f ); 414 void ?|?( istype & is, _Istream_Cstr f);449 ISTYPE_VOID( _Istream_Cstr ); 415 450 } 416 451 … … 425 460 forall( istype & | basic_istream( istype ) ) { 426 461 istype & ?|?( istype & is, _Istream_Char f ); 427 void ?|?( istype & is, _Istream_Char f);462 ISTYPE_VOID( _Istream_Char ); 428 463 } 429 464 … … 435 470 }; // _Istream_Manip 436 471 437 #define I nputFMTDecl( T ) \472 #define INPUT_FMT_DECL( T ) \ 438 473 static inline { \ 439 474 _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \ 440 475 _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \ 441 _Istream_Manip(T) wdi( unsigned int w , T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \442 _Istream_Manip(T) & wdi( unsigned int w , _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \476 _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ val, wd, false }; } \ 477 _Istream_Manip(T) & wdi( unsigned int wd, _Istream_Manip(T) & fmt ) { fmt.wd = wd; return fmt; } \ 443 478 } /* distribution */ \ 444 479 forall( istype & | basic_istream( istype ) ) { \ 445 480 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 446 void ?|?( istype & is, _Istream_Manip(T) f); \481 ISTYPE_VOID( _Istream_Manip(T) ); \ 447 482 } // ?|? 448 483 449 InputFMTDecl( signed char ) 450 InputFMTDecl( unsigned char ) 451 InputFMTDecl( signed short int ) 452 InputFMTDecl( unsigned short int ) 453 InputFMTDecl( signed int ) 454 InputFMTDecl( unsigned int ) 455 InputFMTDecl( signed long int ) 456 InputFMTDecl( unsigned long int ) 457 InputFMTDecl( signed long long int ) 458 InputFMTDecl( unsigned long long int ) 459 460 InputFMTDecl( float ) 461 InputFMTDecl( double ) 462 InputFMTDecl( long double ) 463 464 InputFMTDecl( float _Complex ) 465 InputFMTDecl( double _Complex ) 466 InputFMTDecl( long double _Complex ) 467 484 INPUT_FMT_DECL( signed char ) 485 INPUT_FMT_DECL( unsigned char ) 486 INPUT_FMT_DECL( signed short int ) 487 INPUT_FMT_DECL( unsigned short int ) 488 INPUT_FMT_DECL( signed int ) 489 INPUT_FMT_DECL( unsigned int ) 490 INPUT_FMT_DECL( signed long int ) 491 INPUT_FMT_DECL( unsigned long int ) 492 INPUT_FMT_DECL( signed long long int ) 493 INPUT_FMT_DECL( unsigned long long int ) 494 495 INPUT_FMT_DECL( float ) 496 INPUT_FMT_DECL( double ) 497 INPUT_FMT_DECL( long double ) 498 499 INPUT_FMT_DECL( float _Complex ) 500 INPUT_FMT_DECL( double _Complex ) 501 INPUT_FMT_DECL( long double _Complex ) 468 502 469 503 // *********************************** time *********************************** 470 471 504 472 505 #include <time_t.hfa> // Duration (constructors) / Time (constructors) … … 474 507 forall( ostype & | ostream( ostype ) ) { 475 508 ostype & ?|?( ostype & os, Duration dur ); 476 void ?|?( ostype & os, Duration dur);509 OSTYPE_VOID( Duration ); 477 510 ostype & ?|?( ostype & os, Time time ); 478 void ?|?( ostype & os, Time time );511 OSTYPE_VOID( Time ); 479 512 } // distribution 480 513
Note:
See TracChangeset
for help on using the changeset viewer.