[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 | // fstream -- |
---|
[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 |
---|
[a1a1f37d] | 12 | // Last Modified On : Fri Jul 12 05:45:50 2024 |
---|
| 13 | // Update Count : 275 |
---|
[86bd7c1f] | 14 | // |
---|
| 15 | |
---|
[53a6c2a] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[e474cf09] | 18 | #include "bits/weakso_locks.hfa" // mutex_lock |
---|
[58b6d1b] | 19 | #include "iostream.hfa" |
---|
[51b7345] | 20 | |
---|
[65240bb] | 21 | |
---|
[8d321f9] | 22 | // *********************************** ofstream *********************************** |
---|
[65240bb] | 23 | |
---|
| 24 | |
---|
[b431515] | 25 | enum { ofstream_sepSize = 16 }; |
---|
[53ba273] | 26 | struct ofstream { |
---|
[6c5d92f] | 27 | void * file$; |
---|
| 28 | bool sepDefault$; |
---|
| 29 | bool sepOnOff$; |
---|
| 30 | bool nlOnOff$; |
---|
| 31 | bool prt$; // print text |
---|
| 32 | bool sawNL$; |
---|
| 33 | const char * sepCur$; |
---|
[b431515] | 34 | char separator$[ofstream_sepSize]; |
---|
| 35 | char tupleSeparator$[ofstream_sepSize]; |
---|
[502a107] | 36 | multiple_acquisition_lock lock$; // used by trait is_lock for mutex statement |
---|
[53ba273] | 37 | }; // ofstream |
---|
[90c3b1c] | 38 | |
---|
[b431515] | 39 | // Satisfies ostream |
---|
| 40 | |
---|
[9ebd778] | 41 | // private |
---|
[f5d9c37] | 42 | bool getNL$( ofstream & ); |
---|
[d0cfcbe1] | 43 | bool setNL$( ofstream &, bool ); |
---|
[f5d9c37] | 44 | bool getANL$( ofstream & ); |
---|
[d0cfcbe1] | 45 | bool setANL$( ofstream &, bool ); |
---|
[f5d9c37] | 46 | |
---|
[6c5d92f] | 47 | bool sepPrt$( ofstream & ); |
---|
| 48 | void sepReset$( ofstream & ); |
---|
| 49 | void sepReset$( ofstream &, bool ); |
---|
| 50 | const char * sepGetCur$( ofstream & ); |
---|
| 51 | void sepSetCur$( ofstream &, const char [] ); |
---|
[f5d9c37] | 52 | |
---|
[6c5d92f] | 53 | bool getPrt$( ofstream & ); |
---|
[d0cfcbe1] | 54 | bool setPrt$( ofstream &, bool ); |
---|
[9ebd778] | 55 | |
---|
[7ce2483] | 56 | void lock( ofstream & ); |
---|
| 57 | void unlock( ofstream & ); |
---|
| 58 | |
---|
[9ebd778] | 59 | // public |
---|
[200fcb3] | 60 | void nlOn( ofstream & ); |
---|
| 61 | void nlOff( ofstream & ); |
---|
[9ebd778] | 62 | |
---|
[f5d9c37] | 63 | void sep( ofstream & ); |
---|
| 64 | void nosep( ofstream & ); |
---|
| 65 | bool sepOn( ofstream & ); |
---|
| 66 | bool sepOff( ofstream & ); |
---|
[09687aa] | 67 | const char * sepGet( ofstream & ); |
---|
[e3fea42] | 68 | void sepSet( ofstream &, const char [] ); |
---|
[09687aa] | 69 | const char * sepGetTuple( ofstream & ); |
---|
[e3fea42] | 70 | void sepSetTuple( ofstream &, const char [] ); |
---|
[6152c81] | 71 | |
---|
[b431515] | 72 | void ends( ofstream & ); |
---|
| 73 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
| 74 | |
---|
| 75 | bool fail( ofstream & ); |
---|
[00e9be9] | 76 | void clear( ofstream & ); |
---|
[09687aa] | 77 | int flush( ofstream & ); |
---|
[f451177] | 78 | void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" |
---|
[e3fea42] | 79 | void open( ofstream &, const char name[] ); |
---|
[09687aa] | 80 | void close( ofstream & ); |
---|
[c8371b5] | 81 | |
---|
[e3fea42] | 82 | ofstream & write( ofstream &, const char data[], size_t size ); |
---|
[b431515] | 83 | |
---|
| 84 | void ?{}( ofstream & ); |
---|
[f451177] | 85 | void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" |
---|
[b431515] | 86 | void ?{}( ofstream &, const char name[] ); |
---|
| 87 | void ^?{}( ofstream & ); |
---|
[09687aa] | 88 | |
---|
[f451177] | 89 | // private |
---|
| 90 | static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl |
---|
| 91 | // public |
---|
| 92 | ofstream & nl( ofstream & os ); // override basic_ostream nl |
---|
| 93 | |
---|
[a87d40b] | 94 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases |
---|
[65240bb] | 95 | extern ofstream & exit, & abort; |
---|
| 96 | |
---|
[51b7345] | 97 | |
---|
[8d321f9] | 98 | // *********************************** ifstream *********************************** |
---|
[5cb2b8c] | 99 | |
---|
[51b7345] | 100 | |
---|
[53ba273] | 101 | struct ifstream { |
---|
[6c5d92f] | 102 | void * file$; |
---|
| 103 | bool nlOnOff$; |
---|
[502a107] | 104 | multiple_acquisition_lock lock$; // used by trait is_lock for mutex statement |
---|
[53ba273] | 105 | }; // ifstream |
---|
[6ba0659] | 106 | |
---|
[b431515] | 107 | // Satisfies istream |
---|
| 108 | |
---|
[7ce2483] | 109 | // private |
---|
[c8371b5] | 110 | bool getANL$( ifstream & ); |
---|
[d0cfcbe1] | 111 | bool setANL$( ifstream &, bool ); |
---|
[c8371b5] | 112 | |
---|
[7ce2483] | 113 | void lock( ifstream & ); |
---|
| 114 | void unlock( ifstream & ); |
---|
| 115 | |
---|
[09687aa] | 116 | // public |
---|
[0efb269] | 117 | void nlOn( ifstream & ); |
---|
| 118 | void nlOff( ifstream & ); |
---|
[f451177] | 119 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); |
---|
[a1a1f37d] | 120 | ifstream & ungetc( char c, ifstream & is ); |
---|
[e0dc038] | 121 | bool eof( ifstream & is ); |
---|
[f451177] | 122 | |
---|
[b431515] | 123 | bool fail( ifstream & is ); |
---|
[00e9be9] | 124 | void clear( ifstream & ); |
---|
[f451177] | 125 | void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" |
---|
[e3fea42] | 126 | void open( ifstream & is, const char name[] ); |
---|
[09687aa] | 127 | void close( ifstream & is ); |
---|
[00e9be9] | 128 | ifstream & read( ifstream & is, char data[], size_t size ); |
---|
[f451177] | 129 | |
---|
[09687aa] | 130 | void ?{}( ifstream & is ); |
---|
[f451177] | 131 | void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" |
---|
[e3fea42] | 132 | void ?{}( ifstream & is, const char name[] ); |
---|
[4cae032] | 133 | void ^?{}( ifstream & is ); |
---|
[51b7345] | 134 | |
---|
[a87d40b] | 135 | extern ifstream & sin, & stdin; // aliases |
---|
[51b7345] | 136 | |
---|
[91e52be] | 137 | |
---|
[8d321f9] | 138 | // *********************************** exceptions *********************************** |
---|
[91e52be] | 139 | |
---|
| 140 | |
---|
[77bc259] | 141 | ExceptionDecl( open_failure, |
---|
[91e52be] | 142 | union { |
---|
| 143 | ofstream * ostream; |
---|
| 144 | ifstream * istream; |
---|
| 145 | }; |
---|
[8d321f9] | 146 | // TEMPORARY: need polymorphic exceptions |
---|
| 147 | int tag; // 1 => ostream; 0 => istream |
---|
[77bc259] | 148 | ); |
---|
[91e52be] | 149 | |
---|
[874b16e] | 150 | void ?{}( open_failure & this, ofstream & ); |
---|
| 151 | void ?{}( open_failure & this, ifstream & ); |
---|
[91e52be] | 152 | |
---|
[77bc259] | 153 | ExceptionDecl( close_failure, |
---|
[ba0d2ea] | 154 | union { |
---|
| 155 | ofstream * ostream; |
---|
| 156 | ifstream * istream; |
---|
| 157 | }; |
---|
| 158 | // TEMPORARY: need polymorphic exceptions |
---|
| 159 | int tag; // 1 => ostream; 0 => istream |
---|
[77bc259] | 160 | ); |
---|
[ba0d2ea] | 161 | |
---|
[874b16e] | 162 | void ?{}( close_failure & this, ofstream & ); |
---|
| 163 | void ?{}( close_failure & this, ifstream & ); |
---|
[ba0d2ea] | 164 | |
---|
[77bc259] | 165 | ExceptionDecl( write_failure, |
---|
[ba0d2ea] | 166 | union { |
---|
| 167 | ofstream * ostream; |
---|
| 168 | ifstream * istream; |
---|
| 169 | }; |
---|
| 170 | // TEMPORARY: need polymorphic exceptions |
---|
| 171 | int tag; // 1 => ostream; 0 => istream |
---|
[77bc259] | 172 | ); |
---|
[ba0d2ea] | 173 | |
---|
[874b16e] | 174 | void ?{}( write_failure & this, ofstream & ); |
---|
| 175 | void ?{}( write_failure & this, ifstream & ); |
---|
[ba0d2ea] | 176 | |
---|
[77bc259] | 177 | ExceptionDecl( read_failure, |
---|
[ba0d2ea] | 178 | union { |
---|
| 179 | ofstream * ostream; |
---|
| 180 | ifstream * istream; |
---|
| 181 | }; |
---|
| 182 | // TEMPORARY: need polymorphic exceptions |
---|
| 183 | int tag; // 1 => ostream; 0 => istream |
---|
[77bc259] | 184 | ); |
---|
[ba0d2ea] | 185 | |
---|
[874b16e] | 186 | void ?{}( read_failure & this, ofstream & ); |
---|
| 187 | void ?{}( read_failure & this, ifstream & ); |
---|
[ba0d2ea] | 188 | |
---|
[86bd7c1f] | 189 | // Local Variables: // |
---|
[d3b7937] | 190 | // mode: c // |
---|
[86bd7c1f] | 191 | // tab-width: 4 // |
---|
| 192 | // End: // |
---|