source: libcfa/src/fstream.hfa @ b29a1e8

Last change on this file since b29a1e8 was f5d9c37, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

harmonize separator manipulators names with newline names: change from sep, sepTuple, sepEnable, sepDisable, sepOn, sepOff to sepVal, sepTupleVal, sepOn, sepOff, sep, nosep; fix bug printing null string with WD so no separator

  • Property mode set to 100644
File size: 4.7 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 : Thu Jun 29 11:08:31 2023
13// Update Count     : 251
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 getNL$( ofstream & );
43void setNL$( ofstream &, bool );
44bool getANL$( ofstream & );
45
46bool sepPrt$( ofstream & );
47void sepReset$( ofstream & );
48void sepReset$( ofstream &, bool );
49const char * sepGetCur$( ofstream & );
50void sepSetCur$( ofstream &, const char [] );
51
52bool getPrt$( ofstream & );
53void setPrt$( ofstream &, bool );
54
55void lock( ofstream & );
56void unlock( ofstream & );
57
58// public
59void nlOn( ofstream & );
60void nlOff( ofstream & );
61
62void sep( ofstream & );
63void nosep( ofstream & );
64bool sepOn( ofstream & );
65bool sepOff( ofstream & );
66const char * sepGet( ofstream & );
67void sepSet( ofstream &, const char [] );
68const char * sepGetTuple( ofstream & );
69void sepSetTuple( ofstream &, const char [] );
70
71void ends( ofstream & );
72int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
73
74bool fail( ofstream & );
75void clear( ofstream & );
76int flush( ofstream & );
77void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
78void open( ofstream &, const char name[] );
79void close( ofstream & );
80
81ofstream & write( ofstream &, const char data[], size_t size );
82
83void ?{}( ofstream & );
84void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
85void ?{}( ofstream &, const char name[] );
86void ^?{}( ofstream & );
87
88// private
89static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
90// public
91ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
92
93extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
94extern ofstream & exit, & abort;
95
96
97// *********************************** ifstream ***********************************
98
99
100struct ifstream {
101        void * file$;
102        bool nlOnOff$;
103        multiple_acquisition_lock lock$;
104}; // ifstream
105
106// Satisfies istream
107
108// private
109bool getANL$( ifstream & );
110
111void lock( ifstream & );
112void unlock( ifstream & );
113
114// public
115void nlOn( ifstream & );
116void nlOff( ifstream & );
117void ends( ifstream & );
118int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
119
120bool fail( ifstream & is );
121void clear( ifstream & );
122bool eof( ifstream & is );
123void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
124void open( ifstream & is, const char name[] );
125void close( ifstream & is );
126
127ifstream & read( ifstream & is, char data[], size_t size );
128ifstream & ungetc( ifstream & is, char c );
129
130void ?{}( ifstream & is );
131void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
132void ?{}( ifstream & is, const char name[] );
133void ^?{}( ifstream & is );
134
135extern ifstream & sin, & stdin;                                                 // aliases
136
137
138// *********************************** exceptions ***********************************
139
140
141exception 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
153exception 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
165exception 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
177exception 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.