| [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 | 
|---|
| [3e239ea] | 12 | // Last Modified On : Sun Sep 17 23:24:25 2017 | 
|---|
|  | 13 | // Update Count     : 422 | 
|---|
| [86bd7c1f] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
| [d3b7937] | 16 | #include "iostream" | 
|---|
|  | 17 |  | 
|---|
| [51b73452] | 18 | extern "C" { | 
|---|
|  | 19 | #include <stdio.h> | 
|---|
| [53a6c2a] | 20 | #include <stdbool.h>                                                                    // true/false | 
|---|
| [839ccbb] | 21 | #include <string.h>                                                                             // strlen | 
|---|
| [52f85e0] | 22 | #include <float.h>                                                                              // DBL_DIG, LDBL_DIG | 
|---|
| [d3b7937] | 23 | #include <complex.h>                                                                    // creal, cimag | 
|---|
| [51b73452] | 24 | } | 
|---|
|  | 25 |  | 
|---|
|  | 26 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [53a6c2a] | 27 | ostype * ?|?( ostype * os, char ch ) { | 
|---|
|  | 28 | fmt( os, "%c", ch ); | 
|---|
|  | 29 | if ( ch == '\n' ) setNL( os, true ); | 
|---|
| [53ba273] | 30 | sepOff( os ); | 
|---|
| [90c3b1c] | 31 | return os; | 
|---|
|  | 32 | } // ?|? | 
|---|
|  | 33 |  | 
|---|
| [1630f18] | 34 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 35 | ostype * ?|?( ostype * os, signed char c ) { | 
|---|
| [3e239ea] | 36 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
| [829c907] | 37 | fmt( os, "%hhd", c ); | 
|---|
| [1630f18] | 38 | return os; | 
|---|
|  | 39 | } // ?|? | 
|---|
|  | 40 |  | 
|---|
|  | 41 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 42 | ostype * ?|?( ostype * os, unsigned char c ) { | 
|---|
| [3e239ea] | 43 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
| [829c907] | 44 | fmt( os, "%hhu", c ); | 
|---|
| [1630f18] | 45 | return os; | 
|---|
|  | 46 | } // ?|? | 
|---|
|  | 47 |  | 
|---|
| [90c3b1c] | 48 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 49 | ostype * ?|?( ostype * os, short int si ) { | 
|---|
|  | 50 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 51 | fmt( os, "%hd", si ); | 
|---|
| [90c3b1c] | 52 | return os; | 
|---|
|  | 53 | } // ?|? | 
|---|
|  | 54 |  | 
|---|
|  | 55 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 56 | ostype * ?|?( ostype * os, unsigned short int usi ) { | 
|---|
|  | 57 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 58 | fmt( os, "%hu", usi ); | 
|---|
| [90c3b1c] | 59 | return os; | 
|---|
| [cf16f94] | 60 | } // ?|? | 
|---|
| [51b73452] | 61 |  | 
|---|
|  | 62 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 63 | ostype * ?|?( ostype * os, int i ) { | 
|---|
|  | 64 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 65 | fmt( os, "%d", i ); | 
|---|
| [90c3b1c] | 66 | return os; | 
|---|
| [784deab] | 67 | } // ?|? | 
|---|
|  | 68 |  | 
|---|
|  | 69 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 70 | ostype * ?|?( ostype * os, unsigned int ui ) { | 
|---|
|  | 71 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 72 | fmt( os, "%u", ui ); | 
|---|
| [90c3b1c] | 73 | return os; | 
|---|
| [784deab] | 74 | } // ?|? | 
|---|
|  | 75 |  | 
|---|
|  | 76 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 77 | ostype * ?|?( ostype * os, long int li ) { | 
|---|
|  | 78 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 79 | fmt( os, "%ld", li ); | 
|---|
| [90c3b1c] | 80 | return os; | 
|---|
| [784deab] | 81 | } // ?|? | 
|---|
|  | 82 |  | 
|---|
|  | 83 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 84 | ostype * ?|?( ostype * os, unsigned long int uli ) { | 
|---|
|  | 85 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 86 | fmt( os, "%lu", uli ); | 
|---|
| [90c3b1c] | 87 | return os; | 
|---|
| [784deab] | 88 | } // ?|? | 
|---|
|  | 89 |  | 
|---|
|  | 90 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 91 | ostype * ?|?( ostype * os, long long int lli ) { | 
|---|
|  | 92 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 93 | fmt( os, "%lld", lli ); | 
|---|
| [90c3b1c] | 94 | return os; | 
|---|
| [784deab] | 95 | } // ?|? | 
|---|
|  | 96 |  | 
|---|
|  | 97 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 98 | ostype * ?|?( ostype * os, unsigned long long int ulli ) { | 
|---|
|  | 99 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 100 | fmt( os, "%llu", ulli ); | 
|---|
| [90c3b1c] | 101 | return os; | 
|---|
| [cf16f94] | 102 | } // ?|? | 
|---|
| [51b73452] | 103 |  | 
|---|
| [d3b7937] | 104 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 105 | ostype * ?|?( ostype * os, float f ) { | 
|---|
|  | 106 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 107 | fmt( os, "%g", f ); | 
|---|
| [90c3b1c] | 108 | return os; | 
|---|
| [d3b7937] | 109 | } // ?|? | 
|---|
|  | 110 |  | 
|---|
| [51b73452] | 111 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 112 | ostype * ?|?( ostype * os, double d ) { | 
|---|
|  | 113 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 114 | fmt( os, "%.*lg", DBL_DIG, d ); | 
|---|
| [90c3b1c] | 115 | return os; | 
|---|
| [cf16f94] | 116 | } // ?|? | 
|---|
| [134b86a] | 117 |  | 
|---|
|  | 118 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 119 | ostype * ?|?( ostype * os, long double ld ) { | 
|---|
|  | 120 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 121 | fmt( os, "%.*Lg", LDBL_DIG, ld ); | 
|---|
| [90c3b1c] | 122 | return os; | 
|---|
| [cf16f94] | 123 | } // ?|? | 
|---|
| [51b73452] | 124 |  | 
|---|
| [d3b7937] | 125 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 126 | ostype * ?|?( ostype * os, float _Complex fc ) { | 
|---|
| [17954f0e] | 127 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 128 | fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) ); | 
|---|
| [90c3b1c] | 129 | return os; | 
|---|
| [d3b7937] | 130 | } // ?|? | 
|---|
|  | 131 |  | 
|---|
|  | 132 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 133 | ostype * ?|?( ostype * os, double _Complex dc ) { | 
|---|
| [17954f0e] | 134 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 135 | fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) ); | 
|---|
| [90c3b1c] | 136 | return os; | 
|---|
| [d3b7937] | 137 | } // ?|? | 
|---|
|  | 138 |  | 
|---|
|  | 139 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 140 | ostype * ?|?( ostype * os, long double _Complex ldc ) { | 
|---|
| [17954f0e] | 141 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 142 | fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) ); | 
|---|
| [90c3b1c] | 143 | return os; | 
|---|
| [d3b7937] | 144 | } // ?|? | 
|---|
|  | 145 |  | 
|---|
| [e56cfdb0] | 146 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [6de9f4a] | 147 | ostype * ?|?( ostype * os, const char * str ) { | 
|---|
| [b63e376] | 148 | enum { Open = 1, Close, OpenClose }; | 
|---|
| [a4dd728] | 149 | static const unsigned char mask[256] @= { | 
|---|
| [c443d1d] | 150 | // opening delimiters, no space after | 
|---|
| [b63e376] | 151 | ['('] : Open, ['['] : Open, ['{'] : Open, | 
|---|
| [cb91437] | 152 | ['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, | 
|---|
| [e945826] | 153 | [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open, | 
|---|
| [c443d1d] | 154 | // closing delimiters, no space before | 
|---|
| [b65a9fc] | 155 | [','] : Close, ['.'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, | 
|---|
| [53ba273] | 156 | ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close, | 
|---|
| [829c907] | 157 | [')'] : Close, [']'] : Close, ['}'] : Close, | 
|---|
| [c443d1d] | 158 | // opening-closing delimiters, no space before or after | 
|---|
| [b65a9fc] | 159 | ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, [':'] : OpenClose, | 
|---|
| [e945826] | 160 | [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace | 
|---|
| [b63e376] | 161 | }; // mask | 
|---|
|  | 162 |  | 
|---|
| [6de9f4a] | 163 | if ( str[0] == '\0' ) { sepOff( os ); return os; }            // null string => no separator | 
|---|
| [b72bad4f] | 164 |  | 
|---|
| [53ba273] | 165 | // first character IS NOT spacing or closing punctuation => add left separator | 
|---|
| [6de9f4a] | 166 | unsigned char ch = str[0];                                                      // must make unsigned | 
|---|
| [53ba273] | 167 | if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { | 
|---|
| [829c907] | 168 | fmt( os, "%s", sepGetCur( os ) ); | 
|---|
| [90c3b1c] | 169 | } // if | 
|---|
| [b72bad4f] | 170 |  | 
|---|
|  | 171 | // if string starts line, must reset to determine open state because separator is off | 
|---|
|  | 172 | sepReset( os );                                                                         // reset separator | 
|---|
|  | 173 |  | 
|---|
| [b63e376] | 174 | // last character IS spacing or opening punctuation => turn off separator for next item | 
|---|
| [6de9f4a] | 175 | size_t len = strlen( str ); | 
|---|
|  | 176 | ch = str[len - 1];                                                                      // must make unsigned | 
|---|
| [b72bad4f] | 177 | if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { | 
|---|
| [90c3b1c] | 178 | sepOn( os ); | 
|---|
| [b72bad4f] | 179 | } else { | 
|---|
|  | 180 | sepOff( os ); | 
|---|
| [90c3b1c] | 181 | } // if | 
|---|
| [53a6c2a] | 182 | if ( ch == '\n' ) setNL( os, true );                            // check *AFTER* sepPrt call above as it resets NL flag | 
|---|
| [6de9f4a] | 183 | return write( os, str, len ); | 
|---|
|  | 184 | } // ?|? | 
|---|
|  | 185 |  | 
|---|
|  | 186 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
|  | 187 | ostype * ?|?( ostype * os, const char16_t * str ) { | 
|---|
|  | 188 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 189 | fmt( os, "%ls", str ); | 
|---|
|  | 190 | return os; | 
|---|
|  | 191 | } // ?|? | 
|---|
|  | 192 |  | 
|---|
|  | 193 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
|  | 194 | ostype * ?|?( ostype * os, const char32_t * str ) { | 
|---|
|  | 195 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 196 | fmt( os, "%ls", str ); | 
|---|
|  | 197 | return os; | 
|---|
|  | 198 | } // ?|? | 
|---|
|  | 199 |  | 
|---|
|  | 200 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
|  | 201 | ostype * ?|?( ostype * os, const wchar_t * str ) { | 
|---|
|  | 202 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 203 | fmt( os, "%ls", str ); | 
|---|
|  | 204 | return os; | 
|---|
| [784deab] | 205 | } // ?|? | 
|---|
|  | 206 |  | 
|---|
|  | 207 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 208 | ostype * ?|?( ostype * os, const void * p ) { | 
|---|
|  | 209 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 210 | fmt( os, "%p", p ); | 
|---|
| [90c3b1c] | 211 | return os; | 
|---|
| [cf16f94] | 212 | } // ?|? | 
|---|
|  | 213 |  | 
|---|
|  | 214 |  | 
|---|
| [c443d1d] | 215 | // tuples | 
|---|
| [e1780a2] | 216 | forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } ) | 
|---|
| [c443d1d] | 217 | ostype * ?|?( ostype * os, T arg, Params rest ) { | 
|---|
| [0583064b] | 218 | os | arg;                                                                                       // print first argument | 
|---|
| [86f384b] | 219 | sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator | 
|---|
| [0583064b] | 220 | os | rest;                                                                                      // print remaining arguments | 
|---|
| [829c907] | 221 | sepSetCur( os, sepGet( os ) );                                          // switch to regular separator | 
|---|
| [cb91437] | 222 | return os; | 
|---|
| [c443d1d] | 223 | } // ?|? | 
|---|
|  | 224 |  | 
|---|
|  | 225 |  | 
|---|
|  | 226 | // manipulators | 
|---|
| [a5a71d0] | 227 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [4e06c1e] | 228 | ostype * ?|?( ostype * os, ostype * (* manip)( ostype * ) ) { | 
|---|
| [90c3b1c] | 229 | return manip( os ); | 
|---|
|  | 230 | } // ?|? | 
|---|
| [cf16f94] | 231 |  | 
|---|
| [53a6c2a] | 232 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
|  | 233 | ostype * sep( ostype * os ) { | 
|---|
|  | 234 | os | sepGet( os ); | 
|---|
|  | 235 | return os; | 
|---|
|  | 236 | } // sep | 
|---|
|  | 237 |  | 
|---|
|  | 238 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
|  | 239 | ostype * sepTuple( ostype * os ) { | 
|---|
|  | 240 | os | sepGetTuple( os ); | 
|---|
|  | 241 | return os; | 
|---|
|  | 242 | } // sepTuple | 
|---|
|  | 243 |  | 
|---|
| [a5a71d0] | 244 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [cf16f94] | 245 | ostype * endl( ostype * os ) { | 
|---|
| [90c3b1c] | 246 | os | '\n'; | 
|---|
| [53a6c2a] | 247 | setNL( os, true ); | 
|---|
| [6ba0659] | 248 | flush( os ); | 
|---|
| [0583064b] | 249 | sepOff( os );                                                                           // prepare for next line | 
|---|
| [6ba0659] | 250 | return os; | 
|---|
| [cf16f94] | 251 | } // endl | 
|---|
| [e56cfdb0] | 252 |  | 
|---|
| [a5a71d0] | 253 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [90c3b1c] | 254 | ostype * sepOn( ostype * os ) { | 
|---|
|  | 255 | sepOn( os ); | 
|---|
|  | 256 | return os; | 
|---|
|  | 257 | } // sepOn | 
|---|
|  | 258 |  | 
|---|
| [a5a71d0] | 259 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [90c3b1c] | 260 | ostype * sepOff( ostype * os ) { | 
|---|
|  | 261 | sepOff( os ); | 
|---|
|  | 262 | return os; | 
|---|
|  | 263 | } // sepOff | 
|---|
|  | 264 |  | 
|---|
| [70a06f6] | 265 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [53ba273] | 266 | ostype * sepEnable( ostype * os ) { | 
|---|
|  | 267 | sepEnable( os ); | 
|---|
|  | 268 | return os; | 
|---|
|  | 269 | } // sepEnable | 
|---|
|  | 270 |  | 
|---|
| [70a06f6] | 271 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [53ba273] | 272 | ostype * sepDisable( ostype * os ) { | 
|---|
|  | 273 | sepDisable( os ); | 
|---|
|  | 274 | return os; | 
|---|
|  | 275 | } // sepDisable | 
|---|
|  | 276 |  | 
|---|
| [6ba0659] | 277 | //--------------------------------------- | 
|---|
|  | 278 |  | 
|---|
| [e1780a2] | 279 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) | 
|---|
|  | 280 | void write( iterator_type begin, iterator_type end, ostype * os ) { | 
|---|
|  | 281 | void print( elt_type i ) { os | i; } | 
|---|
| [e56cfdb0] | 282 | for_each( begin, end, print ); | 
|---|
| [cf16f94] | 283 | } // ?|? | 
|---|
| [e56cfdb0] | 284 |  | 
|---|
| [e1780a2] | 285 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) | 
|---|
|  | 286 | void write_reverse( iterator_type begin, iterator_type end, ostype * os ) { | 
|---|
|  | 287 | void print( elt_type i ) { os | i; } | 
|---|
| [e56cfdb0] | 288 | for_each_reverse( begin, end, print ); | 
|---|
| [cf16f94] | 289 | } // ?|? | 
|---|
| [e56cfdb0] | 290 |  | 
|---|
| [6ba0659] | 291 | //--------------------------------------- | 
|---|
| [e56cfdb0] | 292 |  | 
|---|
| [51b73452] | 293 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 294 | istype * ?|?( istype * is, char & c ) { | 
|---|
|  | 295 | fmt( is, "%c", &c );                                                            // must pass pointer through varg to fmt | 
|---|
| [90c3b1c] | 296 | return is; | 
|---|
|  | 297 | } // ?|? | 
|---|
|  | 298 |  | 
|---|
| [6de9f4a] | 299 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 300 | istype * ?|?( istype * is, signed char & sc ) { | 
|---|
|  | 301 | fmt( is, "%hhd", &sc ); | 
|---|
|  | 302 | return is; | 
|---|
|  | 303 | } // ?|? | 
|---|
|  | 304 |  | 
|---|
|  | 305 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 306 | istype * ?|?( istype * is, unsigned char & usc ) { | 
|---|
|  | 307 | fmt( is, "%hhu", &usc ); | 
|---|
|  | 308 | return is; | 
|---|
|  | 309 | } // ?|? | 
|---|
|  | 310 |  | 
|---|
| [90c3b1c] | 311 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 312 | istype * ?|?( istype * is, short int & si ) { | 
|---|
|  | 313 | fmt( is, "%hd", &si ); | 
|---|
| [90c3b1c] | 314 | return is; | 
|---|
|  | 315 | } // ?|? | 
|---|
|  | 316 |  | 
|---|
|  | 317 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 318 | istype * ?|?( istype * is, unsigned short int & usi ) { | 
|---|
|  | 319 | fmt( is, "%hu", &usi ); | 
|---|
| [90c3b1c] | 320 | return is; | 
|---|
|  | 321 | } // ?|? | 
|---|
|  | 322 |  | 
|---|
|  | 323 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 324 | istype * ?|?( istype * is, int & i ) { | 
|---|
|  | 325 | fmt( is, "%d", &i ); | 
|---|
| [90c3b1c] | 326 | return is; | 
|---|
|  | 327 | } // ?|? | 
|---|
|  | 328 |  | 
|---|
|  | 329 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 330 | istype * ?|?( istype * is, unsigned int & ui ) { | 
|---|
|  | 331 | fmt( is, "%u", &ui ); | 
|---|
| [90c3b1c] | 332 | return is; | 
|---|
|  | 333 | } // ?|? | 
|---|
|  | 334 |  | 
|---|
|  | 335 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 336 | istype * ?|?( istype * is, long int & li ) { | 
|---|
|  | 337 | fmt( is, "%ld", &li ); | 
|---|
| [90c3b1c] | 338 | return is; | 
|---|
| [cf16f94] | 339 | } // ?|? | 
|---|
| [51b73452] | 340 |  | 
|---|
|  | 341 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 342 | istype * ?|?( istype * is, unsigned long int & ulli ) { | 
|---|
|  | 343 | fmt( is, "%lu", &ulli ); | 
|---|
| [90c3b1c] | 344 | return is; | 
|---|
|  | 345 | } // ?|? | 
|---|
|  | 346 |  | 
|---|
|  | 347 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 348 | istype * ?|?( istype * is, long long int & lli ) { | 
|---|
|  | 349 | fmt( is, "%lld", &lli ); | 
|---|
| [90c3b1c] | 350 | return is; | 
|---|
|  | 351 | } // ?|? | 
|---|
|  | 352 |  | 
|---|
|  | 353 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 354 | istype * ?|?( istype * is, unsigned long long int & ulli ) { | 
|---|
|  | 355 | fmt( is, "%llu", &ulli ); | 
|---|
| [90c3b1c] | 356 | return is; | 
|---|
|  | 357 | } // ?|? | 
|---|
|  | 358 |  | 
|---|
|  | 359 |  | 
|---|
|  | 360 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 361 | istype * ?|?( istype * is, float & f ) { | 
|---|
|  | 362 | fmt( is, "%f", &f ); | 
|---|
| [90c3b1c] | 363 | return is; | 
|---|
| [cf16f94] | 364 | } // ?|? | 
|---|
| [86bd7c1f] | 365 |  | 
|---|
| [90c3b1c] | 366 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 367 | istype * ?|?( istype * is, double & d ) { | 
|---|
|  | 368 | fmt( is, "%lf", &d ); | 
|---|
| [90c3b1c] | 369 | return is; | 
|---|
|  | 370 | } // ?|? | 
|---|
|  | 371 |  | 
|---|
|  | 372 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 373 | istype * ?|?( istype * is, long double & ld ) { | 
|---|
|  | 374 | fmt( is, "%Lf", &ld ); | 
|---|
| [90c3b1c] | 375 | return is; | 
|---|
|  | 376 | } // ?|? | 
|---|
|  | 377 |  | 
|---|
|  | 378 |  | 
|---|
|  | 379 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 380 | istype * ?|?( istype * is, float _Complex & fc ) { | 
|---|
| [90c3b1c] | 381 | float re, im; | 
|---|
| [829c907] | 382 | fmt( is, "%g%gi", &re, &im ); | 
|---|
| [7bc4e6b] | 383 | fc = re + im * _Complex_I; | 
|---|
| [90c3b1c] | 384 | return is; | 
|---|
|  | 385 | } // ?|? | 
|---|
|  | 386 |  | 
|---|
|  | 387 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 388 | istype * ?|?( istype * is, double _Complex & dc ) { | 
|---|
| [90c3b1c] | 389 | double re, im; | 
|---|
| [829c907] | 390 | fmt( is, "%lf%lfi", &re, &im ); | 
|---|
| [7bc4e6b] | 391 | dc = re + im * _Complex_I; | 
|---|
| [90c3b1c] | 392 | return is; | 
|---|
| [cf16f94] | 393 | } // ?|? | 
|---|
| [51b73452] | 394 |  | 
|---|
|  | 395 | forall( dtype istype | istream( istype ) ) | 
|---|
| [7bc4e6b] | 396 | istype * ?|?( istype * is, long double _Complex & ldc ) { | 
|---|
| [90c3b1c] | 397 | long double re, im; | 
|---|
| [829c907] | 398 | fmt( is, "%Lf%Lfi", &re, &im ); | 
|---|
| [7bc4e6b] | 399 | ldc = re + im * _Complex_I; | 
|---|
| [90c3b1c] | 400 | return is; | 
|---|
| [cf16f94] | 401 | } // ?|? | 
|---|
| [86bd7c1f] | 402 |  | 
|---|
| [e24f13a] | 403 | _Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; } | 
|---|
| [90c3b1c] | 404 | forall( dtype istype | istream( istype ) ) | 
|---|
| [53ba273] | 405 | istype * ?|?( istype * is, _Istream_cstrUC cstr ) { | 
|---|
| [829c907] | 406 | fmt( is, "%s", cstr.s ); | 
|---|
| [90c3b1c] | 407 | return is; | 
|---|
| [53ba273] | 408 | } // cstr | 
|---|
| [90c3b1c] | 409 |  | 
|---|
| [e24f13a] | 410 | _Istream_cstrC cstr( char * str, int size ) { return (_Istream_cstrC){ str, size }; } | 
|---|
| [90c3b1c] | 411 | forall( dtype istype | istream( istype ) ) | 
|---|
| [53ba273] | 412 | istype * ?|?( istype * is, _Istream_cstrC cstr ) { | 
|---|
| [90c3b1c] | 413 | char buf[16]; | 
|---|
| [53ba273] | 414 | sprintf( buf, "%%%ds", cstr.size ); | 
|---|
| [829c907] | 415 | fmt( is, buf, cstr.s ); | 
|---|
| [90c3b1c] | 416 | return is; | 
|---|
| [53ba273] | 417 | } // cstr | 
|---|
| [90c3b1c] | 418 |  | 
|---|
| [86bd7c1f] | 419 | // Local Variables: // | 
|---|
|  | 420 | // tab-width: 4 // | 
|---|
|  | 421 | // compile-command: "cfa iostream.c" // | 
|---|
|  | 422 | // End: // | 
|---|