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