source: libcfa/src/fstream.hfa@ 0ca15b7

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since 0ca15b7 was 7e7a076, checked in by caparsons <caparson@…>, 4 years ago

added routines so fstreams could be acquired with the mutex stmt

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