source: libcfa/src/fstream.hfa @ 2de175ce

Last change on this file since 2de175ce was 874b16e, checked in by Peter A. Buhr <pabuhr@…>, 17 months ago

lower case type names open_failure, close_failure, write_failure, read_failure

  • Property mode set to 100644
File size: 4.8 KB
Line 
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 Jun  5 22:00:20 2023
13// Update Count     : 246
14//
15
16#pragma once
17
18#include "bits/weakso_locks.hfa"                                                // mutex_lock
19#include "iostream.hfa"
20
21
22// *********************************** ofstream ***********************************
23
24
25enum { ofstream_sepSize = 16 };
26struct 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
42bool sepPrt$( ofstream & );
43void sepReset$( ofstream & );
44void sepReset$( ofstream &, bool );
45const char * sepGetCur$( ofstream & );
46void sepSetCur$( ofstream &, const char [] );
47bool getNL$( ofstream & );
48void setNL$( ofstream &, bool );
49bool getANL$( ofstream & );
50bool getPrt$( ofstream & );
51void setPrt$( ofstream &, bool );
52
53void lock( ofstream & );
54void unlock( ofstream & );
55
56// public
57void sepOn( ofstream & );
58void sepOff( ofstream & );
59bool sepDisable( ofstream & );
60bool sepEnable( ofstream & );
61void nlOn( ofstream & );
62void nlOff( ofstream & );
63
64const char * sepGet( ofstream & );
65void sepSet( ofstream &, const char [] );
66const char * sepGetTuple( ofstream & );
67void sepSetTuple( ofstream &, const char [] );
68
69void ends( ofstream & );
70int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
71
72bool fail( ofstream & );
73void clear( ofstream & );
74int flush( ofstream & );
75void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
76void open( ofstream &, const char name[] );
77void close( ofstream & );
78
79ofstream & write( ofstream &, const char data[], size_t size );
80
81void ?{}( ofstream & );
82void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
83void ?{}( ofstream &, const char name[] );
84void ^?{}( ofstream & );
85
86// private
87static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
88// public
89ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
90
91extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
92extern ofstream & exit, & abort;
93
94
95// *********************************** ifstream ***********************************
96
97
98struct ifstream {
99        void * file$;
100        bool nlOnOff$;
101        multiple_acquisition_lock lock$;
102}; // ifstream
103
104// Satisfies istream
105
106// private
107bool getANL$( ifstream & );
108
109void lock( ifstream & );
110void unlock( ifstream & );
111
112// public
113void nlOn( ifstream & );
114void nlOff( ifstream & );
115void ends( ifstream & );
116int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
117
118bool fail( ifstream & is );
119void clear( ifstream & );
120bool eof( ifstream & is );
121void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
122void open( ifstream & is, const char name[] );
123void close( ifstream & is );
124
125ifstream & read( ifstream & is, char data[], size_t size );
126ifstream & ungetc( ifstream & is, char c );
127
128void ?{}( ifstream & is );
129void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
130void ?{}( ifstream & is, const char name[] );
131void ^?{}( ifstream & is );
132
133extern ifstream & sin, & stdin;                                                 // aliases
134
135
136// *********************************** exceptions ***********************************
137
138
139exception 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
148void ?{}( open_failure & this, ofstream & );
149void ?{}( open_failure & this, ifstream & );
150
151exception 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
160void ?{}( close_failure & this, ofstream & );
161void ?{}( close_failure & this, ifstream & );
162
163exception 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
172void ?{}( write_failure & this, ofstream & );
173void ?{}( write_failure & this, ifstream & );
174
175exception 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
184void ?{}( read_failure & this, ofstream & );
185void ?{}( read_failure & this, ifstream & );
186
187// Local Variables: //
188// mode: c //
189// tab-width: 4 //
190// End: //
Note: See TracBrowser for help on using the repository browser.