source: libcfa/src/fstream.hfa @ f451177

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since f451177 was f451177, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

remember basic_ostream nl and then override it using the basic_ostream version

  • Property mode set to 100644
File size: 4.2 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
[f451177]12// Last Modified On : Tue Apr 27 22:00:30 2021
13// Update Count     : 226
[86bd7c1f]14//
15
[53a6c2a]16#pragma once
[51b7345]17
[e474cf09]18#include "bits/weakso_locks.hfa"                                                // mutex_lock
[58b6d1b]19#include "iostream.hfa"
[91e52be]20#include <exception.hfa>
[51b7345]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 & );
[09687aa]72int flush( ofstream & );
[f451177]73void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
[e3fea42]74void open( ofstream &, const char name[] );
[09687aa]75void close( ofstream & );
[e3fea42]76ofstream & write( ofstream &, const char data[], size_t size );
[b431515]77
78void acquire( ofstream & );
79void release( ofstream & );
[e474cf09]80
81struct osacquire {
82        ofstream & os;
83};
[b431515]84void ?{}( osacquire & acq, ofstream & );
[e474cf09]85void ^?{}( osacquire & acq );
[829c907]86
[b431515]87void ?{}( ofstream & );
[f451177]88void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
[b431515]89void ?{}( ofstream &, const char name[] );
90void ^?{}( ofstream & );
[09687aa]91
[f451177]92// private
93static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
94// public
95ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
96
[a87d40b]97extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
[65240bb]98extern ofstream & exit, & abort;
99
[51b7345]100
[8d321f9]101// *********************************** ifstream ***********************************
[5cb2b8c]102
[51b7345]103
[53ba273]104struct ifstream {
[6c5d92f]105        void * file$;
106        bool nlOnOff$;
107        multiple_acquisition_lock lock$;
108        bool acquired$;
[53ba273]109}; // ifstream
[6ba0659]110
[b431515]111// Satisfies istream
112
[09687aa]113// public
[0efb269]114void nlOn( ifstream & );
115void nlOff( ifstream & );
116bool getANL( ifstream & );
[e474cf09]117void ends( ifstream & );
[f451177]118int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
119
[b431515]120bool fail( ifstream & is );
[09687aa]121int eof( ifstream & is );
[f451177]122void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
[e3fea42]123void open( ifstream & is, const char name[] );
[09687aa]124void close( ifstream & is );
[91d766d]125ifstream & read( ifstream & is, char * data, size_t size );
[09687aa]126ifstream & ungetc( ifstream & is, char c );
[f451177]127
[e474cf09]128void acquire( ifstream & is );
129void release( ifstream & is );
130
131struct isacquire {
132        ifstream & is;
133};
134void ?{}( isacquire & acq, ifstream & is );
135void ^?{}( isacquire & acq );
[09687aa]136
137void ?{}( ifstream & is );
[f451177]138void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
[e3fea42]139void ?{}( ifstream & is, const char name[] );
[4cae032]140void ^?{}( ifstream & is );
[51b7345]141
[a87d40b]142extern ifstream & sin, & stdin;                                                 // aliases
[51b7345]143
[91e52be]144
[8d321f9]145// *********************************** exceptions ***********************************
[91e52be]146
147
[ecfd758]148EHM_EXCEPTION(Open_Failure)(
[91e52be]149        union {
150                ofstream * ostream;
151                ifstream * istream;
152        };
[8d321f9]153        // TEMPORARY: need polymorphic exceptions
154        int tag;                                                                                        // 1 => ostream; 0 => istream
[91e52be]155);
156
[b431515]157void ?{}( Open_Failure & this, ofstream & );
158void ?{}( Open_Failure & this, ifstream & );
[91e52be]159
[86bd7c1f]160// Local Variables: //
[d3b7937]161// mode: c //
[86bd7c1f]162// tab-width: 4 //
163// End: //
Note: See TracBrowser for help on using the repository browser.