[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 |
---|
[c8371b5] | 12 | // Last Modified On : Sun Oct 10 09:37:32 2021 |
---|
| 13 | // Update Count : 243 |
---|
[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]; |
---|
[6c5d92f] | 36 | multiple_acquisition_lock lock$; |
---|
[53ba273] | 37 | }; // ofstream |
---|
[90c3b1c] | 38 | |
---|
[b431515] | 39 | // Satisfies ostream |
---|
| 40 | |
---|
[9ebd778] | 41 | // private |
---|
[6c5d92f] | 42 | bool sepPrt$( ofstream & ); |
---|
| 43 | void sepReset$( ofstream & ); |
---|
| 44 | void sepReset$( ofstream &, bool ); |
---|
| 45 | const char * sepGetCur$( ofstream & ); |
---|
| 46 | void sepSetCur$( ofstream &, const char [] ); |
---|
| 47 | bool getNL$( ofstream & ); |
---|
| 48 | void setNL$( ofstream &, bool ); |
---|
| 49 | bool getANL$( ofstream & ); |
---|
| 50 | bool getPrt$( ofstream & ); |
---|
| 51 | void setPrt$( ofstream &, bool ); |
---|
[9ebd778] | 52 | |
---|
[7ce2483] | 53 | void lock( ofstream & ); |
---|
| 54 | void unlock( ofstream & ); |
---|
| 55 | |
---|
[9ebd778] | 56 | // public |
---|
[09687aa] | 57 | void sepOn( ofstream & ); |
---|
| 58 | void sepOff( ofstream & ); |
---|
[93c2e0a] | 59 | bool sepDisable( ofstream & ); |
---|
| 60 | bool sepEnable( ofstream & ); |
---|
[200fcb3] | 61 | void nlOn( ofstream & ); |
---|
| 62 | void nlOff( ofstream & ); |
---|
[9ebd778] | 63 | |
---|
[09687aa] | 64 | const char * sepGet( ofstream & ); |
---|
[e3fea42] | 65 | void sepSet( ofstream &, const char [] ); |
---|
[09687aa] | 66 | const char * sepGetTuple( ofstream & ); |
---|
[e3fea42] | 67 | void sepSetTuple( ofstream &, const char [] ); |
---|
[6152c81] | 68 | |
---|
[b431515] | 69 | void ends( ofstream & ); |
---|
| 70 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
| 71 | |
---|
| 72 | bool fail( ofstream & ); |
---|
[00e9be9] | 73 | void clear( ofstream & ); |
---|
[09687aa] | 74 | int flush( ofstream & ); |
---|
[f451177] | 75 | void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" |
---|
[e3fea42] | 76 | void open( ofstream &, const char name[] ); |
---|
[09687aa] | 77 | void close( ofstream & ); |
---|
[c8371b5] | 78 | |
---|
[e3fea42] | 79 | ofstream & write( ofstream &, const char data[], size_t size ); |
---|
[b431515] | 80 | |
---|
| 81 | void ?{}( ofstream & ); |
---|
[f451177] | 82 | void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" |
---|
[b431515] | 83 | void ?{}( ofstream &, const char name[] ); |
---|
| 84 | void ^?{}( ofstream & ); |
---|
[09687aa] | 85 | |
---|
[f451177] | 86 | // private |
---|
| 87 | static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl |
---|
| 88 | // public |
---|
| 89 | ofstream & nl( ofstream & os ); // override basic_ostream nl |
---|
| 90 | |
---|
[a87d40b] | 91 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases |
---|
[65240bb] | 92 | extern ofstream & exit, & abort; |
---|
| 93 | |
---|
[51b7345] | 94 | |
---|
[8d321f9] | 95 | // *********************************** ifstream *********************************** |
---|
[5cb2b8c] | 96 | |
---|
[51b7345] | 97 | |
---|
[53ba273] | 98 | struct ifstream { |
---|
[6c5d92f] | 99 | void * file$; |
---|
| 100 | bool nlOnOff$; |
---|
| 101 | multiple_acquisition_lock lock$; |
---|
[53ba273] | 102 | }; // ifstream |
---|
[6ba0659] | 103 | |
---|
[b431515] | 104 | // Satisfies istream |
---|
| 105 | |
---|
[7ce2483] | 106 | // private |
---|
[c8371b5] | 107 | bool getANL$( ifstream & ); |
---|
| 108 | |
---|
[7ce2483] | 109 | void lock( ifstream & ); |
---|
| 110 | void unlock( ifstream & ); |
---|
| 111 | |
---|
[09687aa] | 112 | // public |
---|
[0efb269] | 113 | void nlOn( ifstream & ); |
---|
| 114 | void nlOff( ifstream & ); |
---|
[e474cf09] | 115 | void ends( ifstream & ); |
---|
[f451177] | 116 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); |
---|
| 117 | |
---|
[b431515] | 118 | bool fail( ifstream & is ); |
---|
[00e9be9] | 119 | void clear( ifstream & ); |
---|
| 120 | bool eof( ifstream & is ); |
---|
[f451177] | 121 | void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" |
---|
[e3fea42] | 122 | void open( ifstream & is, const char name[] ); |
---|
[09687aa] | 123 | void close( ifstream & is ); |
---|
[c8371b5] | 124 | |
---|
[00e9be9] | 125 | ifstream & read( ifstream & is, char data[], size_t size ); |
---|
[09687aa] | 126 | ifstream & ungetc( ifstream & is, char c ); |
---|
[f451177] | 127 | |
---|
[09687aa] | 128 | void ?{}( ifstream & is ); |
---|
[f451177] | 129 | void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" |
---|
[e3fea42] | 130 | void ?{}( ifstream & is, const char name[] ); |
---|
[4cae032] | 131 | void ^?{}( ifstream & is ); |
---|
[51b7345] | 132 | |
---|
[a87d40b] | 133 | extern ifstream & sin, & stdin; // aliases |
---|
[51b7345] | 134 | |
---|
[91e52be] | 135 | |
---|
[8d321f9] | 136 | // *********************************** exceptions *********************************** |
---|
[91e52be] | 137 | |
---|
| 138 | |
---|
[f9d8755] | 139 | exception Open_Failure { |
---|
[91e52be] | 140 | union { |
---|
| 141 | ofstream * ostream; |
---|
| 142 | ifstream * istream; |
---|
| 143 | }; |
---|
[8d321f9] | 144 | // TEMPORARY: need polymorphic exceptions |
---|
| 145 | int tag; // 1 => ostream; 0 => istream |
---|
[f9d8755] | 146 | }; |
---|
[91e52be] | 147 | |
---|
[b431515] | 148 | void ?{}( Open_Failure & this, ofstream & ); |
---|
| 149 | void ?{}( Open_Failure & this, ifstream & ); |
---|
[91e52be] | 150 | |
---|
[ba0d2ea] | 151 | exception Close_Failure { |
---|
| 152 | union { |
---|
| 153 | ofstream * ostream; |
---|
| 154 | ifstream * istream; |
---|
| 155 | }; |
---|
| 156 | // TEMPORARY: need polymorphic exceptions |
---|
| 157 | int tag; // 1 => ostream; 0 => istream |
---|
| 158 | }; |
---|
| 159 | |
---|
| 160 | void ?{}( Close_Failure & this, ofstream & ); |
---|
| 161 | void ?{}( Close_Failure & this, ifstream & ); |
---|
| 162 | |
---|
| 163 | exception Write_Failure { |
---|
| 164 | union { |
---|
| 165 | ofstream * ostream; |
---|
| 166 | ifstream * istream; |
---|
| 167 | }; |
---|
| 168 | // TEMPORARY: need polymorphic exceptions |
---|
| 169 | int tag; // 1 => ostream; 0 => istream |
---|
| 170 | }; |
---|
| 171 | |
---|
| 172 | void ?{}( Write_Failure & this, ofstream & ); |
---|
| 173 | void ?{}( Write_Failure & this, ifstream & ); |
---|
| 174 | |
---|
| 175 | exception Read_Failure { |
---|
| 176 | union { |
---|
| 177 | ofstream * ostream; |
---|
| 178 | ifstream * istream; |
---|
| 179 | }; |
---|
| 180 | // TEMPORARY: need polymorphic exceptions |
---|
| 181 | int tag; // 1 => ostream; 0 => istream |
---|
| 182 | }; |
---|
| 183 | |
---|
| 184 | void ?{}( Read_Failure & this, ofstream & ); |
---|
| 185 | void ?{}( Read_Failure & this, ifstream & ); |
---|
| 186 | |
---|
[86bd7c1f] | 187 | // Local Variables: // |
---|
[d3b7937] | 188 | // mode: c // |
---|
[86bd7c1f] | 189 | // tab-width: 4 // |
---|
| 190 | // End: // |
---|