Changes in / [8edbe40:50f6afb]
- Files:
-
- 4 added
- 5 edited
-
libcfa/src/Makefile.am (modified) (2 diffs)
-
libcfa/src/fstream.cfa (modified) (6 diffs)
-
libcfa/src/fstream.hfa (modified) (8 diffs)
-
libcfa/src/iostream.cfa (modified) (11 diffs)
-
libcfa/src/iostream.hfa (modified) (10 diffs)
-
libcfa/src/strstream.cfa (added)
-
libcfa/src/strstream.hfa (added)
-
tests/.expect/strstream.txt (added)
-
tests/strstream.cfa (added)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r8edbe40 r50f6afb 11 11 ## Created On : Sun May 31 08:54:01 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Wed Dec 9 22:46:14 202014 ## Update Count : 25 013 ## Last Modified On : Sat Apr 24 09:09:56 2021 14 ## Update Count : 254 15 15 ############################################################################### 16 16 … … 69 69 common.hfa \ 70 70 fstream.hfa \ 71 strstream.hfa \ 71 72 heap.hfa \ 72 73 iostream.hfa \ -
libcfa/src/fstream.cfa
r8edbe40 r50f6afb 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 20 19:04:46 202113 // Update Count : 42 512 // Last Modified On : Sat Apr 24 09:05:16 2021 13 // Update Count : 426 14 14 // 15 15 … … 19 19 #include <stdlib.h> // exit 20 20 #include <stdarg.h> // varargs 21 #include <string.h> // strlen 22 #include <float.h> // DBL_DIG, LDBL_DIG 23 #include <complex.h> // creal, cimag 21 #include <string.h> // strncpy, strerror 24 22 #include <assert.h> 25 23 #include <errno.h> // errno … … 93 91 void sepSet( ofstream & os, const char s[] ) { 94 92 assert( s ); 95 strncpy( os.separator$, s, sepSize - 1 );96 os.separator$[ sepSize - 1] = '\0';93 strncpy( os.separator$, s, ofstream_sepSize - 1 ); 94 os.separator$[ofstream_sepSize - 1] = '\0'; 97 95 } // sepSet 98 96 … … 100 98 void sepSetTuple( ofstream & os, const char s[] ) { 101 99 assert( s ); 102 strncpy( os.tupleSeparator$, s, sepSize - 1 );103 os.tupleSeparator$[ sepSize - 1] = '\0';100 strncpy( os.tupleSeparator$, s, ofstream_sepSize - 1 ); 101 os.tupleSeparator$[ofstream_sepSize - 1] = '\0'; 104 102 } // sepSet 105 103 … … 112 110 } // ends 113 111 114 intfail( ofstream & os ) {112 bool fail( ofstream & os ) { 115 113 return os.file$ == 0 || ferror( (FILE *)(os.file$) ); 116 114 } // fail … … 228 226 bool getANL( ifstream & os ) { return os.nlOnOff$; } 229 227 230 intfail( ifstream & is ) {228 bool fail( ifstream & is ) { 231 229 return is.file$ == 0p || ferror( (FILE *)(is.file$) ); 232 230 } // fail -
libcfa/src/fstream.hfa
r8edbe40 r50f6afb 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 20 19:04:12202113 // Update Count : 21 812 // Last Modified On : Sat Apr 24 09:04:03 2021 13 // Update Count : 219 14 14 // 15 15 … … 24 24 25 25 26 enum { sepSize = 16 };26 enum { ofstream_sepSize = 16 }; 27 27 struct ofstream { 28 28 void * file$; … … 33 33 bool sawNL$; 34 34 const char * sepCur$; 35 char separator$[ sepSize];36 char tupleSeparator$[ sepSize];35 char separator$[ofstream_sepSize]; 36 char tupleSeparator$[ofstream_sepSize]; 37 37 multiple_acquisition_lock lock$; 38 38 bool acquired$; 39 39 }; // ofstream 40 41 // Satisfies ostream 40 42 41 43 // private … … 64 66 void sepSetTuple( ofstream &, const char [] ); 65 67 66 void ends( ofstream & os ); 67 int fail( ofstream & ); 68 void ends( ofstream & ); 69 int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 70 71 bool fail( ofstream & ); 68 72 int flush( ofstream & ); 69 73 void open( ofstream &, const char name[], const char mode[] ); … … 71 75 void close( ofstream & ); 72 76 ofstream & write( ofstream &, const char data[], size_t size ); 73 int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 74 void acquire( ofstream & os);75 void release( ofstream & os);77 78 void acquire( ofstream & ); 79 void release( ofstream & ); 76 80 77 81 struct osacquire { 78 82 ofstream & os; 79 83 }; 80 void ?{}( osacquire & acq, ofstream & os);84 void ?{}( osacquire & acq, ofstream & ); 81 85 void ^?{}( osacquire & acq ); 82 86 83 void ?{}( ofstream & os);84 void ?{}( ofstream & os, const char name[], const char mode[] );85 void ?{}( ofstream & os, const char name[] );86 void ^?{}( ofstream & os);87 void ?{}( ofstream & ); 88 void ?{}( ofstream &, const char name[], const char mode[] ); 89 void ?{}( ofstream &, const char name[] ); 90 void ^?{}( ofstream & ); 87 91 88 92 extern ofstream & sout, & stdout, & serr, & stderr; // aliases … … 100 104 }; // ifstream 101 105 106 // Satisfies istream 107 102 108 // public 103 109 void nlOn( ifstream & ); … … 105 111 bool getANL( ifstream & ); 106 112 void ends( ifstream & ); 107 intfail( ifstream & is );113 bool fail( ifstream & is ); 108 114 int eof( ifstream & is ); 109 115 void open( ifstream & is, const char name[], const char mode[] ); … … 142 148 ); 143 149 144 void ?{}( Open_Failure & this, ofstream & ostream);145 void ?{}( Open_Failure & this, ifstream & istream);150 void ?{}( Open_Failure & this, ofstream & ); 151 void ?{}( Open_Failure & this, ifstream & ); 146 152 147 153 // Local Variables: // -
libcfa/src/iostream.cfa
r8edbe40 r50f6afb 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 20 19:09:41202113 // Update Count : 132 512 // Last Modified On : Sat Apr 24 10:03:54 2021 13 // Update Count : 1329 14 14 // 15 15 … … 36 36 37 37 38 forall( ostype & | ostream( ostype ) ) {38 forall( ostype & | basic_ostream( ostype ) ) { 39 39 ostype & ?|?( ostype & os, bool b ) { 40 40 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); … … 294 294 295 295 // last character IS spacing or opening punctuation => turn off separator for next item 296 size_t len = strlen( s );296 int len = strlen( s ); 297 297 ch = s[len - 1]; // must make unsigned 298 fmt( os, "%s", s ); // fmt resets seperator, but reset it again 298 299 if ( sepPrt$( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 299 300 sepOn( os ); … … 302 303 } // if 303 304 if ( ch == '\n' ) setNL$( os, true ); // check *AFTER* sepPrt$ call above as it resets NL flag 304 return write( os, s, len ); 305 return os; 306 // return write( os, s, len ); 305 307 } // ?|? 306 308 void ?|?( ostype & os, const char s[] ) { … … 397 399 return os; 398 400 } // nlOff 399 401 } // distribution 402 403 forall( ostype & | ostream( ostype ) ) { 400 404 ostype & acquire( ostype & os ) { 401 405 acquire( os ); // call void returning … … 445 449 // Default prefix for non-decimal prints is 0b, 0, 0x. 446 450 #define IntegralFMTImpl( T, IFMTNP, IFMTP ) \ 447 forall( ostype & | ostream( ostype ) ) { \451 forall( ostype & | basic_ostream( ostype ) ) { \ 448 452 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 449 453 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \ … … 539 543 #if defined( __SIZEOF_INT128__ ) 540 544 // Default prefix for non-decimal prints is 0b, 0, 0x. 541 forall( ostype & | ostream( ostype ) )545 forall( ostype & | basic_ostream( ostype ) ) 542 546 static inline void base_128( ostype & os, unsigned int128 val, unsigned int128 power, _Ostream_Manip(uint64_t) & f, unsigned int maxdig, unsigned int bits, unsigned int cnt = 0 ) { 543 547 int wd = 1; // f.wd is never 0 because 0 implies left-pad … … 604 608 605 609 #define IntegralFMTImpl128( T ) \ 606 forall( ostype & | ostream( ostype ) ) { \610 forall( ostype & | basic_ostream( ostype ) ) { \ 607 611 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ 608 612 _Ostream_Manip(uint64_t) fmt; \ … … 677 681 678 682 #define FloatingPointFMTImpl( T, DFMTNP, DFMTP ) \ 679 forall( ostype & | ostream( ostype ) ) { \683 forall( ostype & | basic_ostream( ostype ) ) { \ 680 684 static void eng( T &value, int & pc, int & exp10 ) { \ 681 685 exp10 = lrint( floor( log10( abs( value ) ) ) ); /* round to desired precision */ \ … … 723 727 // *********************************** character *********************************** 724 728 725 forall( ostype & | ostream( ostype ) ) {729 forall( ostype & | basic_ostream( ostype ) ) { 726 730 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) { 727 731 if ( f.base != 'c' ) { // bespoke binary/octal/hex format … … 756 760 // *********************************** C string *********************************** 757 761 758 forall( ostype & | ostream( ostype ) ) {762 forall( ostype & | basic_ostream( ostype ) ) { 759 763 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) { 760 764 if ( ! f.val ) return os; // null pointer ? -
libcfa/src/iostream.hfa
r8edbe40 r50f6afb 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 20 19:09:44202113 // Update Count : 3 8512 // Last Modified On : Sat Apr 24 09:28:56 2021 13 // Update Count : 393 14 14 // 15 15 … … 22 22 23 23 24 trait ostream( ostype & ) {24 trait basic_ostream( ostype & ) { 25 25 // private 26 26 bool sepPrt$( ostype & ); // get separator state (on/off) … … 47 47 void sepSetTuple( ostype &, const char [] ); // set tuple separator to string (15 character maximum) 48 48 49 void ends( ostype & os );// end of output statement50 int f ail( ostype &);49 void ends( ostype & ); // end of output statement 50 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 51 51 int flush( ostype & ); 52 void open( ostype & os, const char name[], const char mode[] ); 53 void close( ostype & os ); 52 }; // basic_ostream 53 54 trait ostream( ostype & | basic_ostream( ostype ) ) { 55 bool fail( ostype & ); // operation failed? 56 void open( ostype &, const char name[], const char mode[] ); 57 void close( ostype & ); 54 58 ostype & write( ostype &, const char [], size_t ); 55 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); 56 void acquire( ostype & ); 59 void acquire( ostype & ); // concurrent access 57 60 }; // ostream 58 61 … … 67 70 // implement writable for intrinsic types 68 71 69 forall( ostype & | ostream( ostype ) ) {72 forall( ostype & | basic_ostream( ostype ) ) { 70 73 ostype & ?|?( ostype &, bool ); 71 74 void ?|?( ostype &, bool ); … … 138 141 ostype & nlOn( ostype & ); 139 142 ostype & nlOff( ostype & ); 143 } // distribution 144 145 forall( ostype & | ostream( ostype ) ) { 140 146 ostype & acquire( ostype & ); 141 147 } // distribution … … 196 202 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 197 203 } /* distribution */ \ 198 forall( ostype & | ostream( ostype ) ) { \204 forall( ostype & | basic_ostream( ostype ) ) { \ 199 205 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 200 206 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 241 247 _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 242 248 } /* distribution */ \ 243 forall( ostype & | ostream( ostype ) ) { \249 forall( ostype & | basic_ostream( ostype ) ) { \ 244 250 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 245 251 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ … … 261 267 _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 262 268 } // distribution 263 forall( ostype & | ostream( ostype ) ) {269 forall( ostype & | basic_ostream( ostype ) ) { 264 270 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 265 271 void ?|?( ostype & os, _Ostream_Manip(char) f ); … … 279 285 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 280 286 } // distribution 281 forall( ostype & | ostream( ostype ) ) {287 forall( ostype & | basic_ostream( ostype ) ) { 282 288 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 283 289 void ?|?( ostype & os, _Ostream_Manip(const char *) f ); … … 294 300 295 301 void ends( istype & os ); // end of output statement 296 intfail( istype & );302 bool fail( istype & ); 297 303 int eof( istype & ); 298 304 void open( istype & is, const char name[] );
Note:
See TracChangeset
for help on using the changeset viewer.