source: libcfa/src/iostream.cfa@ 1fb7bfd

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 1fb7bfd was 3c5dee4, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

change istype nl to ignore characters to newline, change ostype to print a decimal point for floating points

  • Property mode set to 100644
File size: 16.4 KB
RevLine 
[86bd7c1f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[a5a71d0]7// iostream.c --
[86bd7c1f]8//
[90c3b1c]9// Author : Peter A. Buhr
[86bd7c1f]10// Created On : Wed May 27 17:56:53 2015
[e24f13a]11// Last Modified By : Peter A. Buhr
[3c5dee4]12// Last Modified On : Mon May 13 12:46:45 2019
13// Update Count : 650
[86bd7c1f]14//
[51b73452]15
[58b6d1b]16#include "iostream.hfa"
[d3b7937]17
[51b73452]18extern "C" {
19#include <stdio.h>
[53a6c2a]20#include <stdbool.h> // true/false
[200fcb3]21//#include <string.h> // strlen, strcmp
[44574f2]22extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
23extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
[52f85e0]24#include <float.h> // DBL_DIG, LDBL_DIG
[3c5dee4]25#include <math.h> // modff, modf, modlf
[d3b7937]26#include <complex.h> // creal, cimag
[51b73452]27}
28
[3ce0d440]29forall( dtype ostype | ostream( ostype ) ) {
[17a1b21]30 ostype & ?|?( ostype & os, zero_t ) {
31 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
32 fmt( os, "%d", 0n );
33 return os;
34 } // ?|?
35 void ?|?( ostype & os, zero_t z ) {
36 (ostype &)(os | z); nl( os );
37 } // ?|?
38
39 ostype & ?|?( ostype & os, one_t ) {
40 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
41 fmt( os, "%d", 1n );
42 return os;
43 } // ?|?
44 void ?|?( ostype & os, one_t o ) {
45 (ostype &)(os | o); nl( os );
46 } // ?|?
47
[93c2e0a]48 ostype & ?|?( ostype & os, bool b ) {
[3ce0d440]49 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
50 fmt( os, "%s", b ? "true" : "false" );
51 return os;
52 } // ?|?
[200fcb3]53 void ?|?( ostype & os, bool b ) {
[9d362a0]54 (ostype &)(os | b); nl( os );
[200fcb3]55 } // ?|?
[51b73452]56
[200fcb3]57 ostype & ?|?( ostype & os, char c ) {
58 fmt( os, "%c", c );
59 if ( c == '\n' ) setNL( os, true );
60 return sepOff( os );
61 } // ?|?
62 void ?|?( ostype & os, char c ) {
[9d362a0]63 (ostype &)(os | c); nl( os );
[3ce0d440]64 } // ?|?
65
[200fcb3]66 ostype & ?|?( ostype & os, signed char sc ) {
[3ce0d440]67 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[200fcb3]68 fmt( os, "%hhd", sc );
[3ce0d440]69 return os;
70 } // ?|?
[200fcb3]71 void ?|?( ostype & os, signed char sc ) {
[9d362a0]72 (ostype &)(os | sc); nl( os );
[200fcb3]73 } // ?|?
[3ce0d440]74
[200fcb3]75 ostype & ?|?( ostype & os, unsigned char usc ) {
[3ce0d440]76 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[200fcb3]77 fmt( os, "%hhu", usc );
[3ce0d440]78 return os;
79 } // ?|?
[200fcb3]80 void ?|?( ostype & os, unsigned char usc ) {
[9d362a0]81 (ostype &)(os | usc); nl( os );
[200fcb3]82 } // ?|?
[3ce0d440]83
84 ostype & ?|?( ostype & os, short int si ) {
85 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
86 fmt( os, "%hd", si );
87 return os;
88 } // ?|?
[200fcb3]89 void & ?|?( ostype & os, short int si ) {
[9d362a0]90 (ostype &)(os | si); nl( os );
[200fcb3]91 } // ?|?
[3ce0d440]92
93 ostype & ?|?( ostype & os, unsigned short int usi ) {
94 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
95 fmt( os, "%hu", usi );
96 return os;
97 } // ?|?
[200fcb3]98 void & ?|?( ostype & os, unsigned short int usi ) {
[9d362a0]99 (ostype &)(os | usi); nl( os );
[200fcb3]100 } // ?|?
[3ce0d440]101
102 ostype & ?|?( ostype & os, int i ) {
103 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
104 fmt( os, "%d", i );
105 return os;
106 } // ?|?
[200fcb3]107 void & ?|?( ostype & os, int i ) {
[9d362a0]108 (ostype &)(os | i); nl( os );
[200fcb3]109 } // ?|?
[3ce0d440]110
111 ostype & ?|?( ostype & os, unsigned int ui ) {
112 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
113 fmt( os, "%u", ui );
114 return os;
115 } // ?|?
[200fcb3]116 void & ?|?( ostype & os, unsigned int ui ) {
[9d362a0]117 (ostype &)(os | ui); nl( os );
[200fcb3]118 } // ?|?
[3ce0d440]119
120 ostype & ?|?( ostype & os, long int li ) {
121 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
122 fmt( os, "%ld", li );
123 return os;
124 } // ?|?
[200fcb3]125 void & ?|?( ostype & os, long int li ) {
[9d362a0]126 (ostype &)(os | li); nl( os );
[200fcb3]127 } // ?|?
[3ce0d440]128
129 ostype & ?|?( ostype & os, unsigned long int uli ) {
130 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
131 fmt( os, "%lu", uli );
132 return os;
133 } // ?|?
[200fcb3]134 void & ?|?( ostype & os, unsigned long int uli ) {
[9d362a0]135 (ostype &)(os | uli); nl( os );
[200fcb3]136 } // ?|?
[3ce0d440]137
138 ostype & ?|?( ostype & os, long long int lli ) {
139 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
140 fmt( os, "%lld", lli );
141 return os;
142 } // ?|?
[200fcb3]143 void & ?|?( ostype & os, long long int lli ) {
[9d362a0]144 (ostype &)(os | lli); nl( os );
[200fcb3]145 } // ?|?
[3ce0d440]146
147 ostype & ?|?( ostype & os, unsigned long long int ulli ) {
148 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
149 fmt( os, "%llu", ulli );
150 return os;
151 } // ?|?
[200fcb3]152 void & ?|?( ostype & os, unsigned long long int ulli ) {
[9d362a0]153 (ostype &)(os | ulli); nl( os );
[200fcb3]154 } // ?|?
[3ce0d440]155
156 ostype & ?|?( ostype & os, float f ) {
157 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
158 fmt( os, "%g", f );
[3c5dee4]159 float tempi;
160 if ( isfinite( f ) && modff( f, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point
[3ce0d440]161 return os;
162 } // ?|?
[200fcb3]163 void & ?|?( ostype & os, float f ) {
[9d362a0]164 (ostype &)(os | f); nl( os );
[200fcb3]165 } // ?|?
[3ce0d440]166
167 ostype & ?|?( ostype & os, double d ) {
168 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
169 fmt( os, "%.*lg", DBL_DIG, d );
[3c5dee4]170 // fmt( os, "%lg", d );
171 double tempi;
172 if ( isfinite( d ) && modf( d, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point
[3ce0d440]173 return os;
174 } // ?|?
[200fcb3]175 void & ?|?( ostype & os, double d ) {
[9d362a0]176 (ostype &)(os | d); nl( os );
[200fcb3]177 } // ?|?
[3ce0d440]178
179 ostype & ?|?( ostype & os, long double ld ) {
180 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
181 fmt( os, "%.*Lg", LDBL_DIG, ld );
[3c5dee4]182 // fmt( os, "%Lg", ld );
183 long double tempi;
184 if ( isfinite( ld ) && modfl( ld, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point
[3ce0d440]185 return os;
186 } // ?|?
[200fcb3]187 void & ?|?( ostype & os, long double ld ) {
[9d362a0]188 (ostype &)(os | ld); nl( os );
[200fcb3]189 } // ?|?
[3ce0d440]190
191 ostype & ?|?( ostype & os, float _Complex fc ) {
192 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[3c5dee4]193 float temp = crealf( fc ), tempi;
194 fmt( os, "%g", temp );
195 if ( isfinite( temp ) && modff( temp, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point
196 temp = cimagf( fc );
197 fmt( os, "%+g", temp );
198 if ( isfinite( temp ) && modff( temp, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point
199 fmt( os, "i" );
[3ce0d440]200 return os;
201 } // ?|?
[200fcb3]202 void & ?|?( ostype & os, float _Complex fc ) {
[9d362a0]203 (ostype &)(os | fc); nl( os );
[200fcb3]204 } // ?|?
[3ce0d440]205
206 ostype & ?|?( ostype & os, double _Complex dc ) {
207 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[3c5dee4]208 double temp = creal( dc ), tempi;
209 fmt( os, "%.*lg", DBL_DIG, temp );
210 if ( isfinite( temp ) && modf( temp, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point
211 temp = cimag( dc );
212 fmt( os, "%+.*lg", DBL_DIG, temp );
213 if ( isfinite( temp ) && modf( temp, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point
214 fmt( os, "i" );
215 // fmt( os, "%lg%+lgi", creal( dc ), cimag( dc ) );
[3ce0d440]216 return os;
217 } // ?|?
[200fcb3]218 void & ?|?( ostype & os, double _Complex dc ) {
[9d362a0]219 (ostype &)(os | dc); nl( os );
[200fcb3]220 } // ?|?
[3ce0d440]221
222 ostype & ?|?( ostype & os, long double _Complex ldc ) {
223 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[3c5dee4]224 long double temp = creall( ldc ), tempi;
225 fmt( os, "%.*Lg", LDBL_DIG, temp );
226 if ( isfinite( temp ) && modfl( temp, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point
227 temp = cimagl( ldc );
228 fmt( os, "%+.*Lg", LDBL_DIG, cimagl( ldc ) );
229 if ( isfinite( temp ) && modfl( temp, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point
230 fmt( os, "i" );
231 // fmt( os, "%Lg%+Lgi", creall( ldc ), cimagl( ldc ) );
[3ce0d440]232 return os;
233 } // ?|?
[200fcb3]234 void & ?|?( ostype & os, long double _Complex ldc ) {
[9d362a0]235 (ostype &)(os | ldc); nl( os );
[200fcb3]236 } // ?|?
[3ce0d440]237
238 ostype & ?|?( ostype & os, const char * str ) {
239 enum { Open = 1, Close, OpenClose };
240 static const unsigned char mask[256] @= {
241 // opening delimiters, no space after
242 ['('] : Open, ['['] : Open, ['{'] : Open,
[ad72c8b]243 ['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
244 [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
[3ce0d440]245 // closing delimiters, no space before
246 [','] : Close, ['.'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
[ad72c8b]247 ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
[3ce0d440]248 [')'] : Close, [']'] : Close, ['}'] : Close,
249 // opening-closing delimiters, no space before or after
250 ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, [':'] : OpenClose,
251 [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
252 }; // mask
253
254 if ( str[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
255
256 // first character IS NOT spacing or closing punctuation => add left separator
257 unsigned char ch = str[0]; // must make unsigned
258 if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
259 fmt( os, "%s", sepGetCur( os ) );
260 } // if
261
262 // if string starts line, must reset to determine open state because separator is off
263 sepReset( os ); // reset separator
264
265 // last character IS spacing or opening punctuation => turn off separator for next item
266 size_t len = strlen( str );
267 ch = str[len - 1]; // must make unsigned
268 if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
269 sepOn( os );
270 } else {
271 sepOff( os );
272 } // if
273 if ( ch == '\n' ) setNL( os, true ); // check *AFTER* sepPrt call above as it resets NL flag
274 return write( os, str, len );
275 } // ?|?
[200fcb3]276 void ?|?( ostype & os, const char * str ) {
[9d362a0]277 (ostype &)(os | str); nl( os );
[200fcb3]278 } // ?|?
[3ce0d440]279
280// ostype & ?|?( ostype & os, const char16_t * str ) {
281// if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
282// fmt( os, "%ls", str );
283// return os;
284// } // ?|?
[d3b7937]285
[3ce0d440]286// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
287// ostype & ?|?( ostype & os, const char32_t * str ) {
288// if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
289// fmt( os, "%ls", str );
290// return os;
291// } // ?|?
292// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
[d3b7937]293
[3ce0d440]294// ostype & ?|?( ostype & os, const wchar_t * str ) {
295// if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
296// fmt( os, "%ls", str );
297// return os;
298// } // ?|?
299
300 ostype & ?|?( ostype & os, const void * p ) {
301 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
302 fmt( os, "%p", p );
303 return os;
304 } // ?|?
[200fcb3]305 void ?|?( ostype & os, const void * p ) {
[9d362a0]306 (ostype &)(os | p); nl( os );
[200fcb3]307 } // ?|?
[3ce0d440]308
309 // manipulators
310 ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
[9d362a0]311 (ostype &)(manip( os ));
[200fcb3]312 return os;
313 } // ?|?
314 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
[9d362a0]315 (ostype &)(manip( os ));
316 if ( getPrt( os ) ) nl( os ); // something printed ?
[5ea5b28]317 setPrt( os, false ); // turn off
[3ce0d440]318 } // ?|?
319
320 ostype & sep( ostype & os ) {
[9d362a0]321 return (ostype &)(os | sepGet( os ));
[3ce0d440]322 } // sep
323
324 ostype & sepTuple( ostype & os ) {
[200fcb3]325 return os | sepGetTuple( os );
[3ce0d440]326 } // sepTuple
327
[200fcb3]328 ostype & nl( ostype & os ) {
[9d362a0]329 (ostype &)(os | '\n');
[5ea5b28]330 setPrt( os, false ); // turn off
[3ce0d440]331 setNL( os, true );
332 flush( os );
[200fcb3]333 return sepOff( os ); // prepare for next line
334 } // nl
335
[9d362a0]336 void nl( ostype & os ) {
337 if ( getANL( os ) ) (ostype &)(nl( os )); // implementation only
338 else setPrt( os, false ); // turn off
339 } // nl
340
[200fcb3]341 ostype & nonl( ostype & os ) {
[5ea5b28]342 setPrt( os, false ); // turn off
[3ce0d440]343 return os;
[200fcb3]344 } // nonl
[3ce0d440]345
346 ostype & sepOn( ostype & os ) {
[200fcb3]347 sepOn( os ); // call void returning
[3ce0d440]348 return os;
349 } // sepOn
350
351 ostype & sepOff( ostype & os ) {
[200fcb3]352 sepOff( os ); // call void returning
[3ce0d440]353 return os;
354 } // sepOff
[6de9f4a]355
[3ce0d440]356 ostype & sepEnable( ostype & os ) {
[200fcb3]357 sepEnable( os ); // call void returning
[3ce0d440]358 return os;
359 } // sepEnable
[b6dc097]360
[3ce0d440]361 ostype & sepDisable( ostype & os ) {
[200fcb3]362 sepDisable( os ); // call void returning
[3ce0d440]363 return os;
364 } // sepDisable
[cf16f94]365
[200fcb3]366 ostype & nlOn( ostype & os ) {
367 nlOn( os ); // call void returning
368 return os;
369 } // nlOn
370
371 ostype & nlOff( ostype & os ) {
372 nlOff( os ); // call void returning
373 return os;
374 } // nlOff
375} // distribution
[cf16f94]376
[c443d1d]377// tuples
[200fcb3]378forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
379 ostype & ?|?( ostype & os, T arg, Params rest ) {
[9d362a0]380 (ostype &)(os | arg); // print first argument
[200fcb3]381 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator
[9d362a0]382 (ostype &)(os | rest); // print remaining arguments
[200fcb3]383 sepSetCur( os, sepGet( os ) ); // switch to regular separator
384 return os;
385 } // ?|?
386 void ?|?( ostype & os, T arg, Params rest ) {
[9d362a0]387 // (ostype &)(?|?( os, arg, rest )); nl( os );
388 (ostype &)(os | arg); // print first argument
[200fcb3]389 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator
[9d362a0]390 (ostype &)(os | rest); // print remaining arguments
[200fcb3]391 sepSetCur( os, sepGet( os ) ); // switch to regular separator
[9d362a0]392 nl( os );
[200fcb3]393 } // ?|?
394} // distribution
[c443d1d]395
[6ba0659]396//---------------------------------------
397
[3ce0d440]398// writes the range [begin, end) to the given stream
[200fcb3]399forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
400 void write( iterator_type begin, iterator_type end, ostype & os ) {
401 void print( elt_type i ) { os | i; }
402 for_each( begin, end, print );
403 } // ?|?
404
405 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
406 void print( elt_type i ) { os | i; }
407 for_each_reverse( begin, end, print );
408 } // ?|?
409} // distribution
[e56cfdb0]410
[6ba0659]411//---------------------------------------
[e56cfdb0]412
[3ce0d440]413forall( dtype istype | istream( istype ) ) {
[93c2e0a]414 istype & ?|?( istype & is, bool & b ) {
[3ce0d440]415 char val[6];
416 fmt( is, "%5s", val );
417 if ( strcmp( val, "true" ) == 0 ) b = true;
418 else if ( strcmp( val, "false" ) == 0 ) b = false;
419 else {
[93c2e0a]420 fprintf( stderr, "invalid Boolean constant\n" );
[3ce0d440]421 abort();
422 } // if
423 return is;
424 } // ?|?
425
426 istype & ?|?( istype & is, char & c ) {
[0efb269]427 char temp;
428 for () {
429 fmt( is, "%c", &temp ); // must pass pointer through varg to fmt
430 // do not overwrite parameter with newline unless appropriate
431 if ( temp != '\n' || getANL( is ) ) { c = temp; break; }
432 if ( eof( is ) ) break;
433 } // for
[3ce0d440]434 return is;
435 } // ?|?
436
437 istype & ?|?( istype & is, signed char & sc ) {
438 fmt( is, "%hhd", &sc );
439 return is;
440 } // ?|?
441
442 istype & ?|?( istype & is, unsigned char & usc ) {
443 fmt( is, "%hhu", &usc );
444 return is;
445 } // ?|?
446
447 istype & ?|?( istype & is, short int & si ) {
448 fmt( is, "%hd", &si );
449 return is;
450 } // ?|?
451
452 istype & ?|?( istype & is, unsigned short int & usi ) {
453 fmt( is, "%hu", &usi );
454 return is;
455 } // ?|?
456
457 istype & ?|?( istype & is, int & i ) {
458 fmt( is, "%d", &i );
459 return is;
460 } // ?|?
461
462 istype & ?|?( istype & is, unsigned int & ui ) {
463 fmt( is, "%u", &ui );
464 return is;
465 } // ?|?
466
467 istype & ?|?( istype & is, long int & li ) {
468 fmt( is, "%ld", &li );
469 return is;
470 } // ?|?
471
472 istype & ?|?( istype & is, unsigned long int & ulli ) {
473 fmt( is, "%lu", &ulli );
474 return is;
475 } // ?|?
476
477 istype & ?|?( istype & is, long long int & lli ) {
478 fmt( is, "%lld", &lli );
479 return is;
480 } // ?|?
481
482 istype & ?|?( istype & is, unsigned long long int & ulli ) {
483 fmt( is, "%llu", &ulli );
484 return is;
485 } // ?|?
486
487
488 istype & ?|?( istype & is, float & f ) {
489 fmt( is, "%f", &f );
490 return is;
491 } // ?|?
492
493 istype & ?|?( istype & is, double & d ) {
494 fmt( is, "%lf", &d );
495 return is;
496 } // ?|?
497
498 istype & ?|?( istype & is, long double & ld ) {
499 fmt( is, "%Lf", &ld );
500 return is;
501 } // ?|?
502
503
504 istype & ?|?( istype & is, float _Complex & fc ) {
505 float re, im;
506 fmt( is, "%g%gi", &re, &im );
507 fc = re + im * _Complex_I;
508 return is;
509 } // ?|?
510
511 istype & ?|?( istype & is, double _Complex & dc ) {
512 double re, im;
513 fmt( is, "%lf%lfi", &re, &im );
514 dc = re + im * _Complex_I;
515 return is;
516 } // ?|?
517
518 istype & ?|?( istype & is, long double _Complex & ldc ) {
519 long double re, im;
520 fmt( is, "%Lf%Lfi", &re, &im );
521 ldc = re + im * _Complex_I;
522 return is;
523 } // ?|?
524
525 // manipulators
526 istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
527 return manip( is );
528 } // ?|?
529
[200fcb3]530 istype & nl( istype & is ) {
[3c5dee4]531 fmt( is, "%*[^\n]" ); // ignore characters to newline
[3ce0d440]532 return is;
[200fcb3]533 } // nl
[0efb269]534
535 istype & nlOn( istype & is ) {
536 nlOn( is ); // call void returning
537 return is;
538 } // nlOn
539
540 istype & nlOff( istype & is ) {
541 nlOff( is ); // call void returning
542 return is;
543 } // nlOff
[3ce0d440]544} // distribution
[44574f2]545
[e24f13a]546_Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; }
[90c3b1c]547forall( dtype istype | istream( istype ) )
[09687aa]548istype & ?|?( istype & is, _Istream_cstrUC cstr ) {
[829c907]549 fmt( is, "%s", cstr.s );
[90c3b1c]550 return is;
[53ba273]551} // cstr
[90c3b1c]552
[e24f13a]553_Istream_cstrC cstr( char * str, int size ) { return (_Istream_cstrC){ str, size }; }
[90c3b1c]554forall( dtype istype | istream( istype ) )
[09687aa]555istype & ?|?( istype & is, _Istream_cstrC cstr ) {
[90c3b1c]556 char buf[16];
[53ba273]557 sprintf( buf, "%%%ds", cstr.size );
[829c907]558 fmt( is, buf, cstr.s );
[90c3b1c]559 return is;
[53ba273]560} // cstr
[90c3b1c]561
[86bd7c1f]562// Local Variables: //
563// tab-width: 4 //
[084520f]564// compile-command: "cfa iostream.cfa" //
[86bd7c1f]565// End: //
Note: See TracBrowser for help on using the repository browser.