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 : Mon Apr 14 20:42:01 2025
|
---|
13 | // Update Count : 276
|
---|
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$; // used by trait is_lock for mutex statement
|
---|
37 | }; // ofstream
|
---|
38 |
|
---|
39 | // Satisfies ostream
|
---|
40 | extern basic_ostream_data(ofstream) const & basic_ostream_table;
|
---|
41 | extern ostream_data(ofstream) const & ostream_table;
|
---|
42 |
|
---|
43 | // private
|
---|
44 | bool getNL$( ofstream & );
|
---|
45 | bool setNL$( ofstream &, bool );
|
---|
46 | bool getANL$( ofstream & );
|
---|
47 | bool setANL$( ofstream &, bool );
|
---|
48 |
|
---|
49 | bool sepPrt$( ofstream & );
|
---|
50 | void sepReset$( ofstream & );
|
---|
51 | void sepReset$( ofstream &, bool );
|
---|
52 | const char * sepGetCur$( ofstream & );
|
---|
53 | void sepSetCur$( ofstream &, const char [] );
|
---|
54 |
|
---|
55 | bool getPrt$( ofstream & );
|
---|
56 | bool setPrt$( ofstream &, bool );
|
---|
57 |
|
---|
58 | void lock( ofstream & );
|
---|
59 | void unlock( ofstream & );
|
---|
60 |
|
---|
61 | // public
|
---|
62 | void nlOn( ofstream & );
|
---|
63 | void nlOff( ofstream & );
|
---|
64 |
|
---|
65 | void sep( ofstream & );
|
---|
66 | void nosep( ofstream & );
|
---|
67 | bool sepOn( ofstream & );
|
---|
68 | bool sepOff( ofstream & );
|
---|
69 | const char * sepGet( ofstream & );
|
---|
70 | void sepSet( ofstream &, const char [] );
|
---|
71 | const char * sepGetTuple( ofstream & );
|
---|
72 | void sepSetTuple( ofstream &, const char [] );
|
---|
73 |
|
---|
74 | void ends( ofstream & );
|
---|
75 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
|
---|
76 |
|
---|
77 | bool fail( ofstream & );
|
---|
78 | void clearerr( ofstream & );
|
---|
79 | int flush( ofstream & );
|
---|
80 | void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
|
---|
81 | void open( ofstream &, const char name[] );
|
---|
82 | void close( ofstream & );
|
---|
83 |
|
---|
84 | ofstream & write( ofstream &, const char data[], size_t size );
|
---|
85 |
|
---|
86 | void ?{}( ofstream & );
|
---|
87 | void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
|
---|
88 | void ?{}( ofstream &, const char name[] );
|
---|
89 | void ^?{}( ofstream & );
|
---|
90 |
|
---|
91 | // private
|
---|
92 | static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
|
---|
93 | // public
|
---|
94 | ofstream & nl( ofstream & os ); // override basic_ostream nl
|
---|
95 |
|
---|
96 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases
|
---|
97 | extern ofstream & exit, & abort;
|
---|
98 |
|
---|
99 |
|
---|
100 | // *********************************** ifstream ***********************************
|
---|
101 |
|
---|
102 |
|
---|
103 | struct ifstream {
|
---|
104 | void * file$;
|
---|
105 | bool nlOnOff$;
|
---|
106 | multiple_acquisition_lock lock$; // used by trait is_lock for mutex statement
|
---|
107 | }; // ifstream
|
---|
108 |
|
---|
109 | // Satisfies istream
|
---|
110 | extern basic_istream_data(ifstream) const & basic_istream_table;
|
---|
111 | extern istream_data(ifstream) const & istream_table;
|
---|
112 |
|
---|
113 | // private
|
---|
114 | bool getANL$( ifstream & );
|
---|
115 | bool setANL$( ifstream &, bool );
|
---|
116 |
|
---|
117 | void lock( ifstream & );
|
---|
118 | void unlock( ifstream & );
|
---|
119 |
|
---|
120 | // public
|
---|
121 | void nlOn( ifstream & );
|
---|
122 | void nlOff( ifstream & );
|
---|
123 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
|
---|
124 | ifstream & ungetc( char c, ifstream & is );
|
---|
125 | bool eof( ifstream & is );
|
---|
126 |
|
---|
127 | bool fail( ifstream & is );
|
---|
128 | void clearerr( ifstream & );
|
---|
129 | void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
|
---|
130 | void open( ifstream & is, const char name[] );
|
---|
131 | void close( ifstream & is );
|
---|
132 | ifstream & read( ifstream & is, char data[], size_t size );
|
---|
133 |
|
---|
134 | void ?{}( ifstream & is );
|
---|
135 | void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
|
---|
136 | void ?{}( ifstream & is, const char name[] );
|
---|
137 | void ^?{}( ifstream & is );
|
---|
138 |
|
---|
139 | extern ifstream & sin, & stdin; // aliases
|
---|
140 |
|
---|
141 |
|
---|
142 | // *********************************** exceptions ***********************************
|
---|
143 |
|
---|
144 |
|
---|
145 | ExceptionDecl( open_failure,
|
---|
146 | union {
|
---|
147 | ofstream * ostream;
|
---|
148 | ifstream * istream;
|
---|
149 | };
|
---|
150 | // TEMPORARY: need polymorphic exceptions
|
---|
151 | int tag; // 1 => ostream; 0 => istream
|
---|
152 | );
|
---|
153 |
|
---|
154 | void ?{}( open_failure & this, ofstream & );
|
---|
155 | void ?{}( open_failure & this, ifstream & );
|
---|
156 |
|
---|
157 | ExceptionDecl( close_failure,
|
---|
158 | union {
|
---|
159 | ofstream * ostream;
|
---|
160 | ifstream * istream;
|
---|
161 | };
|
---|
162 | // TEMPORARY: need polymorphic exceptions
|
---|
163 | int tag; // 1 => ostream; 0 => istream
|
---|
164 | );
|
---|
165 |
|
---|
166 | void ?{}( close_failure & this, ofstream & );
|
---|
167 | void ?{}( close_failure & this, ifstream & );
|
---|
168 |
|
---|
169 | ExceptionDecl( write_failure,
|
---|
170 | union {
|
---|
171 | ofstream * ostream;
|
---|
172 | ifstream * istream;
|
---|
173 | };
|
---|
174 | // TEMPORARY: need polymorphic exceptions
|
---|
175 | int tag; // 1 => ostream; 0 => istream
|
---|
176 | );
|
---|
177 |
|
---|
178 | void ?{}( write_failure & this, ofstream & );
|
---|
179 | void ?{}( write_failure & this, ifstream & );
|
---|
180 |
|
---|
181 | ExceptionDecl( read_failure,
|
---|
182 | union {
|
---|
183 | ofstream * ostream;
|
---|
184 | ifstream * istream;
|
---|
185 | };
|
---|
186 | // TEMPORARY: need polymorphic exceptions
|
---|
187 | int tag; // 1 => ostream; 0 => istream
|
---|
188 | );
|
---|
189 |
|
---|
190 | void ?{}( read_failure & this, ofstream & );
|
---|
191 | void ?{}( read_failure & this, ifstream & );
|
---|
192 |
|
---|
193 | // Local Variables: //
|
---|
194 | // mode: c //
|
---|
195 | // tab-width: 4 //
|
---|
196 | // End: //
|
---|