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