Changeset e474cf09 for libcfa/src


Ignore:
Timestamp:
Mar 2, 2021, 5:21:35 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
10dafa4
Parents:
0f9c010b
Message:

add concurrency lock to IO stream and provide user interface to lock stream

Location:
libcfa/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r0f9c010b re474cf09  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 19 16:24:54 2020
    13 // Update Count     : 384
     12// Last Modified On : Mon Mar  1 21:12:15 2021
     13// Update Count     : 424
    1414//
    1515
     
    2525#include <errno.h>                                                                              // errno
    2626
    27 
    2827// *********************************** ofstream ***********************************
    2928
     
    3837        os.$prt = false;
    3938        os.$sawNL = false;
     39        os.$acquired = false;
    4040        $sepSetCur( os, sepGet( os ) );
    4141        sepSet( os, " " );
     
    109109        if ( &os == &exit ) exit( EXIT_FAILURE );
    110110        if ( &os == &abort ) abort();
     111        if ( os.$acquired ) { os.$acquired = false; release( os ); }
    111112} // ends
    112113
     
    171172} // fmt
    172173
     174inline void acquire( ofstream & os ) {
     175        lock( os.$lock );
     176        if ( ! os.$acquired ) os.$acquired = true;
     177        else unlock( os.$lock );
     178} // acquire
     179
     180inline void release( ofstream & os ) {
     181        unlock( os.$lock );
     182} // release
     183
     184void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.$lock ); }
     185void ^?{}( osacquire & acq ) { release( acq.os ); }
     186
    173187static ofstream soutFile = { (FILE *)stdout };
    174188ofstream & sout = soutFile, & stdout = soutFile;
     
    176190ofstream & serr = serrFile, & stderr = serrFile;
    177191
     192static ofstream lsoutFile = { (FILE *)stdout };
     193ofstream & lsout = lsoutFile;
     194
    178195static ofstream exitFile = { (FILE *)stdout };
    179196ofstream & exit = exitFile;
     
    189206        is.$file = file;
    190207        is.$nlOnOff = false;
     208        is.$acquired = false;
    191209} // ?{}
    192210
     
    213231        return is.$file == 0p || ferror( (FILE *)(is.$file) );
    214232} // fail
     233
     234void ends( ifstream & is ) {
     235        if ( is.$acquired ) { is.$acquired = false; release( is ); }
     236} // ends
    215237
    216238int eof( ifstream & is ) {
     
    279301} // fmt
    280302
     303inline void acquire( ifstream & is ) {
     304        lock( is.$lock );
     305        if ( ! is.$acquired ) is.$acquired = true;
     306        else unlock( is.$lock );
     307} // acquire
     308
     309inline void release( ifstream & is ) {
     310        unlock( is.$lock );
     311} // release
     312
     313void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.$lock ); }
     314void ^?{}( isacquire & acq ) { release( acq.is ); }
     315
    281316static ifstream sinFile = { (FILE *)stdin };
    282317ifstream & sin = sinFile, & stdin = sinFile;
  • libcfa/src/fstream.hfa

    r0f9c010b re474cf09  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 19 16:29:17 2020
    13 // Update Count     : 189
     12// Last Modified On : Mon Mar  1 22:45:08 2021
     13// Update Count     : 217
    1414//
    1515
    1616#pragma once
    1717
    18 #include "bits/weakso_locks.hfa"
     18#include "bits/weakso_locks.hfa"                                                // mutex_lock
    1919#include "iostream.hfa"
    2020#include <exception.hfa>
     
    3535        char $separator[sepSize];
    3636        char $tupleSeparator[sepSize];
    37 //      multiple_acquisition_lock lock;
     37        multiple_acquisition_lock $lock;
     38        bool $acquired;
    3839}; // ofstream
    3940
     
    7172ofstream & write( ofstream &, const char data[], size_t size );
    7273int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
     74void acquire( ofstream & os );
     75void release( ofstream & os );
     76
     77struct osacquire {
     78        ofstream & os;
     79};
     80void ?{}( osacquire & acq, ofstream & os );
     81void ^?{}( osacquire & acq );
    7382
    7483void ?{}( ofstream & os );
     
    8796        void * $file;
    8897        bool $nlOnOff;
     98        multiple_acquisition_lock $lock;
     99        bool $acquired;
    89100}; // ifstream
    90101
     
    93104void nlOff( ifstream & );
    94105bool getANL( ifstream & );
     106void ends( ifstream & );
    95107int fail( ifstream & is );
    96108int eof( ifstream & is );
     
    101113ifstream & ungetc( ifstream & is, char c );
    102114int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     115void acquire( ifstream & is );
     116void release( ifstream & is );
     117
     118struct isacquire {
     119        ifstream & is;
     120};
     121void ?{}( isacquire & acq, ifstream & is );
     122void ^?{}( isacquire & acq );
    103123
    104124void ?{}( ifstream & is );
  • libcfa/src/iostream.cfa

    r0f9c010b re474cf09  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 24 08:31:35 2020
    13 // Update Count     : 1130
     12// Last Modified On : Tue Mar  2 14:51:30 2021
     13// Update Count     : 1151
    1414//
    1515
     
    266266        } // ?|?
    267267
    268         ostype & ?|?( ostype & os, const char str[] ) {
     268        ostype & ?|?( ostype & os, const char s[] ) {
    269269                enum { Open = 1, Close, OpenClose };
    270270                static const unsigned char mask[256] @= {
     
    282282                }; // mask
    283283
    284           if ( str[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
     284          if ( s[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
    285285
    286286                // first character IS NOT spacing or closing punctuation => add left separator
    287                 unsigned char ch = str[0];                                              // must make unsigned
     287                unsigned char ch = s[0];                                                // must make unsigned
    288288                if ( $sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
    289289                        fmt( os, "%s", $sepGetCur( os ) );
     
    294294
    295295                // last character IS spacing or opening punctuation => turn off separator for next item
    296                 size_t len = strlen( str );
    297                 ch = str[len - 1];                                                              // must make unsigned
     296                size_t len = strlen( s );
     297                ch = s[len - 1];                                                                // must make unsigned
    298298                if ( $sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
    299299                        sepOn( os );
     
    302302                } // if
    303303                if ( ch == '\n' ) $setNL( os, true );                   // check *AFTER* $sepPrt call above as it resets NL flag
    304                 return write( os, str, len );
    305         } // ?|?
    306 
    307         void ?|?( ostype & os, const char str[] ) {
    308                 (ostype &)(os | str); ends( os );
    309         } // ?|?
    310 
    311 //      ostype & ?|?( ostype & os, const char16_t * str ) {
     304                return write( os, s, len );
     305        } // ?|?
     306        void ?|?( ostype & os, const char s[] ) {
     307                (ostype &)(os | s); ends( os );
     308        } // ?|?
     309
     310//      ostype & ?|?( ostype & os, const char16_t * s ) {
    312311//              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    313 //              fmt( os, "%ls", str );
     312//              fmt( os, "%ls", s );
    314313//              return os;
    315314//      } // ?|?
    316315
    317316// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
    318 //      ostype & ?|?( ostype & os, const char32_t * str ) {
     317//      ostype & ?|?( ostype & os, const char32_t * s ) {
    319318//              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    320 //              fmt( os, "%ls", str );
     319//              fmt( os, "%ls", s );
    321320//              return os;
    322321//      } // ?|?
    323322// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
    324323
    325 //      ostype & ?|?( ostype & os, const wchar_t * str ) {
     324//      ostype & ?|?( ostype & os, const wchar_t * s ) {
    326325//              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) );
    327 //              fmt( os, "%ls", str );
     326//              fmt( os, "%ls", s );
    328327//              return os;
    329328//      } // ?|?
     
    340339        // manipulators
    341340        ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    342                 (ostype &)(manip( os ));
    343                 return os;
     341                return manip( os );
    344342        } // ?|?
    345343        void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    346                 (ostype &)(manip( os ));
     344                manip( os );
    347345                if ( $getPrt( os ) ) ends( os );                                // something printed ?
    348346                $setPrt( os, false );                                                   // turn off
     
    399397                return os;
    400398        } // nlOff
     399
     400        ostype & acquire( ostype & os ) {
     401                acquire( os );                                                                  // call void returning
     402                return os;
     403        } // acquire
    401404} // distribution
    402405
     
    517520                return os; \
    518521        } /* ?|? */ \
    519         void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \
     522        void ?|?( ostype & os, _Ostream_Manip(T) f ) { \
     523                (ostype &)(os | f); ends( os ); \
     524        } /* ?|? */ \
    520525} // distribution
    521526
     
    894899                return is;
    895900        } // ?|?
     901        void ?|?( istype & is, bool & b ) {
     902                (istype &)(is | b); ends( is );
     903        } // ?|?
    896904
    897905        istype & ?|?( istype & is, char & c ) {
     
    905913                return is;
    906914        } // ?|?
     915        void ?|?( istype & is, char & c ) {
     916                (istype &)(is | c); ends( is );
     917        } // ?|?
    907918
    908919        istype & ?|?( istype & is, signed char & sc ) {
     
    910921                return is;
    911922        } // ?|?
     923        void ?|?( istype & is, signed char & sc ) {
     924                (istype &)(is | sc); ends( is );
     925        } // ?|?
    912926
    913927        istype & ?|?( istype & is, unsigned char & usc ) {
     
    915929                return is;
    916930        } // ?|?
     931        void ?|?( istype & is, unsigned char & usc ) {
     932                (istype &)(is | usc); ends( is );
     933        } // ?|?
    917934
    918935        istype & ?|?( istype & is, short int & si ) {
     
    920937                return is;
    921938        } // ?|?
     939        void ?|?( istype & is, short int & si ) {
     940                (istype &)(is | si); ends( is );
     941        } // ?|?
    922942
    923943        istype & ?|?( istype & is, unsigned short int & usi ) {
     
    925945                return is;
    926946        } // ?|?
     947        void ?|?( istype & is, unsigned short int & usi ) {
     948                (istype &)(is | usi); ends( is );
     949        } // ?|?
    927950
    928951        istype & ?|?( istype & is, int & i ) {
     
    930953                return is;
    931954        } // ?|?
     955        void ?|?( istype & is, int & i ) {
     956                (istype &)(is | i); ends( is );
     957        } // ?|?
    932958
    933959        istype & ?|?( istype & is, unsigned int & ui ) {
     
    935961                return is;
    936962        } // ?|?
     963        void ?|?( istype & is, unsigned int & ui ) {
     964                (istype &)(is | ui); ends( is );
     965        } // ?|?
    937966
    938967        istype & ?|?( istype & is, long int & li ) {
     
    940969                return is;
    941970        } // ?|?
     971        void ?|?( istype & is, long int & li ) {
     972                (istype &)(is | li); ends( is );
     973        } // ?|?
    942974
    943975        istype & ?|?( istype & is, unsigned long int & ulli ) {
     
    945977                return is;
    946978        } // ?|?
     979        void ?|?( istype & is, unsigned long int & ulli ) {
     980                (istype &)(is | ulli); ends( is );
     981        } // ?|?
    947982
    948983        istype & ?|?( istype & is, long long int & lli ) {
     
    950985                return is;
    951986        } // ?|?
     987        void ?|?( istype & is, long long int & lli ) {
     988                (istype &)(is | lli); ends( is );
     989        } // ?|?
    952990
    953991        istype & ?|?( istype & is, unsigned long long int & ulli ) {
     
    955993                return is;
    956994        } // ?|?
     995        void & ?|?( istype & is, unsigned long long int & ulli ) {
     996                (istype &)(is | ulli); ends( is );
     997        } // ?|?
    957998
    958999#if defined( __SIZEOF_INT128__ )
    959         istype & ?|?( istype & is, int128 & i128 ) {
    960                 return (istype &)(is | (unsigned int128 &)i128);
    961         } // ?|?
    962 
    963         istype & ?|?( istype & is, unsigned int128 & ui128 ) {
     1000        istype & ?|?( istype & is, int128 & llli ) {
     1001                return (istype &)(is | (unsigned int128 &)llli);
     1002        } // ?|?
     1003        void ?|?( istype & is, int128 & llli ) {
     1004                (istype &)(is | llli); ends( is );
     1005        } // ?|?
     1006
     1007        istype & ?|?( istype & is, unsigned int128 & ullli ) {
    9641008                char s[40];
    9651009                bool sign = false;
     
    9681012                // If the input is too large, the value returned is undefined. If there is no input, no value is returned
    9691013                if ( fmt( is, "%39[0-9]%*[0-9]", s ) == 1 ) {   // take first 39 characters, ignore remaining
    970                         ui128 = 0;
     1014                        ullli = 0;
    9711015                        for ( unsigned int i = 0; s[i] != '\0'; i += 1 ) {
    972                                 ui128 = ui128 * 10 + s[i] - '0';
     1016                                ullli = ullli * 10 + s[i] - '0';
    9731017                        } // for
    974                         if ( sign ) ui128 = -ui128;
     1018                        if ( sign ) ullli = -ullli;
    9751019                } else if ( sign ) ungetc( is, '-' );                   // return minus when no digits
    9761020                return is;
     1021        } // ?|?
     1022        void ?|?( istype & is, unsigned int128 & ullli ) {
     1023                (istype &)(is | ullli); ends( is );
    9771024        } // ?|?
    9781025#endif // __SIZEOF_INT128__
     
    9821029                return is;
    9831030        } // ?|?
     1031        void ?|?( istype & is, float & f ) {
     1032                (istype &)(is | f); ends( is );
     1033        } // ?|?
    9841034
    9851035        istype & ?|?( istype & is, double & d ) {
     
    9871037                return is;
    9881038        } // ?|?
     1039        void ?|?( istype & is, double & d ) {
     1040                (istype &)(is | d); ends( is );
     1041        } // ?|?
    9891042
    9901043        istype & ?|?( istype & is, long double & ld ) {
     
    9921045                return is;
    9931046        } // ?|?
    994 
     1047        void ?|?( istype & is, long double & ld ) {
     1048                (istype &)(is | ld); ends( is );
     1049        } // ?|?
    9951050
    9961051        istype & ?|?( istype & is, float _Complex & fc ) {
     
    10001055                return is;
    10011056        } // ?|?
     1057        void ?|?( istype & is, float _Complex & fc ) {
     1058                (istype &)(is | fc); ends( is );
     1059        } // ?|?
    10021060
    10031061        istype & ?|?( istype & is, double _Complex & dc ) {
     
    10071065                return is;
    10081066        } // ?|?
     1067        void ?|?( istype & is, double _Complex & dc ) {
     1068                (istype &)(is | dc); ends( is );
     1069        } // ?|?
    10091070
    10101071        istype & ?|?( istype & is, long double _Complex & ldc ) {
     
    10141075                return is;
    10151076        } // ?|?
     1077        void ?|?( istype & is, long double _Complex & ldc ) {
     1078                (istype &)(is | ldc); ends( is );
     1079        } // ?|?
    10161080
    10171081        // istype & ?|?( istype & is, const char fmt[] ) {
     
    10201084        // } // ?|?
    10211085
    1022         istype & ?|?( istype & is, char * s ) {
     1086        istype & ?|?( istype & is, char s[] ) {
    10231087                fmt( is, "%s", s );
    10241088                return is;
     1089        } // ?|?
     1090        void ?|?( istype & is, char s[] ) {
     1091                (istype &)(is | s); ends( is );
    10251092        } // ?|?
    10261093
     
    10291096                return manip( is );
    10301097        } // ?|?
     1098        void ?|?( istype & is, istype & (* manip)( istype & ) ) {
     1099                manip( is ); ends( is );
     1100        } // ?|?
    10311101
    10321102        istype & nl( istype & is ) {
     
    10441114                return is;
    10451115        } // nlOff
     1116
     1117        istype & acquire( istype & is ) {
     1118                acquire( is );                                                                  // call void returning
     1119                return is;
     1120        } // acquire
    10461121} // distribution
    10471122
    10481123// *********************************** manipulators ***********************************
    10491124
    1050 forall( istype & | istream( istype ) )
    1051 istype & ?|?( istype & is, _Istream_Cstr f ) {
    1052         // skip xxx
    1053         if ( ! f.s ) {
    1054                 // printf( "skip %s %d\n", f.scanset, f.wd );
    1055                 if ( f.wd == -1 ) fmt( is, f.scanset, "" );             // no input arguments
    1056                 else for ( f.wd ) fmt( is, "%*c" );
    1057                 return is;
    1058         } // if
    1059         size_t len = 0;
    1060         if ( f.scanset ) len = strlen( f.scanset );
    1061         char fmtstr[len + 16];
    1062         int start = 1;
    1063         fmtstr[0] = '%';
    1064         if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
    1065         if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
    1066         // cstr %s, %*s, %ws, %*ws
    1067         if ( ! f.scanset ) {
    1068                 fmtstr[start] = 's'; fmtstr[start + 1] = '\0';
    1069                 // printf( "cstr %s\n", fmtstr );
     1125forall( istype & | istream( istype ) ) {
     1126        istype & ?|?( istype & is, _Istream_Cstr f ) {
     1127                // skip xxx
     1128                if ( ! f.s ) {
     1129                        // printf( "skip %s %d\n", f.scanset, f.wd );
     1130                        if ( f.wd == -1 ) fmt( is, f.scanset, "" );             // no input arguments
     1131                        else for ( f.wd ) fmt( is, "%*c" );
     1132                        return is;
     1133                } // if
     1134                size_t len = 0;
     1135                if ( f.scanset ) len = strlen( f.scanset );
     1136                char fmtstr[len + 16];
     1137                int start = 1;
     1138                fmtstr[0] = '%';
     1139                if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
     1140                if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
     1141                // cstr %s, %*s, %ws, %*ws
     1142                if ( ! f.scanset ) {
     1143                        fmtstr[start] = 's'; fmtstr[start + 1] = '\0';
     1144                        // printf( "cstr %s\n", fmtstr );
     1145                        fmt( is, fmtstr, f.s );
     1146                        return is;
     1147                } // if
     1148                // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
     1149                // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
     1150                fmtstr[start] = '['; start += 1;
     1151                if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
     1152                strcpy( &fmtstr[start], f.scanset );                            // copy includes '\0'
     1153                len += start;
     1154                fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
     1155                // printf( "incl/excl %s\n", fmtstr );
    10701156                fmt( is, fmtstr, f.s );
    10711157                return is;
    1072         } // if
    1073         // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
    1074         // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
    1075         fmtstr[start] = '['; start += 1;
    1076         if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
    1077         strcpy( &fmtstr[start], f.scanset );                            // copy includes '\0'
    1078         len += start;
    1079         fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
    1080         // printf( "incl/excl %s\n", fmtstr );
    1081         fmt( is, fmtstr, f.s );
    1082         return is;
    1083 } // ?|?
    1084 
    1085 forall( istype & | istream( istype ) )
    1086 istype & ?|?( istype & is, _Istream_Char f ) {
    1087         fmt( is, "%*c" );                                                                       // argument variable unused
    1088         return is;
    1089 } // ?|?
     1158        } // ?|?
     1159        void ?|?( istype & is, _Istream_Cstr f ) {
     1160                (istype &)(is | f); ends( is );
     1161        } // ?|?
     1162
     1163        istype & ?|?( istype & is, _Istream_Char f ) {
     1164                fmt( is, "%*c" );                                                                       // argument variable unused
     1165                return is;
     1166        } // ?|?
     1167        void ?|?( istype & is, _Istream_Char f ) {
     1168                (istype &)(is | f); ends( is );
     1169        } // ?|?
     1170} // distribution
    10901171
    10911172#define InputFMTImpl( T, CODE ) \
    1092 forall( istype & | istream( istype ) ) \
    1093 istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
    1094         enum { size = 16 }; \
    1095         char fmtstr[size]; \
    1096         if ( f.wd == -1 ) { \
    1097                 snprintf( fmtstr, size, "%%%s%s", f.ignore ? "*" : "", CODE ); \
    1098         } else { \
    1099                 snprintf( fmtstr, size, "%%%s%d%s", f.ignore ? "*" : "", f.wd, CODE ); \
    1100         } /* if */ \
    1101         /* printf( "%d %s %p\n", f.wd, fmtstr, &f.val ); */ \
    1102         fmt( is, fmtstr, &f.val ); \
    1103         return is; \
    1104 } // ?|?
     1173forall( istype & | istream( istype ) ) { \
     1174        istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
     1175                enum { size = 16 }; \
     1176                char fmtstr[size]; \
     1177                if ( f.wd == -1 ) { \
     1178                        snprintf( fmtstr, size, "%%%s%s", f.ignore ? "*" : "", CODE ); \
     1179                } else { \
     1180                        snprintf( fmtstr, size, "%%%s%d%s", f.ignore ? "*" : "", f.wd, CODE ); \
     1181                } /* if */ \
     1182                /* printf( "%d %s %p\n", f.wd, fmtstr, &f.val ); */ \
     1183                fmt( is, fmtstr, &f.val ); \
     1184                return is; \
     1185        } /* ?|? */ \
     1186        void ?|?( istype & is, _Istream_Manip(T) f ) { \
     1187                (istype &)(is | f); ends( is ); \
     1188        } /* ?|? */ \
     1189} // distribution
    11051190
    11061191InputFMTImpl( signed char, "hhi" )
     
    11191204InputFMTImpl( long double, "Lf" )
    11201205
    1121 forall( istype & | istream( istype ) )
    1122 istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
    1123         float re, im;
    1124         _Istream_Manip(float) fmtuc @= { re, fc.wd, fc.ignore };
    1125         is | fmtuc;
    1126         &fmtuc.val = &im;
    1127         is | fmtuc;
    1128         if ( ! fc.ignore ) fc.val = re + im * _Complex_I;       // re/im are uninitialized for ignore
    1129         return is;
    1130 } // ?|?
    1131 
    1132 forall( istype & | istream( istype ) )
    1133 istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
    1134         double re, im;
    1135         _Istream_Manip(double) fmtuc @= { re, dc.wd, dc.ignore };
    1136         is | fmtuc;
    1137         &fmtuc.val = &im;
    1138         is | fmtuc;
    1139         if ( ! dc.ignore ) dc.val = re + im * _Complex_I;       // re/im are uninitialized for ignore
    1140         return is;
    1141 } // ?|?
    1142 
    1143 forall( istype & | istream( istype ) )
    1144 istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
    1145         long double re, im;
    1146         _Istream_Manip(long double) fmtuc @= { re, ldc.wd, ldc.ignore };
    1147         is | fmtuc;
    1148         &fmtuc.val = &im;
    1149         is | fmtuc;
    1150         if ( ! ldc.ignore ) ldc.val = re + im * _Complex_I;     // re/im are uninitialized for ignore
    1151         return is;
    1152 } // ?|?
     1206forall( istype & | istream( istype ) ) {
     1207        istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
     1208                float re, im;
     1209                _Istream_Manip(float) fmtuc @= { re, fc.wd, fc.ignore };
     1210                is | fmtuc;
     1211                &fmtuc.val = &im;
     1212                is | fmtuc;
     1213                if ( ! fc.ignore ) fc.val = re + im * _Complex_I; // re/im are uninitialized for ignore
     1214                return is;
     1215        } // ?|?
     1216        void ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
     1217                (istype &)(is | fc); ends( is );
     1218        } // ?|?
     1219
     1220        istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
     1221                double re, im;
     1222                _Istream_Manip(double) fmtuc @= { re, dc.wd, dc.ignore };
     1223                is | fmtuc;
     1224                &fmtuc.val = &im;
     1225                is | fmtuc;
     1226                if ( ! dc.ignore ) dc.val = re + im * _Complex_I; // re/im are uninitialized for ignore
     1227                return is;
     1228        } // ?|?
     1229        void ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
     1230                (istype &)(is | dc); ends( is );
     1231        } // ?|?
     1232
     1233        istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
     1234                long double re, im;
     1235                _Istream_Manip(long double) fmtuc @= { re, ldc.wd, ldc.ignore };
     1236                is | fmtuc;
     1237                &fmtuc.val = &im;
     1238                is | fmtuc;
     1239                if ( ! ldc.ignore ) ldc.val = re + im * _Complex_I;     // re/im are uninitialized for ignore
     1240                return is;
     1241        } // ?|?
     1242        void ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
     1243                (istype &)(is | ldc); ends( is );
     1244        } // ?|?
     1245} // distribution
    11531246
    11541247// Local Variables: //
  • libcfa/src/iostream.hfa

    r0f9c010b re474cf09  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 22:16:14 2020
    13 // Update Count     : 350
     12// Last Modified On : Tue Mar  2 14:05:08 2021
     13// Update Count     : 369
    1414//
    1515
     
    5454        ostype & write( ostype &, const char [], size_t );
    5555        int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
     56        void acquire( ostype & );
    5657}; // ostream
    5758
     
    137138        ostype & nlOn( ostype & );
    138139        ostype & nlOff( ostype & );
     140        ostype & acquire( ostype & );
    139141} // distribution
    140142
     
    285287        void nlOff( istype & );                                                         // scan newline
    286288        bool getANL( istype & );                                                        // get scan newline (on/off)
     289
     290        void ends( istype & os );                                                       // end of output statement
    287291        int fail( istype & );
    288292        int eof( istype & );
     
    292296        istype & ungetc( istype &, char );
    293297        int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     298        void acquire( istype & );
    294299}; // istream
    295300
     
    300305forall( istype & | istream( istype ) ) {
    301306        istype & ?|?( istype &, bool & );
     307        void ?|?( istype &, bool & );
    302308
    303309        istype & ?|?( istype &, char & );
     310        void ?|?( istype &, char & );
    304311        istype & ?|?( istype &, signed char & );
     312        void ?|?( istype &, signed char & );
    305313        istype & ?|?( istype &, unsigned char & );
     314        void ?|?( istype &, unsigned char & );
    306315
    307316        istype & ?|?( istype &, short int & );
     317        void ?|?( istype &, short int & );
    308318        istype & ?|?( istype &, unsigned short int & );
     319        void ?|?( istype &, unsigned short int & );
    309320        istype & ?|?( istype &, int & );
     321        void ?|?( istype &, int & );
    310322        istype & ?|?( istype &, unsigned int & );
     323        void ?|?( istype &, unsigned int & );
    311324        istype & ?|?( istype &, long int & );
     325        void ?|?( istype &, long int & );
    312326        istype & ?|?( istype &, unsigned long int & );
     327        void ?|?( istype &, unsigned long int & );
    313328        istype & ?|?( istype &, long long int & );
     329        void ?|?( istype &, long long int & );
    314330        istype & ?|?( istype &, unsigned long long int & );
     331        void ?|?( istype &, unsigned long long int & );
    315332#if defined( __SIZEOF_INT128__ )
    316333        istype & ?|?( istype &, int128 & );
     334        void ?|?( istype &, int128 & );
    317335        istype & ?|?( istype &, unsigned int128 & );
     336        void ?|?( istype &, unsigned int128 & );
    318337#endif // __SIZEOF_INT128__
    319338
    320339        istype & ?|?( istype &, float & );
     340        void ?|?( istype &, float & );
    321341        istype & ?|?( istype &, double & );
     342        void ?|?( istype &, double & );
    322343        istype & ?|?( istype &, long double & );
     344        void ?|?( istype &, long double & );
    323345
    324346        istype & ?|?( istype &, float _Complex & );
     347        void ?|?( istype &, float _Complex & );
    325348        istype & ?|?( istype &, double _Complex & );
     349        void ?|?( istype &, double _Complex & );
    326350        istype & ?|?( istype &, long double _Complex & );
     351        void ?|?( istype &, long double _Complex & );
    327352
    328353//      istype & ?|?( istype &, const char [] );
    329         istype & ?|?( istype &, char * );
     354        istype & ?|?( istype &, char [] );
     355        void ?|?( istype &, char [] );
    330356
    331357        // manipulators
    332358        istype & ?|?( istype &, istype & (*)( istype & ) );
     359        void ?|?( istype &, istype & (*)( istype & ) );
    333360        istype & nl( istype & is );
    334361        istype & nlOn( istype & );
    335362        istype & nlOff( istype & );
     363        istype & acquire( istype & );
    336364} // distribution
    337365
     
    363391        _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
    364392} // distribution
    365 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
     393forall( istype & | istream( istype ) ) {
     394        istype & ?|?( istype & is, _Istream_Cstr f );
     395        void ?|?( istype & is, _Istream_Cstr f );
     396}
    366397
    367398struct _Istream_Char {
     
    373404        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    374405} // distribution
    375 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
     406forall( istype & | istream( istype ) ) {
     407        istype & ?|?( istype & is, _Istream_Char f );
     408        void ?|?( istype & is, _Istream_Char f );
     409}
    376410
    377411forall( T & | sized( T ) )
     
    391425forall( istype & | istream( istype ) ) { \
    392426        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
     427        void ?|?( istype & is, _Istream_Manip(T) f ); \
    393428} // ?|?
    394429
Note: See TracChangeset for help on using the changeset viewer.