source: libcfa/src/fstream.hfa@ 8eb85de

stuck-waitfor-destruct
Last change on this file since 8eb85de was 39eb23b0, checked in by Peter A. Buhr <pabuhr@…>, 4 weeks ago

for opening a file, change to default initialization of mode parameter from overloaded functions; fix fstream initialization bug by calling default constructor in other constructors

  • Property mode set to 100644
File size: 4.9 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
[39eb23b0]12// Last Modified On : Wed Jan 14 21:11:16 2026
13// Update Count : 280
[86bd7c1f]14//
15
[53a6c2a]16#pragma once
[51b73452]17
[e474cf09]18#include "bits/weakso_locks.hfa" // mutex_lock
[58b6d1b]19#include "iostream.hfa"
[51b73452]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];
[502a107]36 multiple_acquisition_lock lock$; // used by trait is_lock for mutex statement
[53ba273]37}; // ofstream
[90c3b1c]38
[b431515]39// Satisfies ostream
[ae0c1c3]40extern basic_ostream_data(ofstream) const & basic_ostream_table;
41extern ostream_data(ofstream) const & ostream_table;
[b431515]42
[9ebd778]43// private
[f5d9c37]44bool getNL$( ofstream & );
[d0cfcbe1]45bool setNL$( ofstream &, bool );
[f5d9c37]46bool getANL$( ofstream & );
[d0cfcbe1]47bool setANL$( ofstream &, bool );
[f5d9c37]48
[6c5d92f]49bool sepPrt$( ofstream & );
50void sepReset$( ofstream & );
51void sepReset$( ofstream &, bool );
52const char * sepGetCur$( ofstream & );
53void sepSetCur$( ofstream &, const char [] );
[f5d9c37]54
[6c5d92f]55bool getPrt$( ofstream & );
[d0cfcbe1]56bool setPrt$( ofstream &, bool );
[9ebd778]57
[7ce2483]58void lock( ofstream & );
59void unlock( ofstream & );
60
[9ebd778]61// public
[200fcb3]62void nlOn( ofstream & );
63void nlOff( ofstream & );
[9ebd778]64
[f5d9c37]65void sep( ofstream & );
66void nosep( ofstream & );
67bool sepOn( ofstream & );
68bool sepOff( ofstream & );
[09687aa]69const char * sepGet( ofstream & );
[e3fea42]70void sepSet( ofstream &, const char [] );
[09687aa]71const char * sepGetTuple( ofstream & );
[e3fea42]72void sepSetTuple( ofstream &, const char [] );
[6152c81]73
[b431515]74void ends( ofstream & );
75int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
76
77bool fail( ofstream & );
[768d091]78void clearerr( ofstream & );
[09687aa]79int flush( ofstream & );
[39eb23b0]80void open( ofstream &, const char name[], const char mode[] = "w" );
[09687aa]81void close( ofstream & );
[c8371b5]82
[e3fea42]83ofstream & write( ofstream &, const char data[], size_t size );
[b431515]84
85void ?{}( ofstream & );
[39eb23b0]86void ?{}( ofstream &, const char name[], const char mode[] = "w" );
[b431515]87void ^?{}( ofstream & );
[09687aa]88
[f451177]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
[a87d40b]94extern ofstream & sout, & stdout, & serr, & stderr; // aliases
[65240bb]95extern ofstream & exit, & abort;
96
[51b73452]97
[8d321f9]98// *********************************** ifstream ***********************************
[5cb2b8c]99
[51b73452]100
[53ba273]101struct ifstream {
[6c5d92f]102 void * file$;
103 bool nlOnOff$;
[502a107]104 multiple_acquisition_lock lock$; // used by trait is_lock for mutex statement
[53ba273]105}; // ifstream
[6ba0659]106
[b431515]107// Satisfies istream
[ae0c1c3]108extern basic_istream_data(ifstream) const & basic_istream_table;
109extern istream_data(ifstream) const & istream_table;
[b431515]110
[7ce2483]111// private
[c8371b5]112bool getANL$( ifstream & );
[d0cfcbe1]113bool setANL$( ifstream &, bool );
[c8371b5]114
[7ce2483]115void lock( ifstream & );
116void unlock( ifstream & );
117
[09687aa]118// public
[0efb269]119void nlOn( ifstream & );
120void nlOff( ifstream & );
[f451177]121int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
[a1a1f37d]122ifstream & ungetc( char c, ifstream & is );
[e0dc038]123bool eof( ifstream & is );
[f451177]124
[b431515]125bool fail( ifstream & is );
[768d091]126void clearerr( ifstream & );
[39eb23b0]127void open( ifstream & is, const char name[], const char mode[] = "r" );
[09687aa]128void close( ifstream & is );
[00e9be9]129ifstream & read( ifstream & is, char data[], size_t size );
[f451177]130
[09687aa]131void ?{}( ifstream & is );
[39eb23b0]132void ?{}( ifstream & is, const char name[], const char mode[] = "r" );
[4cae032]133void ^?{}( ifstream & is );
[51b73452]134
[a87d40b]135extern ifstream & sin, & stdin; // aliases
[51b73452]136
[91e52be]137
[8d321f9]138// *********************************** exceptions ***********************************
[91e52be]139
140
[77bc259]141ExceptionDecl( open_failure,
[91e52be]142 union {
143 ofstream * ostream;
144 ifstream * istream;
145 };
[8d321f9]146 // TEMPORARY: need polymorphic exceptions
147 int tag; // 1 => ostream; 0 => istream
[77bc259]148);
[91e52be]149
[874b16e]150void ?{}( open_failure & this, ofstream & );
151void ?{}( open_failure & this, ifstream & );
[91e52be]152
[77bc259]153ExceptionDecl( close_failure,
[ba0d2ea]154 union {
155 ofstream * ostream;
156 ifstream * istream;
157 };
158 // TEMPORARY: need polymorphic exceptions
159 int tag; // 1 => ostream; 0 => istream
[77bc259]160);
[ba0d2ea]161
[874b16e]162void ?{}( close_failure & this, ofstream & );
163void ?{}( close_failure & this, ifstream & );
[ba0d2ea]164
[77bc259]165ExceptionDecl( write_failure,
[ba0d2ea]166 union {
167 ofstream * ostream;
168 ifstream * istream;
169 };
170 // TEMPORARY: need polymorphic exceptions
171 int tag; // 1 => ostream; 0 => istream
[77bc259]172);
[ba0d2ea]173
[874b16e]174void ?{}( write_failure & this, ofstream & );
175void ?{}( write_failure & this, ifstream & );
[ba0d2ea]176
[77bc259]177ExceptionDecl( read_failure,
[ba0d2ea]178 union {
179 ofstream * ostream;
180 ifstream * istream;
181 };
182 // TEMPORARY: need polymorphic exceptions
183 int tag; // 1 => ostream; 0 => istream
[77bc259]184);
[ba0d2ea]185
[874b16e]186void ?{}( read_failure & this, ofstream & );
187void ?{}( read_failure & this, ifstream & );
[ba0d2ea]188
[86bd7c1f]189// Local Variables: //
[d3b7937]190// mode: c //
[86bd7c1f]191// tab-width: 4 //
192// End: //
Note: See TracBrowser for help on using the repository browser.