Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r200fcb3 r084520f  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 11 22:02:03 2018
    13 // Update Count     : 546
     12// Last Modified On : Wed Sep 26 18:22:57 2018
     13// Update Count     : 474
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <stdbool.h>                                                                    // true/false
    21 //#include <string.h>                                                                   // strlen, strcmp
     21//#include <string.h>                                                                           // strlen, strcmp
    2222extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
    2323extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
     
    3232                return os;
    3333        } // ?|?
    34         void ?|?( ostype & os, bool b ) {
    35                 (ostype)(os | b); if ( getANL( os ) ) nl( os );
    36         } // ?|?
    37 
    38         ostype & ?|?( ostype & os, char c ) {
    39                 fmt( os, "%c", c );
    40                 if ( c == '\n' ) setNL( os, true );
    41                 return sepOff( os );
    42         } // ?|?
    43         void ?|?( ostype & os, char c ) {
    44                 (ostype)(os | c); if ( getANL( os ) ) nl( os );
    45         } // ?|?
    46 
    47         ostype & ?|?( ostype & os, signed char sc ) {
    48                 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    49                 fmt( os, "%hhd", sc );
    50                 return os;
    51         } // ?|?
    52         void ?|?( ostype & os, signed char sc ) {
    53                 (ostype)(os | sc); if ( getANL( os ) ) nl( os );
    54         } // ?|?
    55 
    56         ostype & ?|?( ostype & os, unsigned char usc ) {
    57                 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    58                 fmt( os, "%hhu", usc );
    59                 return os;
    60         } // ?|?
    61         void ?|?( ostype & os, unsigned char usc ) {
    62                 (ostype)(os | usc); if ( getANL( os ) ) nl( os );
     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;
    6352        } // ?|?
    6453
     
    6857                return os;
    6958        } // ?|?
    70         void & ?|?( ostype & os, short int si ) {
    71                 (ostype)(os | si); if ( getANL( os ) ) nl( os );
    72         } // ?|?
    7359
    7460        ostype & ?|?( ostype & os, unsigned short int usi ) {
     
    7763                return os;
    7864        } // ?|?
    79         void & ?|?( ostype & os, unsigned short int usi ) {
    80                 (ostype)(os | usi); if ( getANL( os ) ) nl( os );
    81         } // ?|?
    8265
    8366        ostype & ?|?( ostype & os, int i ) {
     
    8669                return os;
    8770        } // ?|?
    88         void & ?|?( ostype & os, int i ) {
    89                 (ostype)(os | i); if ( getANL( os ) ) nl( os );
    90         } // ?|?
    9171
    9272        ostype & ?|?( ostype & os, unsigned int ui ) {
     
    9575                return os;
    9676        } // ?|?
    97         void & ?|?( ostype & os, unsigned int ui ) {
    98                 (ostype)(os | ui); if ( getANL( os ) ) nl( os );
    99         } // ?|?
    10077
    10178        ostype & ?|?( ostype & os, long int li ) {
     
    10481                return os;
    10582        } // ?|?
    106         void & ?|?( ostype & os, long int li ) {
    107                 (ostype)(os | li); if ( getANL( os ) ) nl( os );
    108         } // ?|?
    10983
    11084        ostype & ?|?( ostype & os, unsigned long int uli ) {
     
    11387                return os;
    11488        } // ?|?
    115         void & ?|?( ostype & os, unsigned long int uli ) {
    116                 (ostype)(os | uli); if ( getANL( os ) ) nl( os );
    117         } // ?|?
    11889
    11990        ostype & ?|?( ostype & os, long long int lli ) {
     
    12293                return os;
    12394        } // ?|?
    124         void & ?|?( ostype & os, long long int lli ) {
    125                 (ostype)(os | lli); if ( getANL( os ) ) nl( os );
    126         } // ?|?
    12795
    12896        ostype & ?|?( ostype & os, unsigned long long int ulli ) {
     
    13199                return os;
    132100        } // ?|?
    133         void & ?|?( ostype & os, unsigned long long int ulli ) {
    134                 (ostype)(os | ulli); if ( getANL( os ) ) nl( os );
    135         } // ?|?
    136101
    137102        ostype & ?|?( ostype & os, float f ) {
     
    140105                return os;
    141106        } // ?|?
    142         void & ?|?( ostype & os, float f ) {
    143                 (ostype)(os | f); if ( getANL( os ) ) nl( os );
    144         } // ?|?
    145107
    146108        ostype & ?|?( ostype & os, double d ) {
     
    149111                return os;
    150112        } // ?|?
    151         void & ?|?( ostype & os, double d ) {
    152                 (ostype)(os | d); if ( getANL( os ) ) nl( os );
    153         } // ?|?
    154113
    155114        ostype & ?|?( ostype & os, long double ld ) {
     
    158117                return os;
    159118        } // ?|?
    160         void & ?|?( ostype & os, long double ld ) {
    161                 (ostype)(os | ld); if ( getANL( os ) ) nl( os );
    162         } // ?|?
    163119
    164120        ostype & ?|?( ostype & os, float _Complex fc ) {
     
    167123                return os;
    168124        } // ?|?
    169         void & ?|?( ostype & os, float _Complex fc ) {
    170                 (ostype)(os | fc); if ( getANL( os ) ) nl( os );
    171         } // ?|?
    172125
    173126        ostype & ?|?( ostype & os, double _Complex dc ) {
     
    176129                return os;
    177130        } // ?|?
    178         void & ?|?( ostype & os, double _Complex dc ) {
    179                 (ostype)(os | dc); if ( getANL( os ) ) nl( os );
    180         } // ?|?
    181131
    182132        ostype & ?|?( ostype & os, long double _Complex ldc ) {
     
    184134                fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
    185135                return os;
    186         } // ?|?
    187         void & ?|?( ostype & os, long double _Complex ldc ) {
    188                 (ostype)(os | ldc); if ( getANL( os ) ) nl( os );
    189136        } // ?|?
    190137
     
    227174                return write( os, str, len );
    228175        } // ?|?
    229         void ?|?( ostype & os, const char * str ) {
    230                 (ostype)(os | str); if ( getANL( os ) ) nl( os );
    231         } // ?|?
    232176
    233177//      ostype & ?|?( ostype & os, const char16_t * str ) {
     
    256200                return os;
    257201        } // ?|?
    258         void ?|?( ostype & os, const void * p ) {
    259                 (ostype)(os | p); if ( getANL( os ) ) nl( os );
    260         } // ?|?
     202
    261203
    262204        // manipulators
    263205        ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    264                 (ostype)(manip( os ));
    265                 setNonl( os, false );                                                   // ignore nonl in middle
    266                 return os;
    267         } // ?|?
    268         void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    269                 (ostype)(manip( os ));
    270                 if ( getANL( os ) && ! getNonl( os ) ) nl( os ); // ignore nl if nonl at end
    271                 setNonl( os, false );
     206                return manip( os );
    272207        } // ?|?
    273208
    274209        ostype & sep( ostype & os ) {
    275                 return (ostype)(os | sepGet( os ));
     210                os | sepGet( os );
     211                return os;
    276212        } // sep
    277213
    278214        ostype & sepTuple( ostype & os ) {
    279                 return os | sepGetTuple( os );
     215                os | sepGetTuple( os );
     216                return os;
    280217        } // sepTuple
    281218
    282         ostype & nl( ostype & os ) {
    283                 (ostype)(os | '\n');
     219        ostype & endl( ostype & os ) {
     220                os | '\n';
    284221                setNL( os, true );
    285222                flush( os );
    286                 return sepOff( os );                                                    // prepare for next line
    287         } // nl
    288 
    289         ostype & nonl( ostype & os ) {
    290                 setNonl( os, true );                                                    // indicate nonl manipulator
    291                 return os;
    292         } // nonl
     223                sepOff( os );                                                                   // prepare for next line
     224                return os;
     225        } // endl
    293226
    294227        ostype & sepOn( ostype & os ) {
    295                 sepOn( os );                                                                    // call void returning
     228                sepOn( os );
    296229                return os;
    297230        } // sepOn
    298231
    299232        ostype & sepOff( ostype & os ) {
    300                 sepOff( os );                                                                   // call void returning
     233                sepOff( os );
    301234                return os;
    302235        } // sepOff
    303236
    304237        ostype & sepEnable( ostype & os ) {
    305                 sepEnable( os );                                                                // call void returning
     238                sepEnable( os );
    306239                return os;
    307240        } // sepEnable
    308241
    309242        ostype & sepDisable( ostype & os ) {
    310                 sepDisable( os );                                                               // call void returning
     243                sepDisable( os );
    311244                return os;
    312245        } // sepDisable
    313 
    314         ostype & nlOn( ostype & os ) {
    315                 nlOn( os );                                                                             // call void returning
    316                 return os;
    317         } // nlOn
    318 
    319         ostype & nlOff( ostype & os ) {
    320                 nlOff( os );                                                                    // call void returning
    321                 return os;
    322         } // nlOff
    323246} // distribution
    324247
     248
    325249// tuples
    326 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    327         ostype & ?|?( ostype & os, T arg, Params rest ) {
    328                 (ostype)(os | arg);                                                             // print first argument
    329                 sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
    330                 (ostype)(os | rest);                                                    // print remaining arguments
    331                 sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
    332                 return os;
    333         } // ?|?
    334         void ?|?( ostype & os, T arg, Params rest ) {
    335 //              (ostype)(?|?( os, arg, rest )); if ( getANL( os ) ) nl( os );
    336                 (ostype)(os | arg);                                                             // print first argument
    337                 sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
    338                 (ostype)(os | rest);                                                    // print remaining arguments
    339                 sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
    340                 if ( getANL( os ) ) nl( os );
    341         } // ?|?
    342 } // distribution
     250forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } )
     251ostype & ?|?( ostype & os, T arg, Params rest ) {
     252        os | arg;                                                                                       // print first argument
     253        sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator
     254        os | rest;                                                                                      // print remaining arguments
     255        sepSetCur( os, sepGet( os ) );                                          // switch to regular separator
     256        return os;
     257} // ?|?
    343258
    344259//---------------------------------------
    345260
    346261// writes the range [begin, end) to the given stream
    347 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
    348         void write( iterator_type begin, iterator_type end, ostype & os ) {
    349                 void print( elt_type i ) { os | i; }
    350                 for_each( begin, end, print );
    351         } // ?|?
    352 
    353         void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
    354                 void print( elt_type i ) { os | i; }
    355                 for_each_reverse( begin, end, print );
    356         } // ?|?
    357 } // distribution
     262forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     263void write( iterator_type begin, iterator_type end, ostype & os ) {
     264        void print( elt_type i ) { os | i; }
     265        for_each( begin, end, print );
     266} // ?|?
     267
     268forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     269void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
     270        void print( elt_type i ) { os | i; }
     271        for_each_reverse( begin, end, print );
     272} // ?|?
    358273
    359274//---------------------------------------
     
    471386        } // ?|?
    472387
    473         istype & nl( istype & is ) {
     388        istype & endl( istype & is ) {
    474389                fmt( is, "%*[ \t\f\n\r\v]" );                                   // ignore whitespace
    475390                return is;
    476         } // nl
     391        } // endl
    477392} // distribution
    478393
Note: See TracChangeset for help on using the changeset viewer.