Ignore:
Timestamp:
Jun 27, 2018, 3:28:41 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
b21c77a
Parents:
0182bfa (diff), 63238a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into with_gc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

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