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