Changes in libcfa/src/iostream.cfa [200fcb3:084520f]
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r200fcb3 r084520f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:02:03201813 // Update Count : 54612 // Last Modified On : Wed Sep 26 18:22:57 2018 13 // Update Count : 474 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))); … … 32 32 return os; 33 33 } // ?|? 34 void ?|?( ostype & os, bool b ) { 35 (ostype)(os | b); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) 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); if ( getANL( os ) ) nl( os ); 260 } // ?|? 202 261 203 262 204 // manipulators 263 205 ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 264 (ostype)(manip( os )); 265 setNonl( os, false ); // ignore nonl in middle 266 return os; 267 } // ?|? 268 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 269 (ostype)(manip( os )); 270 if ( getANL( os ) && ! getNonl( os ) ) nl( os ); // ignore nl if nonl at end 271 setNonl( os, false ); 206 return manip( os ); 272 207 } // ?|? 273 208 274 209 ostype & sep( ostype & os ) { 275 return (ostype)(os | sepGet( os )); 210 os | sepGet( os ); 211 return os; 276 212 } // sep 277 213 278 214 ostype & sepTuple( ostype & os ) { 279 return os | sepGetTuple( os ); 215 os | sepGetTuple( os ); 216 return os; 280 217 } // sepTuple 281 218 282 ostype & nl( ostype & os ) {283 (ostype)(os | '\n');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 ostype & nonl( ostype & os ) { 290 setNonl( os, true ); // indicate nonl manipulator 291 return os; 292 } // nonl 223 sepOff( os ); // prepare for next line 224 return os; 225 } // endl 293 226 294 227 ostype & sepOn( ostype & os ) { 295 sepOn( os ); // call void returning228 sepOn( os ); 296 229 return os; 297 230 } // sepOn 298 231 299 232 ostype & sepOff( ostype & os ) { 300 sepOff( os ); // call void returning233 sepOff( os ); 301 234 return os; 302 235 } // sepOff 303 236 304 237 ostype & sepEnable( ostype & os ) { 305 sepEnable( os ); // call void returning238 sepEnable( os ); 306 239 return os; 307 240 } // sepEnable 308 241 309 242 ostype & sepDisable( ostype & os ) { 310 sepDisable( os ); // call void returning243 sepDisable( os ); 311 244 return os; 312 245 } // sepDisable 313 314 ostype & nlOn( ostype & os ) {315 nlOn( os ); // call void returning316 return os;317 } // nlOn318 319 ostype & nlOff( ostype & os ) {320 nlOff( os ); // call void returning321 return os;322 } // nlOff323 246 } // distribution 324 247 248 325 249 // tuples 326 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { 327 ostype & ?|?( ostype & os, T arg, Params rest ) { 328 (ostype)(os | arg); // print first argument 329 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 330 (ostype)(os | rest); // print remaining arguments 331 sepSetCur( os, sepGet( os ) ); // switch to regular separator 332 return os; 333 } // ?|? 334 void ?|?( ostype & os, T arg, Params rest ) { 335 // (ostype)(?|?( os, arg, rest )); if ( getANL( os ) ) nl( os ); 336 (ostype)(os | arg); // print first argument 337 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 338 (ostype)(os | rest); // print remaining arguments 339 sepSetCur( os, sepGet( os ) ); // switch to regular separator 340 if ( getANL( os ) ) nl( os ); 341 } // ?|? 342 } // 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 } // ?|? 343 258 344 259 //--------------------------------------- 345 260 346 261 // writes the range [begin, end) to the given stream 347 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {348 void write( iterator_type begin, iterator_type end, ostype & os ) {349 void print( elt_type i ) { os | i; }350 for_each( begin, end, print );351 } // ?|?352 353 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { 354 void print( elt_type i ) { os | i; } 355 for_each_reverse( begin, end, print );356 } // ?|?357 } // 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 } // ?|? 358 273 359 274 //--------------------------------------- … … 471 386 } // ?|? 472 387 473 istype & nl( istype & is ) {388 istype & endl( istype & is ) { 474 389 fmt( is, "%*[ \t\f\n\r\v]" ); // ignore whitespace 475 390 return is; 476 } // nl391 } // endl 477 392 } // distribution 478 393
Note:
See TracChangeset
for help on using the changeset viewer.