source: libcfa/src/fstream.hfa

Last change on this file was ae0c1c3, checked in by Andrew Beach <ajbeach@…>, 8 weeks ago

Rewrote the iostream traits to have a single assertion each, a table containing function pointers. This is just an experiment right now. It seems that it does cause significant speed up of assertion resolution, but for some reason also seems to add a flat overhead that mostly eats up that saving.

  • 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 : Mon Apr 14 20:42:01 2025
13// Update Count     : 276
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[] ); // FIX ME: use default = "w"
81void open( ofstream &, const char name[] );
82void close( ofstream & );
83
84ofstream & write( ofstream &, const char data[], size_t size );
85
86void ?{}( ofstream & );
87void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
88void ?{}( ofstream &, const char name[] );
89void ^?{}( ofstream & );
90
91// private
92static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
93// public
94ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
95
96extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
97extern ofstream & exit, & abort;
98
99
100// *********************************** ifstream ***********************************
101
102
103struct ifstream {
104        void * file$;
105        bool nlOnOff$;
106        multiple_acquisition_lock lock$;                                        // used by trait is_lock for mutex statement
107}; // ifstream
108
109// Satisfies istream
110extern basic_istream_data(ifstream) const & basic_istream_table;
111extern istream_data(ifstream) const & istream_table;
112
113// private
114bool getANL$( ifstream & );
115bool setANL$( ifstream &, bool );
116
117void lock( ifstream & );
118void unlock( ifstream & );
119
120// public
121void nlOn( ifstream & );
122void nlOff( ifstream & );
123int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
124ifstream & ungetc( char c, ifstream & is );
125bool eof( ifstream & is );
126
127bool fail( ifstream & is );
128void clearerr( ifstream & );
129void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
130void open( ifstream & is, const char name[] );
131void close( ifstream & is );
132ifstream & read( ifstream & is, char data[], size_t size );
133
134void ?{}( ifstream & is );
135void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
136void ?{}( ifstream & is, const char name[] );
137void ^?{}( ifstream & is );
138
139extern ifstream & sin, & stdin;                                                 // aliases
140
141
142// *********************************** exceptions ***********************************
143
144
145ExceptionDecl( open_failure,
146        union {
147                ofstream * ostream;
148                ifstream * istream;
149        };
150        // TEMPORARY: need polymorphic exceptions
151        int tag;                                                                                        // 1 => ostream; 0 => istream
152);
153
154void ?{}( open_failure & this, ofstream & );
155void ?{}( open_failure & this, ifstream & );
156
157ExceptionDecl( close_failure,
158        union {
159                ofstream * ostream;
160                ifstream * istream;
161        };
162        // TEMPORARY: need polymorphic exceptions
163        int tag;                                                                                        // 1 => ostream; 0 => istream
164);
165
166void ?{}( close_failure & this, ofstream & );
167void ?{}( close_failure & this, ifstream & );
168
169ExceptionDecl( write_failure,
170        union {
171                ofstream * ostream;
172                ifstream * istream;
173        };
174        // TEMPORARY: need polymorphic exceptions
175        int tag;                                                                                        // 1 => ostream; 0 => istream
176);
177
178void ?{}( write_failure & this, ofstream & );
179void ?{}( write_failure & this, ifstream & );
180
181ExceptionDecl( read_failure,
182        union {
183                ofstream * ostream;
184                ifstream * istream;
185        };
186        // TEMPORARY: need polymorphic exceptions
187        int tag;                                                                                        // 1 => ostream; 0 => istream
188);
189
190void ?{}( read_failure & this, ofstream & );
191void ?{}( read_failure & this, ifstream & );
192
193// Local Variables: //
194// mode: c //
195// tab-width: 4 //
196// End: //
Note: See TracBrowser for help on using the repository browser.