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