// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // iostream.hfa -- // // Author : Peter A. Buhr // Created On : Wed May 27 17:56:53 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Sun Oct 13 10:49:40 2024 // Update Count : 765 // #pragma once #include "iterator.hfa" #include "Exception.hfa" // *********************************** ostream *********************************** forall( ostype & ) trait basic_ostream { // private bool sepPrt$( ostype & ); // get separator state (on/off) void sepReset$( ostype & ); // set separator state to default state void sepReset$( ostype &, bool ); // set separator and default state const char * sepGetCur$( ostype & ); // get current separator string void sepSetCur$( ostype &, const char [] ); // set current separator string bool getNL$( ostype & ); // get newline bool setNL$( ostype &, bool ); // set newline bool getANL$( ostype & ); // get auto newline (on/off) bool setANL$( ostype &, bool ); // set auto newline (on/off), and return previous state bool getPrt$( ostype & ); // get fmt called in output cascade bool setPrt$( ostype &, bool ); // set fmt called in output cascade // public void nlOn( ostype & ); // turn auto-newline state on void nlOff( ostype & ); // turn auto-newline state off void sep( ostype & ); // turn separator state on void nosep( ostype & ); // turn separator state off bool sepOn( ostype & ); // set default state to on, and return previous state bool sepOff( ostype & ); // set default state to off, and return previous state const char * sepGet( ostype & ); // get separator string void sepSet( ostype &, const char [] ); // set separator to string (15 character maximum) const char * sepGetTuple( ostype & ); // get tuple separator string void sepSetTuple( ostype &, const char [] ); // set tuple separator to string (15 character maximum) void ends( ostype & ); // end of output statement int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); }; // basic_ostream forall( ostype & | basic_ostream( ostype ) ) trait ostream { bool fail( ostype & ); // operation failed? void clear( ostype & ); int flush( ostype & ); void open( ostype &, const char name[], const char mode[] ); void close( ostype & ); ostype & write( ostype &, const char [], size_t ); }; // ostream // forall( T ) // trait writeable { // forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype &, T ); // }; // writeable forall( T, ostype & | ostream( ostype ) ) trait writeable { ostype & ?|?( ostype &, T ); }; // writeable // implement writable for intrinsic types #define OSTYPE_VOID( T ) void ?|?( ostype &, T ) #define OSTYPE_VOID_IMPL( os, T ) \ void ?|?( ostype & os, T t ) { \ (ostype &)(os | t); ends( os ); \ } // ?|? forall( ostype & | basic_ostream( ostype ) ) { ostype & ?|?( ostype &, bool ); OSTYPE_VOID( bool ); ostype & ?|?( ostype &, char ); OSTYPE_VOID( char ); ostype & ?|?( ostype &, signed char ); OSTYPE_VOID( signed char ); ostype & ?|?( ostype &, unsigned char ); OSTYPE_VOID( unsigned char ); ostype & ?|?( ostype &, short int ); OSTYPE_VOID( short int ); ostype & ?|?( ostype &, unsigned short int ); OSTYPE_VOID( unsigned short int ); ostype & ?|?( ostype &, int ); OSTYPE_VOID( int ); ostype & ?|?( ostype &, unsigned int ); OSTYPE_VOID( unsigned int ); ostype & ?|?( ostype &, long int ); OSTYPE_VOID( long int ); ostype & ?|?( ostype &, long long int ); OSTYPE_VOID( long long int ); ostype & ?|?( ostype &, unsigned long int ); OSTYPE_VOID( unsigned long int ); ostype & ?|?( ostype &, unsigned long long int ); OSTYPE_VOID( unsigned long long int ); #if defined( __SIZEOF_INT128__ ) ostype & ?|?( ostype &, int128 ); OSTYPE_VOID( int128 ); ostype & ?|?( ostype &, unsigned int128 ); OSTYPE_VOID( unsigned int128 ); #endif // __SIZEOF_INT128__ ostype & ?|?( ostype &, float ); OSTYPE_VOID( float ); ostype & ?|?( ostype &, double ); OSTYPE_VOID( double ); ostype & ?|?( ostype &, long double ); OSTYPE_VOID( long double ); ostype & ?|?( ostype &, float _Complex ); OSTYPE_VOID( float _Complex ); ostype & ?|?( ostype &, double _Complex ); OSTYPE_VOID( double _Complex ); ostype & ?|?( ostype &, long double _Complex ); OSTYPE_VOID( long double _Complex ); ostype & ?|?( ostype &, const char [] ); OSTYPE_VOID( const char [] ); // ostype & ?|?( ostype &, const char16_t [] ); #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous // ostype & ?|?( ostype &, const char32_t [] ); #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // ostype & ?|?( ostype &, const wchar_t [] ); ostype & ?|?( ostype &, const void * ); OSTYPE_VOID( const void * ); // FIX-ME: does not work so using macros // forall( T | { ostype & ?|?( ostype &, T ); } ) // void ?|?( ostype & os, T ); // manipulators ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); OSTYPE_VOID( ostype & (*)( ostype & ) ); ostype & nl( ostype & ); ostype & nonl( ostype & ); ostype & nlOn( ostype & ); ostype & nlOff( ostype & ); ostype & sepVal( ostype & ); ostype & sepTupleVal( ostype & ); ostype & sep( ostype & ); ostype & nosep( ostype & ); ostype & sepOn( ostype & ); ostype & sepOff( ostype & ); } // distribution // tuples forall( ostype &, T, List ... | writeable( T, ostype ) | { ostype & ?|?( ostype &, List ); } ) { ostype & ?|?( ostype & os, T arg, List rest ); void ?|?( ostype & os, T arg, List rest ); } // distribution // writes the range [begin, end) to the given stream forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) { void write( iterator_type begin, iterator_type end, ostype & os ); void write_reverse( iterator_type begin, iterator_type end, ostype & os ); } // distribution // *********************************** manipulators *********************************** struct _Ostream_Flags { unsigned char eng:1; // engineering notation unsigned char neg:1; // val is negative unsigned char pc:1; // precision specified unsigned char left:1; // left justify unsigned char nobsdp:1; // base prefix / decimal point unsigned char sign:1; // plus / minus sign unsigned char pad0:1; // zero pad }; forall( T ) struct _Ostream_Manip { T val; // polymorphic base-type int wd, pc; // width, precision: signed for computations char base; // numeric base / floating-point style union { unsigned char all; _Ostream_Flags flags; }; }; // _Ostream_Manip // *********************************** integral *********************************** #define INTEGRAL_FMT_DECL( T, CODE ) \ static inline { \ _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'b', { .all = 0 } }; } \ _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'o', { .all = 0 } }; } \ _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'x', { .all = 0 } }; } \ _Ostream_Manip(T) wd( unsigned int wd, T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = wd, .pc = 0, .base = CODE, { .all = 0 } }; } \ _Ostream_Manip(T) wd( unsigned int wd, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = wd, .pc = pc, .base = CODE, { .flags.pc = true } }; } \ _Ostream_Manip(T) & wd( unsigned int wd, _Ostream_Manip(T) & fmt ) { fmt.wd = wd; return fmt; } \ _Ostream_Manip(T) & wd( unsigned int wd, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \ _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \ _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = CODE, { .flags.sign = true } }; } \ _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ } /* distribution */ \ forall( ostype & | basic_ostream( ostype ) ) { \ ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ OSTYPE_VOID( _Ostream_Manip(T) ); \ } // ?|? INTEGRAL_FMT_DECL( signed char, 'd' ) INTEGRAL_FMT_DECL( unsigned char, 'u' ) INTEGRAL_FMT_DECL( signed short int, 'd' ) INTEGRAL_FMT_DECL( unsigned short int, 'u' ) INTEGRAL_FMT_DECL( signed int, 'd' ) INTEGRAL_FMT_DECL( unsigned int, 'u' ) INTEGRAL_FMT_DECL( signed long int, 'd' ) INTEGRAL_FMT_DECL( unsigned long int, 'u' ) INTEGRAL_FMT_DECL( signed long long int, 'd' ) INTEGRAL_FMT_DECL( unsigned long long int, 'u' ) #if defined( __SIZEOF_INT128__ ) INTEGRAL_FMT_DECL( int128, 'd' ) INTEGRAL_FMT_DECL( unsigned int128, 'u' ) #endif // __SIZEOF_INT128__ // *********************************** floating point *********************************** // Default suffix for values with no fraction is "." #define FLOATING_POINT_FMT_DECL( T ) \ static inline { \ _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'a', { .all = 0 } }; } \ _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'e', { .all = 0 } }; } \ _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ .val = val, 1, -1, .base = 'g', { .flags.eng = true } }; } \ _Ostream_Manip(T) wd( unsigned int wd, T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = wd, .pc = 0, .base = 'g', { .all = 0 } }; } \ _Ostream_Manip(T) wd( unsigned int wd, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = wd, .pc = pc, .base = 'f', { .flags.pc = true } }; } \ _Ostream_Manip(T) ws( unsigned int wd, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = wd, .pc = pc, .base = 'g', { .flags.pc = true } }; } \ _Ostream_Manip(T) & wd( unsigned int wd, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = wd; return fmt; } \ _Ostream_Manip(T) & wd( unsigned int wd, unsigned int pc, _Ostream_Manip(T) & fmt ) { \ if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ _Ostream_Manip(T) & ws( unsigned int wd, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'G', { .all = 0 } }; } \ _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \ _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \ _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'g', { .flags.sign = true } }; } \ _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'g', { .flags.nobsdp = true } }; } \ _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ .val = val, .wd = 1, .pc = 0, .base = 'g', { .flags.nobsdp = true } }; } \ _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ } /* distribution */ \ forall( ostype & | basic_ostream( ostype ) ) { \ ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ OSTYPE_VOID( _Ostream_Manip(T) ); \ } // ?|? FLOATING_POINT_FMT_DECL( double ) FLOATING_POINT_FMT_DECL( long double ) // *********************************** character *********************************** static inline { _Ostream_Manip(char) bin( char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'b', { .all = 0 } }; } _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'o', { .all = 0 } }; } _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ .val = c, .wd = 1, .pc = 0, .base = 'x', { .all = 0 } }; } _Ostream_Manip(char) wd( unsigned int wd, char c ) { return (_Ostream_Manip(char))@{ c, wd, 0, .base = 'c', { .all = 0 } }; } _Ostream_Manip(char) & wd( unsigned int wd, _Ostream_Manip(char) & fmt ) { fmt.wd = wd; return fmt; } _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; } _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; } } // distribution forall( ostype & | basic_ostream( ostype ) ) { ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); OSTYPE_VOID( _Ostream_Manip(char) ); \ } // ?|? // *********************************** C string *********************************** static inline { _Ostream_Manip(const char *) bin( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 'b', { .all = 0 } }; } _Ostream_Manip(const char *) oct( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 'o', { .all = 0 } }; } _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val = s, .wd = 1, .pc = 0, .base = 'x', { .all = 0 } }; } _Ostream_Manip(const char *) wd( unsigned int wd, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, wd, 0, .base = 's', { .all = 0 } }; } _Ostream_Manip(const char *) wd( unsigned int wd, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, .wd = wd, .pc = pc, .base = 's', { .flags.pc = true } }; } _Ostream_Manip(const char *) & wd( unsigned int wd, _Ostream_Manip(const char *) & fmt ) { fmt.wd = wd; return fmt; } _Ostream_Manip(const char *) & wd( unsigned int wd, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; } _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } } // distribution forall( ostype & | basic_ostream( ostype ) ) { ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); OSTYPE_VOID( _Ostream_Manip(const char *) ); \ } // ?|? // *********************************** istream *********************************** forall( istype & ) trait basic_istream { // private bool getANL$( istype & ); // get scan newline (on/off) bool setANL$( istype &, bool ); // set scan newline (on/off) // public void nlOn( istype & ); // read newline void nlOff( istype & ); // scan newline int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); istype & ungetc( char, istype & ); bool eof( istype & ); void clear( istype & ); }; // basic_istream forall( istype & | basic_istream( istype ) ) trait istream { bool fail( istype & ); void open( istype & is, const char name[], const char mode[] ); void open( istype & is, const char name[] ); void close( istype & is ); istype & read( istype &, char [], size_t ); }; // istream forall( T ) trait readable { forall( istype & | istream( istype ) ) istype & ?|?( istype &, T ); }; // readable forall( istype & | basic_istream( istype ) ) { istype & ?|?( istype &, bool & ); istype & ?|?( istype &, char & ); istype & ?|?( istype &, signed char & ); istype & ?|?( istype &, unsigned char & ); istype & ?|?( istype &, short int & ); istype & ?|?( istype &, unsigned short int & ); istype & ?|?( istype &, int & ); istype & ?|?( istype &, unsigned int & ); istype & ?|?( istype &, long int & ); istype & ?|?( istype &, unsigned long int & ); istype & ?|?( istype &, long long int & ); istype & ?|?( istype &, unsigned long long int & ); #if defined( __SIZEOF_INT128__ ) istype & ?|?( istype &, int128 & ); istype & ?|?( istype &, unsigned int128 & ); #endif // __SIZEOF_INT128__ istype & ?|?( istype &, float & ); istype & ?|?( istype &, double & ); istype & ?|?( istype &, long double & ); istype & ?|?( istype &, float _Complex & ); istype & ?|?( istype &, double _Complex & ); istype & ?|?( istype &, long double _Complex & ); // This is too restrictive as it prevents building a format in a string and using that format. // inline istype & ?|?( istype &, char [] ) { // possible error, too restrictive to change // _Static_assert( false, "reading a character array without a maximum length is unsafe. Use input manipulator \"wdi( N, s )\", where \"char s[N]\" or fmt( s )." ); // } istype & ?|?( istype &, const char [] ); // match text // manipulators istype & ?|?( istype &, istype & (*)( istype & ) ); istype & nl( istype & is ); istype & nlOn( istype & ); istype & nlOff( istype & ); } // distribution // *********************************** exceptions *********************************** ExceptionDecl( end_of_file ); // read encounters end of file ExceptionDecl( missing_data ); // read finds no appropriate data ExceptionDecl( cstring_length ); // character string size exceeded ExceptionDecl( data_range ); // value too large for numerical type // *********************************** manipulators *********************************** // skip does not compose with other C string manipulators. struct _Istream_Cskip { const char * scanset; unsigned wd; // scan width }; // _Istream_Cskip static inline { _Istream_Cskip skip( const char scanset[] ) { return (_Istream_Cskip)@{ .scanset = scanset, .wd = 0 }; } _Istream_Cskip skip( unsigned int wd ) { return (_Istream_Cskip)@{ .scanset = 0p, .wd = wd }; } } // distribution struct _Istream_str_base { union { const char * scanset; char delimiters[3]; // [0] => left, [1] => right }; int wd; // width union { unsigned char all; struct { unsigned char ignore:1; // do not change input argument unsigned char inex:1; // include/exclude characters in scanset unsigned char delimiter:1; // delimit character(s) unsigned char rwd:1; // read width } flags; }; }; // _Istream_str_base struct _Istream_Cwidth { char * s; inline _Istream_str_base; }; // _Istream_Cwidth // Restrict nesting of input manipulators to those combinations that make sense. struct _Istream_Cquoted { _Istream_Cwidth cstr; }; // _Istream_Cquoted struct _Istream_Cstr { _Istream_Cwidth cstr; }; // _Istream_Cstr static inline { // width must include room for null terminator, (gcc) scanf does not allow a 0 width => wd > 1 (1 char and null) and rd > 0 (1 char); _Istream_Cwidth wdi( unsigned int wd, char s[] ) { if ( wd <= 1 ) throwResume ExceptionInst( cstring_length ); // minimum 1 character and null terminator return (_Istream_Cwidth)@{ .s = s, { {.scanset = 0p}, .wd = wd, {.all = 0} } }; } _Istream_Cwidth wdi( unsigned int wd, unsigned int rwd, char s[] ) { if ( wd <= 1 || wd <= rwd ) throwResume ExceptionInst( cstring_length ); // minimum 1 character, null terminator, plus subset return (_Istream_Cwidth)@{ .s = s, { {.scanset = 0p}, .wd = rwd, {.flags.rwd = true} } }; } _Istream_Cstr & getline( _Istream_Cwidth & f, const char delimiter = '\n' ) { f.delimiters[0] = delimiter; f.delimiters[1] = '\0'; f.flags.delimiter = true; return (_Istream_Cstr &)f; } _Istream_Cquoted quoted( char & ch, const char Ldelimiter = '\'', const char Rdelimiter = '\0' ) { return (_Istream_Cquoted)@{ { .s = &ch, { {.delimiters = { Ldelimiter, Rdelimiter, '\1' }}, .wd = 1, {.flags.rwd = true} } } }; } _Istream_Cquoted & quoted( _Istream_Cwidth & f, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) { f.delimiters[0] = Ldelimiter; f.delimiters[1] = Rdelimiter; f.delimiters[2] = '\0'; return (_Istream_Cquoted &)f; } _Istream_Cstr & incl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = false; return (_Istream_Cstr &)f; } _Istream_Cstr & excl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = true; return (_Istream_Cstr &)f; } _Istream_Cstr ignore( const char s[] ) { return (_Istream_Cstr)@{ { .s = (char *)s, { {.scanset = 0p}, .wd = -1, {.flags.ignore = true} } } }; } _Istream_Cstr & ignore( _Istream_Cwidth & f ) { f.flags.ignore = true; return (_Istream_Cstr &)f; } _Istream_Cquoted & ignore( _Istream_Cquoted & f ) { f.cstr.flags.ignore = true; return (_Istream_Cquoted &)f; } _Istream_Cstr & ignore( _Istream_Cstr & f ) { f.cstr.flags.ignore = true; return (_Istream_Cstr &)f; } } // distribution forall( istype & | basic_istream( istype ) ) { istype & ?|?( istype & is, _Istream_Cskip f ); istype & ?|?( istype & is, _Istream_Cquoted f ); istype & ?|?( istype & is, _Istream_Cstr f ); static inline istype & ?|?( istype & is, _Istream_Cwidth f ) { return is | *(_Istream_Cstr *)&f; } } // distribution forall( T & | sized( T ) ) struct _Istream_Manip { T & val; // polymorphic base-type int wd; // width bool ignore; // do not change input argument }; // _Istream_Manip #define INPUT_FMT_DECL( T ) \ static inline { \ _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ .val = val, .wd = wd, .ignore = false }; } \ _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ .val = (T &)val, .wd = -1, .ignore = true }; } \ _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \ } /* distribution */ \ forall( istype & | basic_istream( istype ) ) { \ istype & ?|?( istype & is, _Istream_Manip(T) f ); \ } // ?|? INPUT_FMT_DECL( char ) INPUT_FMT_DECL( signed char ) INPUT_FMT_DECL( unsigned char ) INPUT_FMT_DECL( signed short int ) INPUT_FMT_DECL( unsigned short int ) INPUT_FMT_DECL( signed int ) INPUT_FMT_DECL( unsigned int ) INPUT_FMT_DECL( signed long int ) INPUT_FMT_DECL( unsigned long int ) INPUT_FMT_DECL( signed long long int ) INPUT_FMT_DECL( unsigned long long int ) INPUT_FMT_DECL( float ) INPUT_FMT_DECL( double ) INPUT_FMT_DECL( long double ) INPUT_FMT_DECL( float _Complex ) INPUT_FMT_DECL( double _Complex ) INPUT_FMT_DECL( long double _Complex ) // *********************************** time *********************************** #include // Duration (constructors) / Time (constructors) forall( ostype & | ostream( ostype ) ) { ostype & ?|?( ostype & os, Duration dur ); OSTYPE_VOID( Duration ); ostype & ?|?( ostype & os, Time time ); OSTYPE_VOID( Time ); } // distribution forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial(E) ) istype & ?|?( istype &, E & ); forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) { ostype & ?|?( ostype &, E ); OSTYPE_VOID( E ); } // Local Variables: // // tab-width: 4 // // End: //