source: libcfa/src/fstream.hfa @ 9cd5bd2

ADTast-experimentalpthread-emulation
Last change on this file since 9cd5bd2 was 31540f5, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Exception Clean-Up: Removed extra include no longer needed with the addition of exception syntax.

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[86bd7c1f]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//
[bb82c03]7// fstream --
[86bd7c1f]8//
[90c3b1c]9// Author           : Peter A. Buhr
[86bd7c1f]10// Created On       : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
[c8371b5]12// Last Modified On : Sun Oct 10 09:37:32 2021
13// Update Count     : 243
[86bd7c1f]14//
15
[53a6c2a]16#pragma once
[51b7345]17
[e474cf09]18#include "bits/weakso_locks.hfa"                                                // mutex_lock
[58b6d1b]19#include "iostream.hfa"
[51b7345]20
[65240bb]21
[8d321f9]22// *********************************** ofstream ***********************************
[65240bb]23
24
[b431515]25enum { ofstream_sepSize = 16 };
[53ba273]26struct ofstream {
[6c5d92f]27        void * file$;
28        bool sepDefault$;
29        bool sepOnOff$;
30        bool nlOnOff$;
31        bool prt$;                                                                                      // print text
32        bool sawNL$;
33        const char * sepCur$;
[b431515]34        char separator$[ofstream_sepSize];
35        char tupleSeparator$[ofstream_sepSize];
[6c5d92f]36        multiple_acquisition_lock lock$;
[53ba273]37}; // ofstream
[90c3b1c]38
[b431515]39// Satisfies ostream
40
[9ebd778]41// private
[6c5d92f]42bool sepPrt$( ofstream & );
43void sepReset$( ofstream & );
44void sepReset$( ofstream &, bool );
45const char * sepGetCur$( ofstream & );
46void sepSetCur$( ofstream &, const char [] );
47bool getNL$( ofstream & );
48void setNL$( ofstream &, bool );
49bool getANL$( ofstream & );
50bool getPrt$( ofstream & );
51void setPrt$( ofstream &, bool );
[9ebd778]52
[7ce2483]53void lock( ofstream & );
54void unlock( ofstream & );
55
[9ebd778]56// public
[09687aa]57void sepOn( ofstream & );
58void sepOff( ofstream & );
[93c2e0a]59bool sepDisable( ofstream & );
60bool sepEnable( ofstream & );
[200fcb3]61void nlOn( ofstream & );
62void nlOff( ofstream & );
[9ebd778]63
[09687aa]64const char * sepGet( ofstream & );
[e3fea42]65void sepSet( ofstream &, const char [] );
[09687aa]66const char * sepGetTuple( ofstream & );
[e3fea42]67void sepSetTuple( ofstream &, const char [] );
[6152c81]68
[b431515]69void ends( ofstream & );
70int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
71
72bool fail( ofstream & );
[00e9be9]73void clear( ofstream & );
[09687aa]74int flush( ofstream & );
[f451177]75void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
[e3fea42]76void open( ofstream &, const char name[] );
[09687aa]77void close( ofstream & );
[c8371b5]78
[e3fea42]79ofstream & write( ofstream &, const char data[], size_t size );
[b431515]80
81void ?{}( ofstream & );
[f451177]82void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
[b431515]83void ?{}( ofstream &, const char name[] );
84void ^?{}( ofstream & );
[09687aa]85
[f451177]86// private
87static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
88// public
89ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
90
[a87d40b]91extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
[65240bb]92extern ofstream & exit, & abort;
93
[51b7345]94
[8d321f9]95// *********************************** ifstream ***********************************
[5cb2b8c]96
[51b7345]97
[53ba273]98struct ifstream {
[6c5d92f]99        void * file$;
100        bool nlOnOff$;
101        multiple_acquisition_lock lock$;
[53ba273]102}; // ifstream
[6ba0659]103
[b431515]104// Satisfies istream
105
[7ce2483]106// private
[c8371b5]107bool getANL$( ifstream & );
108
[7ce2483]109void lock( ifstream & );
110void unlock( ifstream & );
111
[09687aa]112// public
[0efb269]113void nlOn( ifstream & );
114void nlOff( ifstream & );
[e474cf09]115void ends( ifstream & );
[f451177]116int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
117
[b431515]118bool fail( ifstream & is );
[00e9be9]119void clear( ifstream & );
120bool eof( ifstream & is );
[f451177]121void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
[e3fea42]122void open( ifstream & is, const char name[] );
[09687aa]123void close( ifstream & is );
[c8371b5]124
[00e9be9]125ifstream & read( ifstream & is, char data[], size_t size );
[09687aa]126ifstream & ungetc( ifstream & is, char c );
[f451177]127
[09687aa]128void ?{}( ifstream & is );
[f451177]129void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
[e3fea42]130void ?{}( ifstream & is, const char name[] );
[4cae032]131void ^?{}( ifstream & is );
[51b7345]132
[a87d40b]133extern ifstream & sin, & stdin;                                                 // aliases
[51b7345]134
[91e52be]135
[8d321f9]136// *********************************** exceptions ***********************************
[91e52be]137
138
[f9d8755]139exception Open_Failure {
[91e52be]140        union {
141                ofstream * ostream;
142                ifstream * istream;
143        };
[8d321f9]144        // TEMPORARY: need polymorphic exceptions
145        int tag;                                                                                        // 1 => ostream; 0 => istream
[f9d8755]146};
[91e52be]147
[b431515]148void ?{}( Open_Failure & this, ofstream & );
149void ?{}( Open_Failure & this, ifstream & );
[91e52be]150
[ba0d2ea]151exception Close_Failure {
152        union {
153                ofstream * ostream;
154                ifstream * istream;
155        };
156        // TEMPORARY: need polymorphic exceptions
157        int tag;                                                                                        // 1 => ostream; 0 => istream
158};
159
160void ?{}( Close_Failure & this, ofstream & );
161void ?{}( Close_Failure & this, ifstream & );
162
163exception Write_Failure {
164        union {
165                ofstream * ostream;
166                ifstream * istream;
167        };
168        // TEMPORARY: need polymorphic exceptions
169        int tag;                                                                                        // 1 => ostream; 0 => istream
170};
171
172void ?{}( Write_Failure & this, ofstream & );
173void ?{}( Write_Failure & this, ifstream & );
174
175exception Read_Failure {
176        union {
177                ofstream * ostream;
178                ifstream * istream;
179        };
180        // TEMPORARY: need polymorphic exceptions
181        int tag;                                                                                        // 1 => ostream; 0 => istream
182};
183
184void ?{}( Read_Failure & this, ofstream & );
185void ?{}( Read_Failure & this, ifstream & );
186
[86bd7c1f]187// Local Variables: //
[d3b7937]188// mode: c //
[86bd7c1f]189// tab-width: 4 //
190// End: //
Note: See TracBrowser for help on using the repository browser.