Changeset ae63a18 for src/examples/iostream.c
- Timestamp:
- Dec 18, 2015, 2:56:11 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 8762501
- Parents:
- baf7fee (diff), c23f807 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/iostream.c
rbaf7fee rae63a18 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 20 13:19:19201513 // Update Count : 912 // Last Modified On : Mon Dec 7 23:08:02 2015 13 // Update Count : 24 14 14 // 15 15 … … 21 21 22 22 forall( dtype ostype | ostream( ostype ) ) 23 ostype * ? <<?( ostype *os, char c ) {23 ostype * ?|?( ostype *os, char c ) { 24 24 return write( os, &c, 1 ); 25 } // ? <<?25 } // ?|? 26 26 27 27 forall( dtype ostype | ostream( ostype ) ) 28 ostype * ? <<?( ostype *os, int i ) {28 ostype * ?|?( ostype *os, int i ) { 29 29 char buffer[32]; // larger than the largest integer 30 30 sprintf( buffer, "%d", i ); 31 31 return write( os, buffer, strlen( buffer ) ); 32 } // ? <<?32 } // ?|? 33 33 34 34 forall( dtype ostype | ostream( ostype ) ) 35 ostype * ? <<?( ostype *os, double d ) {35 ostype * ?|?( ostype *os, double d ) { 36 36 char buffer[32]; // larger than the largest double 37 37 sprintf( buffer, "%g", d ); 38 38 return write( os, buffer, strlen( buffer ) ); 39 } // ? <<?39 } // ?|? 40 40 41 41 forall( dtype ostype | ostream( ostype ) ) 42 ostype * ? <<?( ostype *os, const char *cp ) {42 ostype * ?|?( ostype *os, const char *cp ) { 43 43 return write( os, cp, strlen( cp ) ); 44 } // ? <<?44 } // ?|? 45 45 46 46 forall( dtype ostype | ostream( ostype ) ) 47 ostype * ? <<?( ostype *os, const void *p ) {47 ostype * ?|?( ostype *os, const void *p ) { 48 48 char buffer[32]; // larger than the largest pointer 49 49 sprintf( buffer, "%p", p ); 50 50 return write( os, buffer, strlen( buffer ) ); 51 } // ?<<? 51 } // ?|? 52 53 54 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) 55 retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) { 56 return manip(os); 57 } 58 59 forall( dtype ostype | ostream( ostype ) ) 60 ostype * endl( ostype * os ) { 61 os | "\n"; 62 // flush 63 return os; 64 } // endl 52 65 53 66 forall( type elt_type | writeable( elt_type ), … … 56 69 void write( iterator_type begin, iterator_type end, os_type *os ) { 57 70 void print( elt_type i ) { 58 os << i <<' ';71 os | i | ' '; 59 72 } 60 73 for_each( begin, end, print ); 61 } // ? <<?74 } // ?|? 62 75 63 76 forall( type elt_type | writeable( elt_type ), … … 65 78 dtype os_type | ostream( os_type ) ) 66 79 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 67 void print( elt_type i ) { 68 os << i << ' '; 69 } 80 void print( elt_type i ) { os | i | ' '; } 70 81 for_each_reverse( begin, end, print ); 71 } // ? <<?82 } // ?|? 72 83 73 84 74 85 forall( dtype istype | istream( istype ) ) 75 istype * ? >>?( istype *is, char *cp ) {86 istype * ?|?( istype *is, char *cp ) { 76 87 return read( is, cp, 1 ); 77 } // ? >>?88 } // ?|? 78 89 79 90 forall( dtype istype | istream( istype ) ) 80 istype * ? >>?( istype *is, int *ip ) {91 istype * ?|?( istype *is, int *ip ) { 81 92 char cur; 82 93 83 94 // skip some whitespace 84 95 do { 85 is >>&cur;96 is | &cur; 86 97 if ( fail( is ) || eof( is ) ) return is; 87 98 } while ( !( cur >= '0' && cur <= '9' ) ); … … 91 102 while ( cur >= '0' && cur <= '9' ) { 92 103 *ip = *ip * 10 + ( cur - '0' ); 93 is >>&cur;104 is | &cur; 94 105 if ( fail( is ) || eof( is ) ) return is; 95 106 } … … 97 108 unread( is, cur ); 98 109 return is; 99 } // ? >>?110 } // ?|? 100 111 101 112 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.