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 | // |
---|
7 | // fstream -- |
---|
8 | // |
---|
9 | // Author : Peter A. Buhr |
---|
10 | // Created On : Wed May 27 17:56:53 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sun Oct 10 09:37:32 2021 |
---|
13 | // Update Count : 243 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include "bits/weakso_locks.hfa" // mutex_lock |
---|
19 | #include "iostream.hfa" |
---|
20 | |
---|
21 | |
---|
22 | // *********************************** ofstream *********************************** |
---|
23 | |
---|
24 | |
---|
25 | enum { ofstream_sepSize = 16 }; |
---|
26 | struct ofstream { |
---|
27 | void * file$; |
---|
28 | bool sepDefault$; |
---|
29 | bool sepOnOff$; |
---|
30 | bool nlOnOff$; |
---|
31 | bool prt$; // print text |
---|
32 | bool sawNL$; |
---|
33 | const char * sepCur$; |
---|
34 | char separator$[ofstream_sepSize]; |
---|
35 | char tupleSeparator$[ofstream_sepSize]; |
---|
36 | multiple_acquisition_lock lock$; |
---|
37 | }; // ofstream |
---|
38 | |
---|
39 | // Satisfies ostream |
---|
40 | |
---|
41 | // private |
---|
42 | bool sepPrt$( ofstream & ); |
---|
43 | void sepReset$( ofstream & ); |
---|
44 | void sepReset$( ofstream &, bool ); |
---|
45 | const char * sepGetCur$( ofstream & ); |
---|
46 | void sepSetCur$( ofstream &, const char [] ); |
---|
47 | bool getNL$( ofstream & ); |
---|
48 | void setNL$( ofstream &, bool ); |
---|
49 | bool getANL$( ofstream & ); |
---|
50 | bool getPrt$( ofstream & ); |
---|
51 | void setPrt$( ofstream &, bool ); |
---|
52 | |
---|
53 | void lock( ofstream & ); |
---|
54 | void unlock( ofstream & ); |
---|
55 | |
---|
56 | // public |
---|
57 | void sepOn( ofstream & ); |
---|
58 | void sepOff( ofstream & ); |
---|
59 | bool sepDisable( ofstream & ); |
---|
60 | bool sepEnable( ofstream & ); |
---|
61 | void nlOn( ofstream & ); |
---|
62 | void nlOff( ofstream & ); |
---|
63 | |
---|
64 | const char * sepGet( ofstream & ); |
---|
65 | void sepSet( ofstream &, const char [] ); |
---|
66 | const char * sepGetTuple( ofstream & ); |
---|
67 | void sepSetTuple( ofstream &, const char [] ); |
---|
68 | |
---|
69 | void ends( ofstream & ); |
---|
70 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
71 | |
---|
72 | bool fail( ofstream & ); |
---|
73 | void clear( ofstream & ); |
---|
74 | int flush( ofstream & ); |
---|
75 | void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" |
---|
76 | void open( ofstream &, const char name[] ); |
---|
77 | void close( ofstream & ); |
---|
78 | |
---|
79 | ofstream & write( ofstream &, const char data[], size_t size ); |
---|
80 | |
---|
81 | void ?{}( ofstream & ); |
---|
82 | void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" |
---|
83 | void ?{}( ofstream &, const char name[] ); |
---|
84 | void ^?{}( ofstream & ); |
---|
85 | |
---|
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 | |
---|
91 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases |
---|
92 | extern ofstream & exit, & abort; |
---|
93 | |
---|
94 | |
---|
95 | // *********************************** ifstream *********************************** |
---|
96 | |
---|
97 | |
---|
98 | struct ifstream { |
---|
99 | void * file$; |
---|
100 | bool nlOnOff$; |
---|
101 | multiple_acquisition_lock lock$; |
---|
102 | }; // ifstream |
---|
103 | |
---|
104 | // Satisfies istream |
---|
105 | |
---|
106 | // private |
---|
107 | bool getANL$( ifstream & ); |
---|
108 | |
---|
109 | void lock( ifstream & ); |
---|
110 | void unlock( ifstream & ); |
---|
111 | |
---|
112 | // public |
---|
113 | void nlOn( ifstream & ); |
---|
114 | void nlOff( ifstream & ); |
---|
115 | void ends( ifstream & ); |
---|
116 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); |
---|
117 | |
---|
118 | bool fail( ifstream & is ); |
---|
119 | void clear( ifstream & ); |
---|
120 | bool eof( ifstream & is ); |
---|
121 | void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" |
---|
122 | void open( ifstream & is, const char name[] ); |
---|
123 | void close( ifstream & is ); |
---|
124 | |
---|
125 | ifstream & read( ifstream & is, char data[], size_t size ); |
---|
126 | ifstream & ungetc( ifstream & is, char c ); |
---|
127 | |
---|
128 | void ?{}( ifstream & is ); |
---|
129 | void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r" |
---|
130 | void ?{}( ifstream & is, const char name[] ); |
---|
131 | void ^?{}( ifstream & is ); |
---|
132 | |
---|
133 | extern ifstream & sin, & stdin; // aliases |
---|
134 | |
---|
135 | |
---|
136 | // *********************************** exceptions *********************************** |
---|
137 | |
---|
138 | |
---|
139 | exception Open_Failure { |
---|
140 | union { |
---|
141 | ofstream * ostream; |
---|
142 | ifstream * istream; |
---|
143 | }; |
---|
144 | // TEMPORARY: need polymorphic exceptions |
---|
145 | int tag; // 1 => ostream; 0 => istream |
---|
146 | }; |
---|
147 | |
---|
148 | void ?{}( Open_Failure & this, ofstream & ); |
---|
149 | void ?{}( Open_Failure & this, ifstream & ); |
---|
150 | |
---|
151 | exception Close_Failure { |
---|
152 | union { |
---|
153 | ofstream * ostream; |
---|
154 | ifstream * istream; |
---|
155 | }; |
---|
156 | // TEMPORARY: need polymorphic exceptions |
---|
157 | int tag; // 1 => ostream; 0 => istream |
---|
158 | }; |
---|
159 | |
---|
160 | void ?{}( Close_Failure & this, ofstream & ); |
---|
161 | void ?{}( Close_Failure & this, ifstream & ); |
---|
162 | |
---|
163 | exception Write_Failure { |
---|
164 | union { |
---|
165 | ofstream * ostream; |
---|
166 | ifstream * istream; |
---|
167 | }; |
---|
168 | // TEMPORARY: need polymorphic exceptions |
---|
169 | int tag; // 1 => ostream; 0 => istream |
---|
170 | }; |
---|
171 | |
---|
172 | void ?{}( Write_Failure & this, ofstream & ); |
---|
173 | void ?{}( Write_Failure & this, ifstream & ); |
---|
174 | |
---|
175 | exception Read_Failure { |
---|
176 | union { |
---|
177 | ofstream * ostream; |
---|
178 | ifstream * istream; |
---|
179 | }; |
---|
180 | // TEMPORARY: need polymorphic exceptions |
---|
181 | int tag; // 1 => ostream; 0 => istream |
---|
182 | }; |
---|
183 | |
---|
184 | void ?{}( Read_Failure & this, ofstream & ); |
---|
185 | void ?{}( Read_Failure & this, ifstream & ); |
---|
186 | |
---|
187 | // Local Variables: // |
---|
188 | // mode: c // |
---|
189 | // tab-width: 4 // |
---|
190 | // End: // |
---|