source: libcfa/src/fstream.hfa @ 9cd5bd2

ADTast-experimentalpthread-emulation
Last change on this file since 9cd5bd2 was 31540f5, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Exception Clean-Up: Removed extra include no longer needed with the addition of exception syntax.

  • 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 : 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
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.