source: libcfa/src/fstream.hfa@ f450f2f

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since f450f2f was ba0d2ea, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

add exceptions Close_Failure, Write_Failure, Read_Failure to fstream

  • Property mode set to 100644
File size: 5.0 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 Jul 28 07:35:50 2021
13// Update Count : 234
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 bool acquired$;
39}; // ofstream
40
41// Satisfies ostream
42
43// private
44bool sepPrt$( ofstream & );
45void sepReset$( ofstream & );
46void sepReset$( ofstream &, bool );
47const char * sepGetCur$( ofstream & );
48void sepSetCur$( ofstream &, const char [] );
49bool getNL$( ofstream & );
50void setNL$( ofstream &, bool );
51bool getANL$( ofstream & );
52bool getPrt$( ofstream & );
53void setPrt$( ofstream &, bool );
54
55// public
56void sepOn( ofstream & );
57void sepOff( ofstream & );
58bool sepDisable( ofstream & );
59bool sepEnable( ofstream & );
60void nlOn( ofstream & );
61void nlOff( ofstream & );
62
63const char * sepGet( ofstream & );
64void sepSet( ofstream &, const char [] );
65const char * sepGetTuple( ofstream & );
66void sepSetTuple( ofstream &, const char [] );
67
68void ends( ofstream & );
69int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
70
71bool fail( ofstream & );
72void clear( ofstream & );
73int flush( ofstream & );
74void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
75void open( ofstream &, const char name[] );
76void close( ofstream & );
77ofstream & write( ofstream &, const char data[], size_t size );
78
79void acquire( ofstream & );
80void release( ofstream & );
81
82struct osacquire {
83 ofstream & os;
84};
85void ?{}( osacquire & acq, ofstream & );
86void ^?{}( osacquire & acq );
87
88void ?{}( ofstream & );
89void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
90void ?{}( ofstream &, const char name[] );
91void ^?{}( ofstream & );
92
93// private
94static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
95// public
96ofstream & nl( ofstream & os ); // override basic_ostream nl
97
98extern ofstream & sout, & stdout, & serr, & stderr; // aliases
99extern ofstream & exit, & abort;
100
101
102// *********************************** ifstream ***********************************
103
104
105struct ifstream {
106 void * file$;
107 bool nlOnOff$;
108 multiple_acquisition_lock lock$;
109 bool acquired$;
110}; // ifstream
111
112// Satisfies istream
113
114// public
115void nlOn( ifstream & );
116void nlOff( ifstream & );
117bool getANL( ifstream & );
118void ends( ifstream & );
119int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
120
121bool fail( ifstream & is );
122void clear( ifstream & );
123bool eof( ifstream & is );
124void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
125void open( ifstream & is, const char name[] );
126void close( ifstream & is );
127ifstream & read( ifstream & is, char data[], size_t size );
128ifstream & ungetc( ifstream & is, char c );
129
130void acquire( ifstream & is );
131void release( ifstream & is );
132
133struct isacquire {
134 ifstream & is;
135};
136void ?{}( isacquire & acq, ifstream & is );
137void ^?{}( isacquire & acq );
138
139void ?{}( ifstream & is );
140void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
141void ?{}( ifstream & is, const char name[] );
142void ^?{}( ifstream & is );
143
144extern ifstream & sin, & stdin; // aliases
145
146
147// *********************************** exceptions ***********************************
148
149
150exception Open_Failure {
151 union {
152 ofstream * ostream;
153 ifstream * istream;
154 };
155 // TEMPORARY: need polymorphic exceptions
156 int tag; // 1 => ostream; 0 => istream
157};
158
159void ?{}( Open_Failure & this, ofstream & );
160void ?{}( Open_Failure & this, ifstream & );
161
162exception Close_Failure {
163 union {
164 ofstream * ostream;
165 ifstream * istream;
166 };
167 // TEMPORARY: need polymorphic exceptions
168 int tag; // 1 => ostream; 0 => istream
169};
170
171void ?{}( Close_Failure & this, ofstream & );
172void ?{}( Close_Failure & this, ifstream & );
173
174exception Write_Failure {
175 union {
176 ofstream * ostream;
177 ifstream * istream;
178 };
179 // TEMPORARY: need polymorphic exceptions
180 int tag; // 1 => ostream; 0 => istream
181};
182
183void ?{}( Write_Failure & this, ofstream & );
184void ?{}( Write_Failure & this, ifstream & );
185
186exception Read_Failure {
187 union {
188 ofstream * ostream;
189 ifstream * istream;
190 };
191 // TEMPORARY: need polymorphic exceptions
192 int tag; // 1 => ostream; 0 => istream
193};
194
195void ?{}( Read_Failure & this, ofstream & );
196void ?{}( Read_Failure & this, ifstream & );
197
198// Local Variables: //
199// mode: c //
200// tab-width: 4 //
201// End: //
Note: See TracBrowser for help on using the repository browser.