Changeset 61c7239 for libcfa/src


Ignore:
Timestamp:
Jun 9, 2019, 6:23:47 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a62749f, ca8824d, e7f8119
Parents:
1e6ea4e1
Message:

first attempt input/output manipulators

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r1e6ea4e1 r61c7239  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun  4 17:32:34 2019
    13 // Update Count     : 761
     12// Last Modified On : Sun Jun  9 16:27:17 2019
     13// Update Count     : 803
    1414//
    1515
     
    2828#include <complex.h>                                                                    // creal, cimag
    2929} // extern "C"
     30
     31
     32//*********************************** Ostream ***********************************
     33
    3034
    3135forall( dtype ostype | ostream( ostype ) ) {
     
    391395} // distribution
    392396
     397// writes the range [begin, end) to the given stream
     398forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
     399        void write( iterator_type begin, iterator_type end, ostype & os ) {
     400                void print( elt_type i ) { os | i; }
     401                for_each( begin, end, print );
     402        } // ?|?
     403
     404        void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
     405                void print( elt_type i ) { os | i; }
     406                for_each_reverse( begin, end, print );
     407        } // ?|?
     408} // distribution
     409
     410//*********************************** Manipulators ***********************************
    393411
    394412//*********************************** Integral ***********************************
     
    606624} // distribution
    607625
    608 //---------------------------------------
    609 
    610 // writes the range [begin, end) to the given stream
    611 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
    612         void write( iterator_type begin, iterator_type end, ostype & os ) {
    613                 void print( elt_type i ) { os | i; }
    614                 for_each( begin, end, print );
    615         } // ?|?
    616 
    617         void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
    618                 void print( elt_type i ) { os | i; }
    619                 for_each_reverse( begin, end, print );
    620         } // ?|?
    621 } // distribution
    622 
    623626
    624627//*********************************** Istream ***********************************
     
    758761} // distribution
    759762
    760 _Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; }
     763//*********************************** Manipulators ***********************************
     764
    761765forall( dtype istype | istream( istype ) )
    762 istype & ?|?( istype & is, _Istream_cstrUC cstr ) {
    763         fmt( is, "%s", cstr.s );
     766istype & ?|?( istype & is, _Istream_Cstr f ) {
     767        // skip xxx
     768        if ( ! f.s ) {
     769                // printf( "skip %s\n", f.scanset );
     770                fmt( is, f.scanset, "" );                                               // no input arguments
     771                return is;
     772        } // if
     773        size_t len = 0;
     774        if ( f.scanset ) len = strlen( f.scanset );
     775        char fmtstr[len + 16];
     776        int start = 1;
     777        fmtstr[0] = '%';
     778        if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
     779        if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
     780        // cstr %s, %*s, %ws, %*ws
     781        if ( ! f.scanset ) {
     782                fmtstr[start] = 's'; fmtstr[start + 1] = '\0';
     783                // printf( "cstr %s\n", fmtstr );
     784                fmt( is, fmtstr, f.s );
     785                return is;
     786        } // if
     787        // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
     788        // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
     789        fmtstr[start] = '['; start += 1;
     790        if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
     791        strcpy( &fmtstr[start], f.scanset );                            // copy includes '\0'
     792        len += start;
     793        fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
     794        // printf( "incl/excl %s\n", fmtstr );
     795        fmt( is, fmtstr, f.s );
    764796        return is;
    765 } // cstr
    766 
    767 _Istream_cstrC cstr( char * str, int size ) { return (_Istream_cstrC){ str, size }; }
    768 forall( dtype istype | istream( istype ) )
    769 istype & ?|?( istype & is, _Istream_cstrC cstr ) {
    770         char buf[16];
    771         sprintf( buf, "%%%ds", cstr.size );
    772         fmt( is, buf, cstr.s );
    773         return is;
    774 } // cstr
    775 
    776 #if 0
    777 forall( dtype istype | istream( istype ) )
    778 istype & ?|?( istype & is, _Istream_skip skip ) {
    779         fmt( is, skip.s, "" );                                                          // no input arguments
    780         return is;
    781 } // skip
    782 
    783 forall( dtype istype | istream( istype ) )
    784 istype & ?|?( istype & is, _Istream_incl incl ) {
    785         size_t len = strlen( incl.scanset ) + 4;                        // extras: "%[]\0"
    786         char fmtstr[len];
    787         fmtstr[0] = '%'; fmtstr[1] = '[';
    788         strcpy( &fmtstr[2], incl.scanset );                                     // after '[', copy includes '\0'
    789         fmtstr[len - 2] = ']'; fmtstr[len - 1] = '\0';
    790         fmt( is, fmtstr, incl.s );
    791         return is;
    792 } // incl
    793 
    794 forall( dtype istype | istream( istype ) )
    795 istype & ?|?( istype & is, _Istream_excl excl ) {
    796         size_t len = strlen( excl.scanset );
    797         char fmtstr[len+5];
    798         fmtstr[0] = '%'; fmtstr[1] = '['; fmtstr[2] = '^';
    799         strcpy( &fmtstr[3], excl.scanset );                                     // after '^', copy includes '\0'
    800         fmtstr[len - 2] = ']'; fmtstr[len - 1] = '\0';
    801         fmt( is, fmtstr, excl.s );
    802         return is;
    803 } // excl
    804 
    805 forall( dtype istype | istream( istype ) )
    806 istype & ?|?( istype & is, _Istream_cstr cstr ) {
    807         fmt( is, "%s", cstr.s );
    808         return is;
    809 } // cstr
    810 
    811 _Istream_cstrW cstr( char * s, int size ) { return (_Istream_cstrW){ s, size }; }
    812 forall( dtype istype | istream( istype ) )
    813 istype & ?|?( istype & is, _Istream_cstrW cstr ) {
    814         enum { size = 16 };
    815         char fmtstr[size];
    816         sprintf( fmtstr, "%%%ds", cstr.size );
    817         fmt( is, fmtstr, cstr.s );
    818         return is;
    819 } // cstr
    820 
    821 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_Cstr ) {
    822        
    823 }
    824 
    825 //*********************************** Manipulators ***********************************
     797} // ?|?
    826798
    827799#define InputFMTImpl( T, CODE ) \
     
    830802        enum { size = 16 }; \
    831803        char fmtstr[size]; \
    832         if ( f.wd == -1 ) { \
     804        if ( f.wd == -1 || strcmp( CODE, "c" ) == 0 ) { /* ignore width with "c" */     \
    833805                snprintf( fmtstr, size, "%%%s%s", f.ignore ? "*" : "", CODE ); \
    834806        } else { \
     
    838810        fmt( is, fmtstr, &f.val ); \
    839811        return is; \
    840 } /* ?|? */
     812} // ?|?
    841813
    842814InputFMTImpl( char, "c" )
     
    856828InputFMTImpl( long double, "Lf" )
    857829
    858 InputFMTImpl( float _Complex, "ff" )
    859 InputFMTImpl( double _Complex, "lf" )
    860 InputFMTImpl( long double _Complex, "Lf" )
    861 #endif // 0
     830forall( dtype istype | istream( istype ) )
     831istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
     832        float re, im;
     833        _Istream_Manip(float) fmtuc @= { re, fc.wd, fc.ignore };
     834        is | fmtuc;
     835        &fmtuc.val = &im;
     836        is | fmtuc;
     837        if ( ! fc.ignore ) fc.val = re + im * _Complex_I;       // re/im are uninitialized for ignore
     838        return is;
     839} // ?|?
     840
     841forall( dtype istype | istream( istype ) )
     842istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
     843        double re, im;
     844        _Istream_Manip(double) fmtuc @= { re, dc.wd, dc.ignore };
     845        is | fmtuc;
     846        &fmtuc.val = &im;
     847        is | fmtuc;
     848        if ( ! dc.ignore ) dc.val = re + im * _Complex_I;       // re/im are uninitialized for ignore
     849        return is;
     850} // ?|?
     851
     852forall( dtype istype | istream( istype ) )
     853istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
     854        long double re, im;
     855        _Istream_Manip(long double) fmtuc @= { re, ldc.wd, ldc.ignore };
     856        is | fmtuc;
     857        &fmtuc.val = &im;
     858        is | fmtuc;
     859        if ( ! ldc.ignore ) ldc.val = re + im * _Complex_I;     // re/im are uninitialized for ignore
     860        return is;
     861} // ?|?
    862862
    863863// Local Variables: //
  • libcfa/src/iostream.hfa

    r1e6ea4e1 r61c7239  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun  4 17:33:43 2019
    13 // Update Count     : 286
     12// Last Modified On : Sat Jun  8 17:28:44 2019
     13// Update Count     : 312
    1414//
    1515
     
    171171//*********************************** Integral ***********************************
    172172
     173// See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular
     174// subobject overriding any previously listed initializer for the same subobject; ***all subobjects that are not
     175// initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.***
     176
    173177#define IntegralFMTDecl( T, CODE ) \
    174178static inline { \
    175         _Ostream_Manip(T) bin( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'b', { .all : 0 } }; } \
    176         _Ostream_Manip(T) oct( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'o', { .all : 0 } }; } \
    177         _Ostream_Manip(T) hex( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'x', { .all : 0 } }; } \
    178         _Ostream_Manip(T) wd( unsigned char w, T v ) { return (_Ostream_Manip(T))@{ v, w, 0, CODE, { .all : 0 } }; } \
    179         _Ostream_Manip(T) wd( unsigned char w, unsigned char p, T v ) { return (_Ostream_Manip(T))@{ v, w, p, CODE, { .flags.pc : true } }; } \
    180         _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) with(fmt) { wd = w; return fmt; } \
    181         _Ostream_Manip(T) & wd( unsigned char w, unsigned char p, _Ostream_Manip(T) & fmt ) with(fmt) { wd = w; pc = p; flags.pc = true; return fmt; } \
     179        _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \
     180        _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'o', { .all : 0 } }; } \
     181        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \
     182        _Ostream_Manip(T) wd( unsigned char w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \
     183        _Ostream_Manip(T) wd( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \
     184        _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
     185        _Ostream_Manip(T) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    182186        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    183187        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \
    184188        _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    185189        _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
    186         _Ostream_Manip(T) sign( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, CODE, { .flags.sign : true } }; } \
     190        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \
    187191        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    188192} \
     
    190194        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    191195        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
    192 }
     196} // ?|?
    193197
    194198IntegralFMTDecl( signed char, 'd' )
     
    208212#define FloatingPointFMTDecl( T ) \
    209213static inline { \
    210         _Ostream_Manip(T) sci( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'e', { .all : 0 } }; } \
    211         _Ostream_Manip(T) hex( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'a', { .all : 0 } }; } \
    212         _Ostream_Manip(T) wd( unsigned char w, T v ) { return (_Ostream_Manip(T))@{ v, w, 0, 'f', { .all : 0 } }; } \
    213         _Ostream_Manip(T) wd( unsigned char w, unsigned char p, T v ) { return (_Ostream_Manip(T))@{ v, w, p, 'f', { .flags.pc : true } }; } \
    214         _Ostream_Manip(T) ws( unsigned char w, unsigned char p, T v ) { return (_Ostream_Manip(T))@{ v, w, p, 'g', { .flags.pc : true } }; } \
    215         _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) with(fmt) { wd = w; return fmt; } \
    216         _Ostream_Manip(T) & wd( unsigned char w, unsigned char p, _Ostream_Manip(T) & fmt ) with(fmt) { wd = w; pc = p; flags.pc = true; return fmt; } \
     214        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \
     215        _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \
     216        _Ostream_Manip(T) wd( unsigned char w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'f', { .all : 0 } }; } \
     217        _Ostream_Manip(T) wd( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
     218        _Ostream_Manip(T) ws( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
     219        _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
     220        _Ostream_Manip(T) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    217221        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    218         _Ostream_Manip(T) upcase( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'G', { .all : 0 } }; } \
     222        _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \
    219223        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \
    220224        _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
    221         _Ostream_Manip(T) sign( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'g', { .flags.sign : true } }; } \
     225        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.sign : true } }; } \
    222226        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    223         _Ostream_Manip(T) nodp( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'g', { .flags.nobsdp : true } }; } \
     227        _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
    224228        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    225229} \
     
    227231        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    228232        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
    229 }
     233} // ?|?
    230234
    231235FloatingPointFMTDecl( double )
     
    235239
    236240static inline {
    237         _Ostream_Manip(char) bin( char v ) { return (_Ostream_Manip(char))@{ v, 1, 0, 'b', { .all : 0 } }; }
    238         _Ostream_Manip(char) oct( char v ) { return (_Ostream_Manip(char))@{ v, 1, 0, 'o', { .all : 0 } }; }
    239         _Ostream_Manip(char) hex( char v ) { return (_Ostream_Manip(char))@{ v, 1, 0, 'x', { .all : 0 } }; }
    240         _Ostream_Manip(char) wd( unsigned char w, char v ) { return (_Ostream_Manip(char))@{ v, w, 0, 'c', { .all : 0 } }; }
    241         _Ostream_Manip(char) & wd( unsigned char w, _Ostream_Manip(char) & fmt ) with(fmt) { wd = w; return fmt; }
     241        _Ostream_Manip(char) bin( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'b', { .all : 0 } }; }
     242        _Ostream_Manip(char) oct( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'o', { .all : 0 } }; }
     243        _Ostream_Manip(char) hex( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'x', { .all : 0 } }; }
     244        _Ostream_Manip(char) wd( unsigned char w, char val ) { return (_Ostream_Manip(char))@{ val, w, 0, 'c', { .all : 0 } }; }
     245        _Ostream_Manip(char) & wd( unsigned char w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; }
    242246        _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; }
    243247        _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
     
    247251        ostype & ?|?( ostype & os, _Ostream_Manip(char) f );
    248252        void ?|?( ostype & os, _Ostream_Manip(char) f );
    249 }
     253} // ?|?
    250254
    251255//*********************************** C String ***********************************
    252256
    253257static inline {
    254         _Ostream_Manip(const char *) bin( const char * v ) { return (_Ostream_Manip(const char *))@{ v, 1, 0, 'b', { .all : 0 } }; }
    255         _Ostream_Manip(const char *) oct( const char * v ) { return (_Ostream_Manip(const char *))@{ v, 1, 0, 'o', { .all : 0 } }; }
    256         _Ostream_Manip(const char *) hex( const char * v ) { return (_Ostream_Manip(const char *))@{ v, 1, 0, 'x', { .all : 0 } }; }
    257         _Ostream_Manip(const char *) wd( unsigned char w, const char * v ) { return (_Ostream_Manip(const char *))@{ v, w, 0, 's', { .all : 0 } }; }
    258         _Ostream_Manip(const char *) wd( unsigned char w, unsigned char p, const char * v ) { return (_Ostream_Manip(const char *))@{ v, w, p, 's', { .flags.pc : true } }; }
    259         _Ostream_Manip(const char *) & wd( unsigned char w, _Ostream_Manip(const char *) & fmt ) with(fmt) { wd = w; return fmt; }
    260         _Ostream_Manip(const char *) & wd( unsigned char w, unsigned char p, _Ostream_Manip(const char *) & fmt ) with(fmt) { wd = w; pc = p; flags.pc = true; return fmt; }
     258        _Ostream_Manip(const char *) bin( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'b', { .all : 0 } }; }
     259        _Ostream_Manip(const char *) oct( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'o', { .all : 0 } }; }
     260        _Ostream_Manip(const char *) hex( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'x', { .all : 0 } }; }
     261        _Ostream_Manip(const char *) wd( unsigned char w, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, 0, 's', { .all : 0 } }; }
     262        _Ostream_Manip(const char *) wd( unsigned char w, unsigned char pc, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, pc, 's', { .flags.pc : true } }; }
     263        _Ostream_Manip(const char *) & wd( unsigned char w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
     264        _Ostream_Manip(const char *) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
    261265        _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; }
    262266        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
     
    265269        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f );
    266270        void ?|?( ostype & os, _Ostream_Manip(const char *) f );
    267 }
     271} // ?|?
    268272
    269273
     
    312316        istype & ?|?( istype &, long double _Complex & );
    313317
     318        // Cannot have char & and char * => cstr manipulator
     319        // istype & ?|?( istype &, char * );
     320
    314321        // manipulators
    315322        istype & ?|?( istype &, istype & (*)( istype & ) );
     
    319326} // distribution
    320327
    321 struct _Istream_cstrUC { char * s; };
    322 _Istream_cstrUC cstr( char * );
    323 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC );
    324 
    325 struct _Istream_cstrC { char * s; int size; };
    326 _Istream_cstrC cstr( char *, int size );
    327 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC );
    328 
    329 #if 0
     328//*********************************** Manipulators ***********************************
     329
    330330struct _Istream_Cstr {
    331         char * s, * scanset;
     331        char * s;
     332        const char * scanset;
    332333        int wd;                                                                                         // width
    333         bool ignore;                                                                            // no input argument
    334 };
    335 static inline _Istream_Cstr skip( char * s ) { return (_Istream_Cstr){ 0p, s, -1, false }; }
    336 static inline _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, false }; }
    337 static inline _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, false }; }
    338 static inline _Istream_Cstr cstr( char * s ) { return (_Istream_Cstr){ s, 0p, -1, false }; }
    339 static inline _Istream_Cstr ignore( char * s ) { return (_Istream_Cstr)@{ s, 0p, -1, true }; }
    340 static inline _Istream_Cstr ignore( _Istream_Cstr & fmt ) { fmt.ignore = true; return fmt; }
    341 static inline _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, false }; }
     334        union {
     335                unsigned char all;
     336                struct {
     337                        unsigned char ignore:1;                                         // do not change input argument
     338                        unsigned char inex:1;                                           // include/exclude characters in scanset
     339                } flags;
     340        };
     341}; // _Istream_Cstr
     342
     343static inline _Istream_Cstr skip( const char * scanset ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
     344static inline _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; }
     345static inline _Istream_Cstr incl( const char * scanset, _Istream_Cstr & fmt ) { fmt.flags.inex = false; return fmt; }
     346static inline _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; }
     347static inline _Istream_Cstr excl( const char * scanset, _Istream_Cstr & fmt ) { fmt.flags.inex = true; return fmt; }
     348static inline _Istream_Cstr cstr( char * s ) { return (_Istream_Cstr){ s, 0p, -1, { .all : 0 } }; }
     349static inline _Istream_Cstr ignore( const char * s ) { return (_Istream_Cstr)@{ s, 0p, -1, { .flags.ignore : true } }; }
     350static inline _Istream_Cstr ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; }
     351static inline _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; }
     352static inline _Istream_Cstr wd( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
    342353forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_Cstr );
    343 
    344 //*********************************** Manipulators ***********************************
    345354
    346355forall( otype T )
     
    348357        T & val;                                                                                        // polymorphic base-type
    349358        int wd;                                                                                         // width
    350         bool ignore;                                                                            // no input argument
     359        bool ignore;                                                                            // do not change input argument
    351360}; // _Istream_Manip
    352361
    353362#define InputFMTDecl( T ) \
    354 static inline _Istream_Manip(T) ignore( T & v ) { return (_Istream_Manip(T))@{ v, -1, true }; } \
     363static inline _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \
    355364static inline _Istream_Manip(T) ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
    356 static inline _Istream_Manip(T) wd( unsigned int w, T & v ) { return (_Istream_Manip(T))@{ v, w, false }; } \
     365static inline _Istream_Manip(T) wd( unsigned int w, T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \
    357366forall( dtype istype | istream( istype ) ) { \
    358367        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
    359 }
     368} // ?|?
    360369
    361370InputFMTDecl( char )
     
    378387InputFMTDecl( double _Complex )
    379388InputFMTDecl( long double _Complex )
    380 #endif // 0
    381389
    382390
Note: See TracChangeset for help on using the changeset viewer.