source: libcfa/src/fstream.hfa @ 8dcb832

Last change on this file since 8dcb832 was 8dcb832, checked in by Peter A. Buhr <pabuhr@…>, 3 months ago

remove mutual-exclusion acquire for streams, add EINTR restarts for C stream functions

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