source: libcfa/src/fstream.hfa @ 7ce2483

enumforall-pointer-decay
Last change on this file since 7ce2483 was 7ce2483, checked in by Peter A. Buhr <pabuhr@…>, 8 months ago

formatting, remove release, and update lock/unlock for use with mutex statement

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