Changes in libcfa/src/iostream.cfa [9d362a0:58b6d1b]
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r9d362a0 r58b6d1b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 24 18:33:40201813 // Update Count : 58912 // Last Modified On : Sat Jun 2 08:24:56 2018 13 // Update Count : 471 14 14 // 15 15 … … 19 19 #include <stdio.h> 20 20 #include <stdbool.h> // true/false 21 //#include <string.h> // strlen, strcmp21 //#include <string.h> // strlen, strcmp 22 22 extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); 23 23 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); … … 27 27 28 28 forall( dtype ostype | ostream( ostype ) ) { 29 ostype & ?|?( ostype & os, bool b ) {29 ostype & ?|?( ostype & os, _Bool b ) { 30 30 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 31 31 fmt( os, "%s", b ? "true" : "false" ); 32 32 return os; 33 33 } // ?|? 34 void ?|?( ostype & os, bool b ) { 35 (ostype &)(os | b); nl( os ); 36 } // ?|? 37 38 ostype & ?|?( ostype & os, char c ) { 39 fmt( os, "%c", c ); 40 if ( c == '\n' ) setNL( os, true ); 41 return sepOff( os ); 42 } // ?|? 43 void ?|?( ostype & os, char c ) { 44 (ostype &)(os | c); nl( os ); 45 } // ?|? 46 47 ostype & ?|?( ostype & os, signed char sc ) { 48 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 49 fmt( os, "%hhd", sc ); 50 return os; 51 } // ?|? 52 void ?|?( ostype & os, signed char sc ) { 53 (ostype &)(os | sc); nl( os ); 54 } // ?|? 55 56 ostype & ?|?( ostype & os, unsigned char usc ) { 57 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 58 fmt( os, "%hhu", usc ); 59 return os; 60 } // ?|? 61 void ?|?( ostype & os, unsigned char usc ) { 62 (ostype &)(os | usc); nl( os ); 34 35 ostype & ?|?( ostype & os, char ch ) { 36 fmt( os, "%c", ch ); 37 if ( ch == '\n' ) setNL( os, true ); 38 sepOff( os ); 39 return os; 40 } // ?|? 41 42 ostype & ?|?( ostype & os, signed char c ) { 43 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 44 fmt( os, "%hhd", c ); 45 return os; 46 } // ?|? 47 48 ostype & ?|?( ostype & os, unsigned char c ) { 49 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 50 fmt( os, "%hhu", c ); 51 return os; 63 52 } // ?|? 64 53 … … 68 57 return os; 69 58 } // ?|? 70 void & ?|?( ostype & os, short int si ) {71 (ostype &)(os | si); nl( os );72 } // ?|?73 59 74 60 ostype & ?|?( ostype & os, unsigned short int usi ) { … … 77 63 return os; 78 64 } // ?|? 79 void & ?|?( ostype & os, unsigned short int usi ) {80 (ostype &)(os | usi); nl( os );81 } // ?|?82 65 83 66 ostype & ?|?( ostype & os, int i ) { … … 86 69 return os; 87 70 } // ?|? 88 void & ?|?( ostype & os, int i ) {89 (ostype &)(os | i); nl( os );90 } // ?|?91 71 92 72 ostype & ?|?( ostype & os, unsigned int ui ) { … … 95 75 return os; 96 76 } // ?|? 97 void & ?|?( ostype & os, unsigned int ui ) {98 (ostype &)(os | ui); nl( os );99 } // ?|?100 77 101 78 ostype & ?|?( ostype & os, long int li ) { … … 104 81 return os; 105 82 } // ?|? 106 void & ?|?( ostype & os, long int li ) {107 (ostype &)(os | li); nl( os );108 } // ?|?109 83 110 84 ostype & ?|?( ostype & os, unsigned long int uli ) { … … 113 87 return os; 114 88 } // ?|? 115 void & ?|?( ostype & os, unsigned long int uli ) {116 (ostype &)(os | uli); nl( os );117 } // ?|?118 89 119 90 ostype & ?|?( ostype & os, long long int lli ) { … … 122 93 return os; 123 94 } // ?|? 124 void & ?|?( ostype & os, long long int lli ) {125 (ostype &)(os | lli); nl( os );126 } // ?|?127 95 128 96 ostype & ?|?( ostype & os, unsigned long long int ulli ) { … … 131 99 return os; 132 100 } // ?|? 133 void & ?|?( ostype & os, unsigned long long int ulli ) {134 (ostype &)(os | ulli); nl( os );135 } // ?|?136 101 137 102 ostype & ?|?( ostype & os, float f ) { … … 140 105 return os; 141 106 } // ?|? 142 void & ?|?( ostype & os, float f ) {143 (ostype &)(os | f); nl( os );144 } // ?|?145 107 146 108 ostype & ?|?( ostype & os, double d ) { … … 149 111 return os; 150 112 } // ?|? 151 void & ?|?( ostype & os, double d ) {152 (ostype &)(os | d); nl( os );153 } // ?|?154 113 155 114 ostype & ?|?( ostype & os, long double ld ) { … … 158 117 return os; 159 118 } // ?|? 160 void & ?|?( ostype & os, long double ld ) {161 (ostype &)(os | ld); nl( os );162 } // ?|?163 119 164 120 ostype & ?|?( ostype & os, float _Complex fc ) { … … 167 123 return os; 168 124 } // ?|? 169 void & ?|?( ostype & os, float _Complex fc ) {170 (ostype &)(os | fc); nl( os );171 } // ?|?172 125 173 126 ostype & ?|?( ostype & os, double _Complex dc ) { … … 176 129 return os; 177 130 } // ?|? 178 void & ?|?( ostype & os, double _Complex dc ) {179 (ostype &)(os | dc); nl( os );180 } // ?|?181 131 182 132 ostype & ?|?( ostype & os, long double _Complex ldc ) { … … 184 134 fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) ); 185 135 return os; 186 } // ?|?187 void & ?|?( ostype & os, long double _Complex ldc ) {188 (ostype &)(os | ldc); nl( os );189 136 } // ?|? 190 137 … … 227 174 return write( os, str, len ); 228 175 } // ?|? 229 void ?|?( ostype & os, const char * str ) {230 (ostype &)(os | str); nl( os );231 } // ?|?232 176 233 177 // ostype & ?|?( ostype & os, const char16_t * str ) { … … 256 200 return os; 257 201 } // ?|? 258 void ?|?( ostype & os, const void * p ) { 259 (ostype &)(os | p); nl( os ); 260 } // ?|? 202 261 203 262 204 // manipulators 263 205 ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 264 (ostype &)(manip( os )); 265 return os; 266 } // ?|? 267 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 268 (ostype &)(manip( os )); 269 if ( getPrt( os ) ) nl( os ); // something printed ? 270 setPrt( os, false ); // turn off 206 return manip( os ); 271 207 } // ?|? 272 208 273 209 ostype & sep( ostype & os ) { 274 return (ostype &)(os | sepGet( os )); 210 os | sepGet( os ); 211 return os; 275 212 } // sep 276 213 277 214 ostype & sepTuple( ostype & os ) { 278 return os | sepGetTuple( os ); 215 os | sepGetTuple( os ); 216 return os; 279 217 } // sepTuple 280 218 281 ostype & nl( ostype & os ) { 282 (ostype &)(os | '\n'); 283 setPrt( os, false ); // turn off 219 ostype & endl( ostype & os ) { 220 os | '\n'; 284 221 setNL( os, true ); 285 222 flush( os ); 286 return sepOff( os ); // prepare for next line 287 } // nl 288 289 void nl( ostype & os ) { 290 if ( getANL( os ) ) (ostype &)(nl( os )); // implementation only 291 else setPrt( os, false ); // turn off 292 } // nl 293 294 ostype & nonl( ostype & os ) { 295 setPrt( os, false ); // turn off 296 return os; 297 } // nonl 223 sepOff( os ); // prepare for next line 224 return os; 225 } // endl 298 226 299 227 ostype & sepOn( ostype & os ) { 300 sepOn( os ); // call void returning228 sepOn( os ); 301 229 return os; 302 230 } // sepOn 303 231 304 232 ostype & sepOff( ostype & os ) { 305 sepOff( os ); // call void returning233 sepOff( os ); 306 234 return os; 307 235 } // sepOff 308 236 309 237 ostype & sepEnable( ostype & os ) { 310 sepEnable( os ); // call void returning238 sepEnable( os ); 311 239 return os; 312 240 } // sepEnable 313 241 314 242 ostype & sepDisable( ostype & os ) { 315 sepDisable( os ); // call void returning243 sepDisable( os ); 316 244 return os; 317 245 } // sepDisable 318 319 ostype & nlOn( ostype & os ) {320 nlOn( os ); // call void returning321 return os;322 } // nlOn323 324 ostype & nlOff( ostype & os ) {325 nlOff( os ); // call void returning326 return os;327 } // nlOff328 246 } // distribution 329 247 248 330 249 // tuples 331 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 332 ostype & ?|?( ostype & os, T arg, Params rest ) { 333 (ostype &)(os | arg); // print first argument 334 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 335 (ostype &)(os | rest); // print remaining arguments 336 sepSetCur( os, sepGet( os ) ); // switch to regular separator 337 return os; 338 } // ?|? 339 void ?|?( ostype & os, T arg, Params rest ) { 340 // (ostype &)(?|?( os, arg, rest )); nl( os ); 341 (ostype &)(os | arg); // print first argument 342 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 343 (ostype &)(os | rest); // print remaining arguments 344 sepSetCur( os, sepGet( os ) ); // switch to regular separator 345 nl( os ); 346 } // ?|? 347 } // distribution 250 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) 251 ostype & ?|?( ostype & os, T arg, Params rest ) { 252 os | arg; // print first argument 253 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 254 os | rest; // print remaining arguments 255 sepSetCur( os, sepGet( os ) ); // switch to regular separator 256 return os; 257 } // ?|? 348 258 349 259 //--------------------------------------- 350 260 351 261 // writes the range [begin, end) to the given stream 352 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {353 void write( iterator_type begin, iterator_type end, ostype & os ) {354 void print( elt_type i ) { os | i; }355 for_each( begin, end, print );356 } // ?|?357 358 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { 359 void print( elt_type i ) { os | i; } 360 for_each_reverse( begin, end, print );361 } // ?|?362 } // distribution262 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 263 void write( iterator_type begin, iterator_type end, ostype & os ) { 264 void print( elt_type i ) { os | i; } 265 for_each( begin, end, print ); 266 } // ?|? 267 268 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 269 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { 270 void print( elt_type i ) { os | i; } 271 for_each_reverse( begin, end, print ); 272 } // ?|? 363 273 364 274 //--------------------------------------- 365 275 366 276 forall( dtype istype | istream( istype ) ) { 367 istype & ?|?( istype & is, bool & b ) {277 istype & ?|?( istype & is, _Bool & b ) { 368 278 char val[6]; 369 279 fmt( is, "%5s", val ); … … 371 281 else if ( strcmp( val, "false" ) == 0 ) b = false; 372 282 else { 373 fprintf( stderr, "invalid Booleanconstant\n" );283 fprintf( stderr, "invalid _Bool constant\n" ); 374 284 abort(); 375 285 } // if … … 476 386 } // ?|? 477 387 478 istype & nl( istype & is ) {388 istype & endl( istype & is ) { 479 389 fmt( is, "%*[ \t\f\n\r\v]" ); // ignore whitespace 480 390 return is; 481 } // nl391 } // endl 482 392 } // distribution 483 393 … … 500 410 // Local Variables: // 501 411 // tab-width: 4 // 502 // compile-command: "cfa iostream.c fa" //412 // compile-command: "cfa iostream.c" // 503 413 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.