| [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 | 
|---|
| [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 & ); | 
|---|
| [c8371b5] | 79 |  | 
|---|
| [e3fea42] | 80 | ofstream & write( ofstream &, const char data[], size_t size ); | 
|---|
| [b431515] | 81 |  | 
|---|
|  | 82 | void ?{}( ofstream & ); | 
|---|
| [f451177] | 83 | void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" | 
|---|
| [b431515] | 84 | void ?{}( ofstream &, const char name[] ); | 
|---|
|  | 85 | void ^?{}( ofstream & ); | 
|---|
| [09687aa] | 86 |  | 
|---|
| [f451177] | 87 | // private | 
|---|
|  | 88 | static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl | 
|---|
|  | 89 | // public | 
|---|
|  | 90 | ofstream & nl( ofstream & os );                                                 // override basic_ostream nl | 
|---|
|  | 91 |  | 
|---|
| [a87d40b] | 92 | extern ofstream & sout, & stdout, & serr, & stderr;             // aliases | 
|---|
| [65240bb] | 93 | extern ofstream & exit, & abort; | 
|---|
|  | 94 |  | 
|---|
| [51b73452] | 95 |  | 
|---|
| [8d321f9] | 96 | // *********************************** ifstream *********************************** | 
|---|
| [5cb2b8c] | 97 |  | 
|---|
| [51b73452] | 98 |  | 
|---|
| [53ba273] | 99 | struct ifstream { | 
|---|
| [6c5d92f] | 100 | void * file$; | 
|---|
|  | 101 | bool nlOnOff$; | 
|---|
|  | 102 | multiple_acquisition_lock lock$; | 
|---|
| [53ba273] | 103 | }; // ifstream | 
|---|
| [6ba0659] | 104 |  | 
|---|
| [b431515] | 105 | // Satisfies istream | 
|---|
|  | 106 |  | 
|---|
| [7ce2483] | 107 | // private | 
|---|
| [c8371b5] | 108 | bool getANL$( ifstream & ); | 
|---|
|  | 109 |  | 
|---|
| [7ce2483] | 110 | void lock( ifstream & ); | 
|---|
|  | 111 | void unlock( ifstream & ); | 
|---|
|  | 112 |  | 
|---|
| [09687aa] | 113 | // public | 
|---|
| [0efb269] | 114 | void nlOn( ifstream & ); | 
|---|
|  | 115 | void nlOff( ifstream & ); | 
|---|
| [e474cf09] | 116 | void ends( ifstream & ); | 
|---|
| [f451177] | 117 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); | 
|---|
|  | 118 |  | 
|---|
| [b431515] | 119 | bool fail( ifstream & is ); | 
|---|
| [00e9be9] | 120 | void clear( ifstream & ); | 
|---|
|  | 121 | bool eof( ifstream & is ); | 
|---|
| [f451177] | 122 | void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" | 
|---|
| [e3fea42] | 123 | void open( ifstream & is, const char name[] ); | 
|---|
| [09687aa] | 124 | void close( ifstream & is ); | 
|---|
| [c8371b5] | 125 |  | 
|---|
| [00e9be9] | 126 | ifstream & read( ifstream & is, char data[], size_t size ); | 
|---|
| [09687aa] | 127 | ifstream & ungetc( ifstream & is, char c ); | 
|---|
| [f451177] | 128 |  | 
|---|
| [09687aa] | 129 | void ?{}( ifstream & is ); | 
|---|
| [f451177] | 130 | void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" | 
|---|
| [e3fea42] | 131 | void ?{}( ifstream & is, const char name[] ); | 
|---|
| [4cae032] | 132 | void ^?{}( ifstream & is ); | 
|---|
| [51b73452] | 133 |  | 
|---|
| [a87d40b] | 134 | extern ifstream & sin, & stdin;                                                 // aliases | 
|---|
| [51b73452] | 135 |  | 
|---|
| [91e52be] | 136 |  | 
|---|
| [8d321f9] | 137 | // *********************************** exceptions *********************************** | 
|---|
| [91e52be] | 138 |  | 
|---|
|  | 139 |  | 
|---|
| [f9d8755] | 140 | exception Open_Failure { | 
|---|
| [91e52be] | 141 | union { | 
|---|
|  | 142 | ofstream * ostream; | 
|---|
|  | 143 | ifstream * istream; | 
|---|
|  | 144 | }; | 
|---|
| [8d321f9] | 145 | // TEMPORARY: need polymorphic exceptions | 
|---|
|  | 146 | int tag;                                                                                        // 1 => ostream; 0 => istream | 
|---|
| [f9d8755] | 147 | }; | 
|---|
| [91e52be] | 148 |  | 
|---|
| [b431515] | 149 | void ?{}( Open_Failure & this, ofstream & ); | 
|---|
|  | 150 | void ?{}( Open_Failure & this, ifstream & ); | 
|---|
| [91e52be] | 151 |  | 
|---|
| [ba0d2ea] | 152 | exception Close_Failure { | 
|---|
|  | 153 | union { | 
|---|
|  | 154 | ofstream * ostream; | 
|---|
|  | 155 | ifstream * istream; | 
|---|
|  | 156 | }; | 
|---|
|  | 157 | // TEMPORARY: need polymorphic exceptions | 
|---|
|  | 158 | int tag;                                                                                        // 1 => ostream; 0 => istream | 
|---|
|  | 159 | }; | 
|---|
|  | 160 |  | 
|---|
|  | 161 | void ?{}( Close_Failure & this, ofstream & ); | 
|---|
|  | 162 | void ?{}( Close_Failure & this, ifstream & ); | 
|---|
|  | 163 |  | 
|---|
|  | 164 | exception Write_Failure { | 
|---|
|  | 165 | union { | 
|---|
|  | 166 | ofstream * ostream; | 
|---|
|  | 167 | ifstream * istream; | 
|---|
|  | 168 | }; | 
|---|
|  | 169 | // TEMPORARY: need polymorphic exceptions | 
|---|
|  | 170 | int tag;                                                                                        // 1 => ostream; 0 => istream | 
|---|
|  | 171 | }; | 
|---|
|  | 172 |  | 
|---|
|  | 173 | void ?{}( Write_Failure & this, ofstream & ); | 
|---|
|  | 174 | void ?{}( Write_Failure & this, ifstream & ); | 
|---|
|  | 175 |  | 
|---|
|  | 176 | exception Read_Failure { | 
|---|
|  | 177 | union { | 
|---|
|  | 178 | ofstream * ostream; | 
|---|
|  | 179 | ifstream * istream; | 
|---|
|  | 180 | }; | 
|---|
|  | 181 | // TEMPORARY: need polymorphic exceptions | 
|---|
|  | 182 | int tag;                                                                                        // 1 => ostream; 0 => istream | 
|---|
|  | 183 | }; | 
|---|
|  | 184 |  | 
|---|
|  | 185 | void ?{}( Read_Failure & this, ofstream & ); | 
|---|
|  | 186 | void ?{}( Read_Failure & this, ifstream & ); | 
|---|
|  | 187 |  | 
|---|
| [86bd7c1f] | 188 | // Local Variables: // | 
|---|
| [d3b7937] | 189 | // mode: c // | 
|---|
| [86bd7c1f] | 190 | // tab-width: 4 // | 
|---|
|  | 191 | // End: // | 
|---|