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