Changes in libcfa/src/iostream.hfa [ef3ac46:1adab3e]
- File:
-
- 1 edited
-
libcfa/src/iostream.hfa (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.hfa
ref3ac46 r1adab3e 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 pr 27 17:59:21 202113 // Update Count : 3 9812 // Last Modified On : Tue Aug 11 22:16:14 2020 13 // Update Count : 350 14 14 // 15 15 … … 22 22 23 23 24 trait basic_ostream( ostype & ) {24 trait 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 & ); // end of output statement 49 void ends( ostype & os ); // end of output statement 50 int fail( ostype & ); 51 int flush( ostype & ); 52 void open( ostype & os, const char name[], const char mode[] ); 53 void close( ostype & os ); 54 ostype & write( ostype &, const char [], size_t ); 50 55 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 51 }; // basic_ostream52 53 trait ostream( ostype & | basic_ostream( ostype ) ) {54 int flush( ostype & );55 bool fail( ostype & ); // operation failed?56 void open( ostype &, const char name[], const char mode[] );57 void close( ostype & );58 ostype & write( ostype &, const char [], size_t );59 void acquire( ostype & ); // concurrent access60 56 }; // ostream 61 57 … … 70 66 // implement writable for intrinsic types 71 67 72 forall( ostype & | basic_ostream( ostype ) ) {68 forall( ostype & | ostream( ostype ) ) { 73 69 ostype & ?|?( ostype &, bool ); 74 70 void ?|?( ostype &, bool ); … … 97 93 ostype & ?|?( ostype &, unsigned long long int ); 98 94 void ?|?( ostype &, unsigned long long int ); 99 #if defined( __SIZEOF_INT128__ )95 #if defined( __SIZEOF_INT128__ ) 100 96 ostype & ?|?( ostype &, int128 ); 101 97 void ?|?( ostype &, int128 ); 102 98 ostype & ?|?( ostype &, unsigned int128 ); 103 99 void ?|?( ostype &, unsigned int128 ); 104 #endif // __SIZEOF_INT128__100 #endif // __SIZEOF_INT128__ 105 101 106 102 ostype & ?|?( ostype &, float ); … … 121 117 void ?|?( ostype &, const char [] ); 122 118 // ostype & ?|?( ostype &, const char16_t * ); 123 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous119 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous 124 120 // ostype & ?|?( ostype &, const char32_t * ); 125 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )121 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) 126 122 // ostype & ?|?( ostype &, const wchar_t * ); 127 123 ostype & ?|?( ostype &, const void * ); … … 143 139 } // distribution 144 140 145 forall( ostype & | ostream( ostype ) ) {146 ostype & acquire( ostype & );147 } // distribution148 149 141 // tuples 150 142 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { … … 164 156 struct _Ostream_Manip { 165 157 T val; // polymorphic base-type 166 int wd, pc; // width, precision: signed for computations158 unsigned int wd, pc; // width, precision 167 159 char base; // numeric base / floating-point style 168 160 union { 169 161 unsigned char all; 170 162 struct { 171 unsigned char eng:1; // engineering notation172 163 unsigned char neg:1; // val is negative 173 164 unsigned char pc:1; // precision specified … … 192 183 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \ 193 184 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \ 194 _Ostream_Manip(T) wd( unsigned int w, unsigned intpc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \185 _Ostream_Manip(T) wd( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \ 195 186 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 196 _Ostream_Manip(T) & wd( unsigned int w, unsigned intpc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \187 _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; } \ 197 188 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 198 189 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \ … … 202 193 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 203 194 } /* distribution */ \ 204 forall( ostype & | basic_ostream( ostype ) ) { \195 forall( ostype & | ostream( ostype ) ) { \ 205 196 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 206 197 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 229 220 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \ 230 221 _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \ 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; } \ 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; } \ 238 227 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 239 228 _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \ … … 244 233 _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \ 245 234 _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; } \248 235 } /* distribution */ \ 249 forall( ostype & | basic_ostream( ostype ) ) { \236 forall( ostype & | ostream( ostype ) ) { \ 250 237 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 251 238 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 267 254 _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 268 255 } // distribution 269 forall( ostype & | basic_ostream( ostype ) ) {256 forall( ostype & | ostream( ostype ) ) { 270 257 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 271 258 void ?|?( ostype & os, _Ostream_Manip(char) f ); … … 279 266 _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; } 280 267 _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; } 281 _Ostream_Manip(const char *) wd( unsigned int w, unsigned intpc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }268 _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 } }; } 282 269 _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; } 283 _Ostream_Manip(const char *) & wd( unsigned int w, unsigned intpc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }270 _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; } 284 271 _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; } 285 272 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 286 273 } // distribution 287 forall( ostype & | basic_ostream( ostype ) ) {274 forall( ostype & | ostream( ostype ) ) { 288 275 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 289 276 void ?|?( ostype & os, _Ostream_Manip(const char *) f ); … … 294 281 295 282 296 trait basic_istream( istype & ) { 297 bool getANL( istype & ); // get scan newline (on/off) 283 trait istream( istype & ) { 298 284 void nlOn( istype & ); // read newline 299 285 void nlOff( istype & ); // scan newline 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 ); 286 bool getANL( istype & ); // get scan newline (on/off) 287 int fail( istype & ); 304 288 int eof( istype & ); 305 }; // basic_istream306 307 trait istream( istype & | basic_istream( istype ) ) {308 bool fail( istype & );309 289 void open( istype & is, const char name[] ); 310 290 void close( istype & is ); 311 291 istype & read( istype &, char *, size_t ); 312 void acquire( istype & ); // concurrent access 292 istype & ungetc( istype &, char ); 293 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); 313 294 }; // istream 314 295 … … 317 298 }; // readable 318 299 319 forall( istype & | basic_istream( istype ) ) {300 forall( istype & | istream( istype ) ) { 320 301 istype & ?|?( istype &, bool & ); 321 void ?|?( istype &, bool & );322 302 323 303 istype & ?|?( istype &, char & ); 324 void ?|?( istype &, char & );325 304 istype & ?|?( istype &, signed char & ); 326 void ?|?( istype &, signed char & );327 305 istype & ?|?( istype &, unsigned char & ); 328 void ?|?( istype &, unsigned char & );329 306 330 307 istype & ?|?( istype &, short int & ); 331 void ?|?( istype &, short int & );332 308 istype & ?|?( istype &, unsigned short int & ); 333 void ?|?( istype &, unsigned short int & );334 309 istype & ?|?( istype &, int & ); 335 void ?|?( istype &, int & );336 310 istype & ?|?( istype &, unsigned int & ); 337 void ?|?( istype &, unsigned int & );338 311 istype & ?|?( istype &, long int & ); 339 void ?|?( istype &, long int & );340 312 istype & ?|?( istype &, unsigned long int & ); 341 void ?|?( istype &, unsigned long int & );342 313 istype & ?|?( istype &, long long int & ); 343 void ?|?( istype &, long long int & );344 314 istype & ?|?( istype &, unsigned long long int & ); 345 void ?|?( istype &, unsigned long long int & ); 346 #if defined( __SIZEOF_INT128__ ) 315 #if defined( __SIZEOF_INT128__ ) 347 316 istype & ?|?( istype &, int128 & ); 348 void ?|?( istype &, int128 & );349 317 istype & ?|?( istype &, unsigned int128 & ); 350 void ?|?( istype &, unsigned int128 & ); 351 #endif // __SIZEOF_INT128__ 318 #endif // __SIZEOF_INT128__ 352 319 353 320 istype & ?|?( istype &, float & ); 354 void ?|?( istype &, float & );355 321 istype & ?|?( istype &, double & ); 356 void ?|?( istype &, double & );357 322 istype & ?|?( istype &, long double & ); 358 void ?|?( istype &, long double & );359 323 360 324 istype & ?|?( istype &, float _Complex & ); 361 void ?|?( istype &, float _Complex & );362 325 istype & ?|?( istype &, double _Complex & ); 363 void ?|?( istype &, double _Complex & );364 326 istype & ?|?( istype &, long double _Complex & ); 365 void ?|?( istype &, long double _Complex & );366 327 367 328 // istype & ?|?( istype &, const char [] ); 368 istype & ?|?( istype &, char [] ); 369 void ?|?( istype &, char [] ); 329 istype & ?|?( istype &, char * ); 370 330 371 331 // manipulators 372 332 istype & ?|?( istype &, istype & (*)( istype & ) ); 373 void ?|?( istype &, istype & (*)( istype & ) );374 333 istype & nl( istype & is ); 375 334 istype & nlOn( istype & ); 376 335 istype & nlOff( istype & ); 377 } // distribution378 379 forall( istype & | istream( istype ) ) {380 istype & acquire( istype & );381 336 } // distribution 382 337 … … 397 352 398 353 static inline { 354 _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; } 399 355 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; } 400 _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; }401 356 _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; } 402 357 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; } … … 408 363 _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; } 409 364 } // distribution 410 forall( istype & | basic_istream( istype ) ) { 411 istype & ?|?( istype & is, _Istream_Cstr f ); 412 void ?|?( istype & is, _Istream_Cstr f ); 413 } 365 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f ); 414 366 415 367 struct _Istream_Char { … … 421 373 _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; } 422 374 } // distribution 423 forall( istype & | basic_istream( istype ) ) { 424 istype & ?|?( istype & is, _Istream_Char f ); 425 void ?|?( istype & is, _Istream_Char f ); 426 } 375 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f ); 427 376 428 377 forall( T & | sized( T ) ) … … 440 389 _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 441 390 } /* distribution */ \ 442 forall( istype & | basic_istream( istype ) ) { \391 forall( istype & | istream( istype ) ) { \ 443 392 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 444 void ?|?( istype & is, _Istream_Manip(T) f ); \445 393 } // ?|? 446 394
Note:
See TracChangeset
for help on using the changeset viewer.