[86bd7c1f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[bb82c03] | 7 | // iostream -- |
---|
[86bd7c1f] | 8 | // |
---|
[90c3b1c] | 9 | // Author : Peter A. Buhr |
---|
[86bd7c1f] | 10 | // Created On : Wed May 27 17:56:53 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[c4b072c] | 12 | // Last Modified On : Fri May 3 22:55:04 2019 |
---|
| 13 | // Update Count : 230 |
---|
[86bd7c1f] | 14 | // |
---|
| 15 | |
---|
[53a6c2a] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[58b6d1b] | 18 | #include "iterator.hfa" |
---|
[e56cfdb0] | 19 | |
---|
[4040425] | 20 | trait ostream( dtype ostype ) { |
---|
[9ebd778] | 21 | // private |
---|
[9d362a0] | 22 | bool sepPrt( ostype & ); // get separator state (on/off) |
---|
[09687aa] | 23 | void sepReset( ostype & ); // set separator state to default state |
---|
[93c2e0a] | 24 | void sepReset( ostype &, bool ); // set separator and default state |
---|
[09687aa] | 25 | const char * sepGetCur( ostype & ); // get current separator string |
---|
| 26 | void sepSetCur( ostype &, const char * ); // set current separator string |
---|
[200fcb3] | 27 | bool getNL( ostype & ); // check newline |
---|
[93c2e0a] | 28 | void setNL( ostype &, bool ); // saw newline |
---|
[9d362a0] | 29 | bool getANL( ostype & ); // get auto newline (on/off) |
---|
| 30 | bool getPrt( ostype & ); // get fmt called in output cascade |
---|
| 31 | void setPrt( ostype &, bool ); // set fmt called in output cascade |
---|
[9ebd778] | 32 | // public |
---|
[09687aa] | 33 | void sepOn( ostype & ); // turn separator state on |
---|
| 34 | void sepOff( ostype & ); // turn separator state off |
---|
[93c2e0a] | 35 | bool sepDisable( ostype & ); // set default state to off, and return previous state |
---|
[200fcb3] | 36 | bool sepEnable( ostype & ); // set default state to on, and return previous state |
---|
| 37 | void nlOn( ostype & ); // turn auto-newline state on |
---|
| 38 | void nlOff( ostype & ); // turn auto-newline state off |
---|
[09687aa] | 39 | |
---|
| 40 | const char * sepGet( ostype & ); // get separator string |
---|
| 41 | void sepSet( ostype &, const char * ); // set separator to string (15 character maximum) |
---|
| 42 | const char * sepGetTuple( ostype & ); // get tuple separator string |
---|
| 43 | void sepSetTuple( ostype &, const char * ); // set tuple separator to string (15 character maximum) |
---|
| 44 | |
---|
| 45 | int fail( ostype & ); |
---|
| 46 | int flush( ostype & ); |
---|
| 47 | void open( ostype & os, const char * name, const char * mode ); |
---|
| 48 | void close( ostype & os ); |
---|
[7c919446] | 49 | ostype & write( ostype &, const char *, size_t ); |
---|
[c4b072c] | 50 | int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
[86f384b] | 51 | }; // ostream |
---|
[90c3b1c] | 52 | |
---|
[e1780a2] | 53 | // trait writeable( otype T ) { |
---|
[09687aa] | 54 | // forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T ); |
---|
[e1780a2] | 55 | // }; // writeable |
---|
| 56 | |
---|
| 57 | trait writeable( otype T, dtype ostype | ostream( ostype ) ) { |
---|
[09687aa] | 58 | ostype & ?|?( ostype &, T ); |
---|
[86f384b] | 59 | }; // writeable |
---|
[51b7345] | 60 | |
---|
[4e06c1e] | 61 | // implement writable for intrinsic types |
---|
[51b7345] | 62 | |
---|
[3ce0d440] | 63 | forall( dtype ostype | ostream( ostype ) ) { |
---|
[17a1b21] | 64 | ostype & ?|?( ostype &, zero_t ); |
---|
| 65 | void ?|?( ostype &, zero_t ); |
---|
| 66 | ostype & ?|?( ostype &, one_t ); |
---|
| 67 | void ?|?( ostype &, one_t ); |
---|
| 68 | |
---|
[93c2e0a] | 69 | ostype & ?|?( ostype &, bool ); |
---|
[5ea5b28] | 70 | void ?|?( ostype &, bool ); |
---|
[1e6e08de] | 71 | |
---|
[3ce0d440] | 72 | ostype & ?|?( ostype &, char ); |
---|
[5ea5b28] | 73 | void ?|?( ostype &, char ); |
---|
[3ce0d440] | 74 | ostype & ?|?( ostype &, signed char ); |
---|
[5ea5b28] | 75 | void ?|?( ostype &, signed char ); |
---|
[3ce0d440] | 76 | ostype & ?|?( ostype &, unsigned char ); |
---|
[5ea5b28] | 77 | void ?|?( ostype &, unsigned char ); |
---|
[09687aa] | 78 | |
---|
[3ce0d440] | 79 | ostype & ?|?( ostype &, short int ); |
---|
[5ea5b28] | 80 | void ?|?( ostype &, short int ); |
---|
[3ce0d440] | 81 | ostype & ?|?( ostype &, unsigned short int ); |
---|
[5ea5b28] | 82 | void ?|?( ostype &, unsigned short int ); |
---|
[3ce0d440] | 83 | ostype & ?|?( ostype &, int ); |
---|
[5ea5b28] | 84 | void ?|?( ostype &, int ); |
---|
[3ce0d440] | 85 | ostype & ?|?( ostype &, unsigned int ); |
---|
[5ea5b28] | 86 | void ?|?( ostype &, unsigned int ); |
---|
[3ce0d440] | 87 | ostype & ?|?( ostype &, long int ); |
---|
[5ea5b28] | 88 | void ?|?( ostype &, long int ); |
---|
[3ce0d440] | 89 | ostype & ?|?( ostype &, long long int ); |
---|
[5ea5b28] | 90 | void ?|?( ostype &, long long int ); |
---|
[3ce0d440] | 91 | ostype & ?|?( ostype &, unsigned long int ); |
---|
[5ea5b28] | 92 | void ?|?( ostype &, unsigned long int ); |
---|
[3ce0d440] | 93 | ostype & ?|?( ostype &, unsigned long long int ); |
---|
[5ea5b28] | 94 | void ?|?( ostype &, unsigned long long int ); |
---|
[09687aa] | 95 | |
---|
[3ce0d440] | 96 | ostype & ?|?( ostype &, float ); // FIX ME: should not be required |
---|
[5ea5b28] | 97 | void ?|?( ostype &, float ); // FIX ME: should not be required |
---|
[3ce0d440] | 98 | ostype & ?|?( ostype &, double ); |
---|
[5ea5b28] | 99 | void ?|?( ostype &, double ); |
---|
[3ce0d440] | 100 | ostype & ?|?( ostype &, long double ); |
---|
[5ea5b28] | 101 | void ?|?( ostype &, long double ); |
---|
[09687aa] | 102 | |
---|
[3ce0d440] | 103 | ostype & ?|?( ostype &, float _Complex ); |
---|
[5ea5b28] | 104 | void ?|?( ostype &, float _Complex ); |
---|
[3ce0d440] | 105 | ostype & ?|?( ostype &, double _Complex ); |
---|
[5ea5b28] | 106 | void ?|?( ostype &, double _Complex ); |
---|
[3ce0d440] | 107 | ostype & ?|?( ostype &, long double _Complex ); |
---|
[5ea5b28] | 108 | void ?|?( ostype &, long double _Complex ); |
---|
[09687aa] | 109 | |
---|
[3ce0d440] | 110 | ostype & ?|?( ostype &, const char * ); |
---|
[5ea5b28] | 111 | void ?|?( ostype &, const char * ); |
---|
[3ce0d440] | 112 | // ostype & ?|?( ostype &, const char16_t * ); |
---|
[0db817e] | 113 | #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous |
---|
[3ce0d440] | 114 | // ostype & ?|?( ostype &, const char32_t * ); |
---|
[0db817e] | 115 | #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) |
---|
[3ce0d440] | 116 | // ostype & ?|?( ostype &, const wchar_t * ); |
---|
| 117 | ostype & ?|?( ostype &, const void * ); |
---|
[5ea5b28] | 118 | void ?|?( ostype &, const void * ); |
---|
[3ce0d440] | 119 | |
---|
| 120 | // manipulators |
---|
| 121 | ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); |
---|
[200fcb3] | 122 | void ?|?( ostype &, ostype & (*)( ostype & ) ); |
---|
| 123 | ostype & nl( ostype & ); |
---|
[9d362a0] | 124 | void nl( ostype & ); |
---|
[200fcb3] | 125 | ostype & nonl( ostype & ); |
---|
[3ce0d440] | 126 | ostype & sep( ostype & ); |
---|
| 127 | ostype & sepTuple( ostype & ); |
---|
| 128 | ostype & sepOn( ostype & ); |
---|
| 129 | ostype & sepOff( ostype & ); |
---|
| 130 | ostype & sepDisable( ostype & ); |
---|
| 131 | ostype & sepEnable( ostype & ); |
---|
[200fcb3] | 132 | ostype & nlOn( ostype & ); |
---|
| 133 | ostype & nlOff( ostype & ); |
---|
[3ce0d440] | 134 | } // distribution |
---|
[cf16f94] | 135 | |
---|
[c443d1d] | 136 | // tuples |
---|
[200fcb3] | 137 | forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { |
---|
| 138 | ostype & ?|?( ostype & os, T arg, Params rest ); |
---|
| 139 | void ?|?( ostype & os, T arg, Params rest ); |
---|
| 140 | } // distribution |
---|
[c443d1d] | 141 | |
---|
[e56cfdb0] | 142 | // writes the range [begin, end) to the given stream |
---|
[200fcb3] | 143 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) { |
---|
| 144 | void write( iterator_type begin, iterator_type end, ostype & os ); |
---|
| 145 | void write_reverse( iterator_type begin, iterator_type end, ostype & os ); |
---|
| 146 | } // distribution |
---|
[51b7345] | 147 | |
---|
[6ba0659] | 148 | //--------------------------------------- |
---|
[51b7345] | 149 | |
---|
[4040425] | 150 | trait istream( dtype istype ) { |
---|
[0efb269] | 151 | void nlOn( istype & ); // read newline |
---|
| 152 | void nlOff( istype & ); // scan newline |
---|
| 153 | bool getANL( istype & ); // get scan newline (on/off) |
---|
[09687aa] | 154 | int fail( istype & ); |
---|
| 155 | int eof( istype & ); |
---|
| 156 | void open( istype & is, const char * name ); |
---|
| 157 | void close( istype & is ); |
---|
[9428d52] | 158 | istype & read( istype &, char *, size_t ); |
---|
[09687aa] | 159 | istype & ungetc( istype &, char ); |
---|
[c4b072c] | 160 | int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); |
---|
[86f384b] | 161 | }; // istream |
---|
[51b7345] | 162 | |
---|
[4040425] | 163 | trait readable( otype T ) { |
---|
[09687aa] | 164 | forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T ); |
---|
[86f384b] | 165 | }; // readable |
---|
[51b7345] | 166 | |
---|
[3ce0d440] | 167 | forall( dtype istype | istream( istype ) ) { |
---|
[93c2e0a] | 168 | istype & ?|?( istype &, bool & ); |
---|
[3ce0d440] | 169 | |
---|
| 170 | istype & ?|?( istype &, char & ); |
---|
| 171 | istype & ?|?( istype &, signed char & ); |
---|
| 172 | istype & ?|?( istype &, unsigned char & ); |
---|
| 173 | |
---|
| 174 | istype & ?|?( istype &, short int & ); |
---|
| 175 | istype & ?|?( istype &, unsigned short int & ); |
---|
| 176 | istype & ?|?( istype &, int & ); |
---|
| 177 | istype & ?|?( istype &, unsigned int & ); |
---|
| 178 | istype & ?|?( istype &, long int & ); |
---|
| 179 | istype & ?|?( istype &, long long int & ); |
---|
| 180 | istype & ?|?( istype &, unsigned long int & ); |
---|
| 181 | istype & ?|?( istype &, unsigned long long int & ); |
---|
| 182 | |
---|
| 183 | istype & ?|?( istype &, float & ); |
---|
| 184 | istype & ?|?( istype &, double & ); |
---|
| 185 | istype & ?|?( istype &, long double & ); |
---|
| 186 | |
---|
| 187 | istype & ?|?( istype &, float _Complex & ); |
---|
| 188 | istype & ?|?( istype &, double _Complex & ); |
---|
| 189 | istype & ?|?( istype &, long double _Complex & ); |
---|
| 190 | |
---|
| 191 | // manipulators |
---|
[0efb269] | 192 | istype & nlOn( istype & ); |
---|
| 193 | istype & nlOff( istype & ); |
---|
[3ce0d440] | 194 | istype & ?|?( istype &, istype & (*)( istype & ) ); |
---|
[200fcb3] | 195 | istype & nl( istype & is ); |
---|
[3ce0d440] | 196 | } // distribution |
---|
[44574f2] | 197 | |
---|
[53ba273] | 198 | struct _Istream_cstrUC { char * s; }; |
---|
| 199 | _Istream_cstrUC cstr( char * ); |
---|
[09687aa] | 200 | forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC ); |
---|
[51b7345] | 201 | |
---|
[53ba273] | 202 | struct _Istream_cstrC { char * s; int size; }; |
---|
| 203 | _Istream_cstrC cstr( char *, int size ); |
---|
[09687aa] | 204 | forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC ); |
---|
[51b7345] | 205 | |
---|
[10a97adb] | 206 | |
---|
[200fcb3] | 207 | #include <time_t.hfa> // Duration (constructors) / Time (constructors) |
---|
[10a97adb] | 208 | |
---|
[200fcb3] | 209 | forall( dtype ostype | ostream( ostype ) ) { |
---|
| 210 | ostype & ?|?( ostype & os, Duration dur ); |
---|
| 211 | void ?|?( ostype & os, Duration dur ); |
---|
| 212 | ostype & ?|?( ostype & os, Time time ); |
---|
| 213 | void ?|?( ostype & os, Time time ); |
---|
| 214 | } // distribution |
---|
[10a97adb] | 215 | |
---|
[86bd7c1f] | 216 | // Local Variables: // |
---|
[d3b7937] | 217 | // mode: c // |
---|
[86bd7c1f] | 218 | // tab-width: 4 // |
---|
| 219 | // End: // |
---|