source: libcfa/src/fstream.hfa @ e0dc038

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

first attempt at new C string input

  • 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 : Fri Oct 13 13:55:21 2023
13// Update Count     : 260
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
40
41// private
42bool getNL$( ofstream & );
43bool setNL$( ofstream &, bool );
44bool getANL$( ofstream & );
45bool setANL$( ofstream &, bool );
46
47bool sepPrt$( ofstream & );
48void sepReset$( ofstream & );
49void sepReset$( ofstream &, bool );
50const char * sepGetCur$( ofstream & );
51void sepSetCur$( ofstream &, const char [] );
52
53bool getPrt$( ofstream & );
54bool setPrt$( ofstream &, bool );
55
56void lock( ofstream & );
57void unlock( ofstream & );
58
59// public
60void nlOn( ofstream & );
61void nlOff( ofstream & );
62
63void sep( ofstream & );
64void nosep( ofstream & );
65bool sepOn( ofstream & );
66bool sepOff( ofstream & );
67const char * sepGet( ofstream & );
68void sepSet( ofstream &, const char [] );
69const char * sepGetTuple( ofstream & );
70void sepSetTuple( ofstream &, const char [] );
71
72void ends( ofstream & );
73int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
74
75bool fail( ofstream & );
76void clear( ofstream & );
77int flush( ofstream & );
78void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
79void open( ofstream &, const char name[] );
80void close( ofstream & );
81
82ofstream & write( ofstream &, const char data[], size_t size );
83
84void ?{}( ofstream & );
85void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
86void ?{}( ofstream &, const char name[] );
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
108
109// private
110bool getANL$( ifstream & );
111bool setANL$( ifstream &, bool );
112
113void lock( ifstream & );
114void unlock( ifstream & );
115
116// public
117void nlOn( ifstream & );
118void nlOff( ifstream & );
119void ends( ifstream & );
120int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
121ifstream & ungetc( ifstream & is, char c );
122bool eof( ifstream & is );
123
124bool fail( ifstream & is );
125void clear( ifstream & );
126void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
127void open( ifstream & is, const char name[] );
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[] ); // FIX ME: use default = "r"
133void ?{}( ifstream & is, const char name[] );
134void ^?{}( ifstream & is );
135
136extern ifstream & sin, & stdin;                                                 // aliases
137
138
139// *********************************** exceptions ***********************************
140
141
142exception open_failure {
143        union {
144                ofstream * ostream;
145                ifstream * istream;
146        };
147        // TEMPORARY: need polymorphic exceptions
148        int tag;                                                                                        // 1 => ostream; 0 => istream
149};
150
151void ?{}( open_failure & this, ofstream & );
152void ?{}( open_failure & this, ifstream & );
153
154exception close_failure {
155        union {
156                ofstream * ostream;
157                ifstream * istream;
158        };
159        // TEMPORARY: need polymorphic exceptions
160        int tag;                                                                                        // 1 => ostream; 0 => istream
161};
162
163void ?{}( close_failure & this, ofstream & );
164void ?{}( close_failure & this, ifstream & );
165
166exception write_failure {
167        union {
168                ofstream * ostream;
169                ifstream * istream;
170        };
171        // TEMPORARY: need polymorphic exceptions
172        int tag;                                                                                        // 1 => ostream; 0 => istream
173};
174
175void ?{}( write_failure & this, ofstream & );
176void ?{}( write_failure & this, ifstream & );
177
178exception read_failure {
179        union {
180                ofstream * ostream;
181                ifstream * istream;
182        };
183        // TEMPORARY: need polymorphic exceptions
184        int tag;                                                                                        // 1 => ostream; 0 => istream
185};
186
187void ?{}( read_failure & this, ofstream & );
188void ?{}( read_failure & this, ifstream & );
189
190// Local Variables: //
191// mode: c //
192// tab-width: 4 //
193// End: //
Note: See TracBrowser for help on using the repository browser.