source: libcfa/src/iostream.cfa @ b2ac656

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since b2ac656 was b2ac656, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

fix decimal print for floating point

  • Property mode set to 100644
File size: 16.6 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
[b2ac656]12// Last Modified On : Sun May 19 10:48:27 2019
13// Update Count     : 654
[86bd7c1f]14//
[51b7345]15
[58b6d1b]16#include "iostream.hfa"
[d3b7937]17
[51b7345]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
[b2ac656]25#include <math.h>                                                                               // isfinite
[d3b7937]26#include <complex.h>                                                                    // creal, cimag
[51b7345]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        } // ?|?
[51b7345]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
[b2ac656]156        static void checkDecPt( ostype & os, const char * buf, int len ) {
157                for ( int i = 0;; i += 1 ) {
158                        if ( i == len ) { fmt( os, "." ); break; }
159                        if ( buf[i] == '.' ) break;
160                } // for
161        } // checkDecPt
162
[3ce0d440]163        ostype & ?|?( ostype & os, float f ) {
164                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[b2ac656]165                char buf[48];
166                int len = snprintf( buf, 48, "%g", f );
167                fmt( os, "%s", buf );
168                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
[3ce0d440]169                return os;
170        } // ?|?
[200fcb3]171        void & ?|?( ostype & os, float f ) {
[9d362a0]172                (ostype &)(os | f); nl( os );
[200fcb3]173        } // ?|?
[3ce0d440]174
175        ostype & ?|?( ostype & os, double d ) {
176                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[b2ac656]177                char buf[48];
178                int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d );
179                fmt( os, "%s", buf );
180                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
[3ce0d440]181                return os;
182        } // ?|?
[200fcb3]183        void & ?|?( ostype & os, double d ) {
[9d362a0]184                (ostype &)(os | d); nl( os );
[200fcb3]185        } // ?|?
[3ce0d440]186
187        ostype & ?|?( ostype & os, long double ld ) {
188                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[b2ac656]189                char buf[48];
190                int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld );
191                fmt( os, "%s", buf );
192                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
[3ce0d440]193                return os;
194        } // ?|?
[200fcb3]195        void & ?|?( ostype & os, long double ld ) {
[9d362a0]196                (ostype &)(os | ld); nl( os );
[200fcb3]197        } // ?|?
[3ce0d440]198
199        ostype & ?|?( ostype & os, float _Complex fc ) {
200                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[b2ac656]201//              os | crealf( fc ) | nonl;
202                float f = crealf( fc );
203                char buf[48];
204                int len = snprintf( buf, 48, "%g", f );
205                fmt( os, "%s", buf );
206                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
207                f = cimagf( fc );
208                len = snprintf( buf, 48, "%+g", f );
209                fmt( os, "%s", buf );
210                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
[3c5dee4]211                fmt( os, "i" );
[3ce0d440]212                return os;
213        } // ?|?
[200fcb3]214        void & ?|?( ostype & os, float _Complex fc ) {
[9d362a0]215                (ostype &)(os | fc); nl( os );
[200fcb3]216        } // ?|?
[3ce0d440]217
218        ostype & ?|?( ostype & os, double _Complex dc ) {
219                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[b2ac656]220//              os | creal( dc ) | nonl;
221                double d = creal( dc );
222                char buf[48];
223                int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d );
224                fmt( os, "%s", buf );
225                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
226                d = cimag( dc );
227                len = snprintf( buf, 48, "%+.*lg", DBL_DIG, d );
228                fmt( os, "%s", buf );
229                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
[3c5dee4]230                fmt( os, "i" );
[3ce0d440]231                return os;
232        } // ?|?
[200fcb3]233        void & ?|?( ostype & os, double _Complex dc ) {
[9d362a0]234                (ostype &)(os | dc); nl( os );
[200fcb3]235        } // ?|?
[3ce0d440]236
237        ostype & ?|?( ostype & os, long double _Complex ldc ) {
238                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
[b2ac656]239//              os | creall( ldc ) || nonl;
240                long double ld = creall( ldc );
241                char buf[48];
242                int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld );
243                fmt( os, "%s", buf );
244                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
245                ld = cimagl( ldc );
246                len = snprintf( buf, 48, "%+.*Lg", LDBL_DIG, ld );
247                fmt( os, "%s", buf );
248                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
[3c5dee4]249                fmt( os, "i" );
[3ce0d440]250                return os;
251        } // ?|?
[200fcb3]252        void & ?|?( ostype & os, long double _Complex ldc ) {
[9d362a0]253                (ostype &)(os | ldc); nl( os );
[200fcb3]254        } // ?|?
[3ce0d440]255
256        ostype & ?|?( ostype & os, const char * str ) {
257                enum { Open = 1, Close, OpenClose };
258                static const unsigned char mask[256] @= {
259                        // opening delimiters, no space after
260                        ['('] : Open, ['['] : Open, ['{'] : Open,
[ad72c8b]261                        ['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
262                        [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
[3ce0d440]263                        // closing delimiters, no space before
264                        [','] : Close, ['.'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
[ad72c8b]265                        ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
[3ce0d440]266                        [')'] : Close, [']'] : Close, ['}'] : Close,
267                        // opening-closing delimiters, no space before or after
268                        ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, [':'] : OpenClose,
269                        [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
270                }; // mask
271
272          if ( str[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
273
274                // first character IS NOT spacing or closing punctuation => add left separator
275                unsigned char ch = str[0];                                              // must make unsigned
276                if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
277                        fmt( os, "%s", sepGetCur( os ) );
278                } // if
279
280                // if string starts line, must reset to determine open state because separator is off
281                sepReset( os );                                                                 // reset separator
282
283                // last character IS spacing or opening punctuation => turn off separator for next item
284                size_t len = strlen( str );
285                ch = str[len - 1];                                                              // must make unsigned
286                if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
287                        sepOn( os );
288                } else {
289                        sepOff( os );
290                } // if
291                if ( ch == '\n' ) setNL( os, true );                    // check *AFTER* sepPrt call above as it resets NL flag
292                return write( os, str, len );
293        } // ?|?
[200fcb3]294        void ?|?( ostype & os, const char * str ) {
[9d362a0]295                (ostype &)(os | str); nl( os );
[200fcb3]296        } // ?|?
[3ce0d440]297
298//      ostype & ?|?( ostype & os, const char16_t * str ) {
299//              if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
300//              fmt( os, "%ls", str );
301//              return os;
302//      } // ?|?
[d3b7937]303
[3ce0d440]304// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
305//      ostype & ?|?( ostype & os, const char32_t * str ) {
306//              if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
307//              fmt( os, "%ls", str );
308//              return os;
309//      } // ?|?
310// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
[d3b7937]311
[3ce0d440]312//      ostype & ?|?( ostype & os, const wchar_t * str ) {
313//              if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
314//              fmt( os, "%ls", str );
315//              return os;
316//      } // ?|?
317
318        ostype & ?|?( ostype & os, const void * p ) {
319                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
320                fmt( os, "%p", p );
321                return os;
322        } // ?|?
[200fcb3]323        void ?|?( ostype & os, const void * p ) {
[9d362a0]324                (ostype &)(os | p); nl( os );
[200fcb3]325        } // ?|?
[3ce0d440]326
327        // manipulators
328        ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
[9d362a0]329                (ostype &)(manip( os ));
[200fcb3]330                return os;
331        } // ?|?
332        void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
[9d362a0]333                (ostype &)(manip( os ));
334                if ( getPrt( os ) ) nl( os );                                   // something printed ?
[5ea5b28]335                setPrt( os, false );                                                    // turn off
[3ce0d440]336        } // ?|?
337
338        ostype & sep( ostype & os ) {
[9d362a0]339                return (ostype &)(os | sepGet( os ));
[3ce0d440]340        } // sep
341
342        ostype & sepTuple( ostype & os ) {
[200fcb3]343                return os | sepGetTuple( os );
[3ce0d440]344        } // sepTuple
345
[200fcb3]346        ostype & nl( ostype & os ) {
[9d362a0]347                (ostype &)(os | '\n');
[5ea5b28]348                setPrt( os, false );                                                    // turn off
[3ce0d440]349                setNL( os, true );
350                flush( os );
[200fcb3]351                return sepOff( os );                                                    // prepare for next line
352        } // nl
353
[9d362a0]354        void nl( ostype & os ) {
355                if ( getANL( os ) ) (ostype &)(nl( os ));               // implementation only
356                else setPrt( os, false );                                               // turn off
357        } // nl
358
[200fcb3]359        ostype & nonl( ostype & os ) {
[5ea5b28]360                setPrt( os, false );                                                    // turn off
[3ce0d440]361                return os;
[200fcb3]362        } // nonl
[3ce0d440]363
364        ostype & sepOn( ostype & os ) {
[200fcb3]365                sepOn( os );                                                                    // call void returning
[3ce0d440]366                return os;
367        } // sepOn
368
369        ostype & sepOff( ostype & os ) {
[200fcb3]370                sepOff( os );                                                                   // call void returning
[3ce0d440]371                return os;
372        } // sepOff
[6de9f4a]373
[3ce0d440]374        ostype & sepEnable( ostype & os ) {
[200fcb3]375                sepEnable( os );                                                                // call void returning
[3ce0d440]376                return os;
377        } // sepEnable
[b6dc097]378
[3ce0d440]379        ostype & sepDisable( ostype & os ) {
[200fcb3]380                sepDisable( os );                                                               // call void returning
[3ce0d440]381                return os;
382        } // sepDisable
[cf16f94]383
[200fcb3]384        ostype & nlOn( ostype & os ) {
385                nlOn( os );                                                                             // call void returning
386                return os;
387        } // nlOn
388
389        ostype & nlOff( ostype & os ) {
390                nlOff( os );                                                                    // call void returning
391                return os;
392        } // nlOff
393} // distribution
[cf16f94]394
[c443d1d]395// tuples
[200fcb3]396forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
397        ostype & ?|?( ostype & os, T arg, Params rest ) {
[9d362a0]398                (ostype &)(os | arg);                                                   // print first argument
[200fcb3]399                sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
[9d362a0]400                (ostype &)(os | rest);                                                  // print remaining arguments
[200fcb3]401                sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
402                return os;
403        } // ?|?
404        void ?|?( ostype & os, T arg, Params rest ) {
[9d362a0]405                // (ostype &)(?|?( os, arg, rest )); nl( os );
406                (ostype &)(os | arg);                                                   // print first argument
[200fcb3]407                sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
[9d362a0]408                (ostype &)(os | rest);                                                  // print remaining arguments
[200fcb3]409                sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
[9d362a0]410                nl( os );
[200fcb3]411        } // ?|?
412} // distribution
[c443d1d]413
[6ba0659]414//---------------------------------------
415
[3ce0d440]416// writes the range [begin, end) to the given stream
[200fcb3]417forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
418        void write( iterator_type begin, iterator_type end, ostype & os ) {
419                void print( elt_type i ) { os | i; }
420                for_each( begin, end, print );
421        } // ?|?
422
423        void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
424                void print( elt_type i ) { os | i; }
425                for_each_reverse( begin, end, print );
426        } // ?|?
427} // distribution
[e56cfdb0]428
[6ba0659]429//---------------------------------------
[e56cfdb0]430
[3ce0d440]431forall( dtype istype | istream( istype ) ) {
[93c2e0a]432        istype & ?|?( istype & is, bool & b ) {
[3ce0d440]433                char val[6];
434                fmt( is, "%5s", val );
435                if ( strcmp( val, "true" ) == 0 ) b = true;
436                else if ( strcmp( val, "false" ) == 0 ) b = false;
437                else {
[93c2e0a]438                        fprintf( stderr, "invalid Boolean constant\n" );
[3ce0d440]439                        abort();
440                } // if
441                return is;
442        } // ?|?
443
444        istype & ?|?( istype & is, char & c ) {
[0efb269]445                char temp;
446                for () {
447                        fmt( is, "%c", &temp );                                                 // must pass pointer through varg to fmt
448                        // do not overwrite parameter with newline unless appropriate
449                        if ( temp != '\n' || getANL( is ) ) { c = temp; break; }
450                        if ( eof( is ) ) break;
451                } // for
[3ce0d440]452                return is;
453        } // ?|?
454
455        istype & ?|?( istype & is, signed char & sc ) {
456                fmt( is, "%hhd", &sc );
457                return is;
458        } // ?|?
459
460        istype & ?|?( istype & is, unsigned char & usc ) {
461                fmt( is, "%hhu", &usc );
462                return is;
463        } // ?|?
464
465        istype & ?|?( istype & is, short int & si ) {
466                fmt( is, "%hd", &si );
467                return is;
468        } // ?|?
469
470        istype & ?|?( istype & is, unsigned short int & usi ) {
471                fmt( is, "%hu", &usi );
472                return is;
473        } // ?|?
474
475        istype & ?|?( istype & is, int & i ) {
476                fmt( is, "%d", &i );
477                return is;
478        } // ?|?
479
480        istype & ?|?( istype & is, unsigned int & ui ) {
481                fmt( is, "%u", &ui );
482                return is;
483        } // ?|?
484
485        istype & ?|?( istype & is, long int & li ) {
486                fmt( is, "%ld", &li );
487                return is;
488        } // ?|?
489
490        istype & ?|?( istype & is, unsigned long int & ulli ) {
491                fmt( is, "%lu", &ulli );
492                return is;
493        } // ?|?
494
495        istype & ?|?( istype & is, long long int & lli ) {
496                fmt( is, "%lld", &lli );
497                return is;
498        } // ?|?
499
500        istype & ?|?( istype & is, unsigned long long int & ulli ) {
501                fmt( is, "%llu", &ulli );
502                return is;
503        } // ?|?
504
505
506        istype & ?|?( istype & is, float & f ) {
507                fmt( is, "%f", &f );
508                return is;
509        } // ?|?
510
511        istype & ?|?( istype & is, double & d ) {
512                fmt( is, "%lf", &d );
513                return is;
514        } // ?|?
515
516        istype & ?|?( istype & is, long double & ld ) {
517                fmt( is, "%Lf", &ld );
518                return is;
519        } // ?|?
520
521
522        istype & ?|?( istype & is, float _Complex & fc ) {
523                float re, im;
524                fmt( is, "%g%gi", &re, &im );
525                fc = re + im * _Complex_I;
526                return is;
527        } // ?|?
528
529        istype & ?|?( istype & is, double _Complex & dc ) {
530                double re, im;
531                fmt( is, "%lf%lfi", &re, &im );
532                dc = re + im * _Complex_I;
533                return is;
534        } // ?|?
535
536        istype & ?|?( istype & is, long double _Complex & ldc ) {
537                long double re, im;
538                fmt( is, "%Lf%Lfi", &re, &im );
539                ldc = re + im * _Complex_I;
540                return is;
541        } // ?|?
542
543        // manipulators
544        istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
545                return manip( is );
546        } // ?|?
547
[200fcb3]548        istype & nl( istype & is ) {
[3c5dee4]549                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
[3ce0d440]550                return is;
[200fcb3]551        } // nl
[0efb269]552
553        istype & nlOn( istype & is ) {
554                nlOn( is );                                                                             // call void returning
555                return is;
556        } // nlOn
557
558        istype & nlOff( istype & is ) {
559                nlOff( is );                                                                    // call void returning
560                return is;
561        } // nlOff
[3ce0d440]562} // distribution
[44574f2]563
[e24f13a]564_Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; }
[90c3b1c]565forall( dtype istype | istream( istype ) )
[09687aa]566istype & ?|?( istype & is, _Istream_cstrUC cstr ) {
[829c907]567        fmt( is, "%s", cstr.s );
[90c3b1c]568        return is;
[53ba273]569} // cstr
[90c3b1c]570
[e24f13a]571_Istream_cstrC cstr( char * str, int size ) { return (_Istream_cstrC){ str, size }; }
[90c3b1c]572forall( dtype istype | istream( istype ) )
[09687aa]573istype & ?|?( istype & is, _Istream_cstrC cstr ) {
[90c3b1c]574        char buf[16];
[53ba273]575        sprintf( buf, "%%%ds", cstr.size );
[829c907]576        fmt( is, buf, cstr.s );
[90c3b1c]577        return is;
[53ba273]578} // cstr
[90c3b1c]579
[86bd7c1f]580// Local Variables: //
581// tab-width: 4 //
[084520f]582// compile-command: "cfa iostream.cfa" //
[86bd7c1f]583// End: //
Note: See TracBrowser for help on using the repository browser.