source: libcfa/src/fstream.hfa@ 39eb23b0

Last change on this file since 39eb23b0 was 39eb23b0, checked in by Peter A. Buhr <pabuhr@…>, 2 weeks ago

for opening a file, change to default initialization of mode parameter from overloaded functions; fix fstream initialization bug by calling default constructor in other constructors

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