source: libcfa/src/fstream.hfa @ e474cf09

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

add concurrency lock to IO stream and provide user interface to lock stream

  • Property mode set to 100644
File size: 3.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
[e474cf09]12// Last Modified On : Mon Mar  1 22:45:08 2021
13// Update Count     : 217
[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
[53a6c2a]26enum { sepSize = 16 };
[53ba273]27struct ofstream {
[d1a9ff5]28        void * $file;
29        bool $sepDefault;
30        bool $sepOnOff;
31        bool $nlOnOff;
32        bool $prt;                                                                                      // print text
33        bool $sawNL;
34        const char * $sepCur;
35        char $separator[sepSize];
36        char $tupleSeparator[sepSize];
[e474cf09]37        multiple_acquisition_lock $lock;
38        bool $acquired;
[53ba273]39}; // ofstream
[90c3b1c]40
[9ebd778]41// private
[d1a9ff5]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
53// public
[09687aa]54void sepOn( ofstream & );
55void sepOff( ofstream & );
[93c2e0a]56bool sepDisable( ofstream & );
57bool sepEnable( ofstream & );
[200fcb3]58void nlOn( ofstream & );
59void nlOff( ofstream & );
[9ebd778]60
[09687aa]61const char * sepGet( ofstream & );
[e3fea42]62void sepSet( ofstream &, const char [] );
[09687aa]63const char * sepGetTuple( ofstream & );
[e3fea42]64void sepSetTuple( ofstream &, const char [] );
[6152c81]65
[65240bb]66void ends( ofstream & os );
[09687aa]67int fail( ofstream & );
68int flush( ofstream & );
[e3fea42]69void open( ofstream &, const char name[], const char mode[] );
70void open( ofstream &, const char name[] );
[09687aa]71void close( ofstream & );
[e3fea42]72ofstream & write( ofstream &, const char data[], size_t size );
[40cac90]73int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
[e474cf09]74void acquire( ofstream & os );
75void release( ofstream & os );
76
77struct osacquire {
78        ofstream & os;
79};
80void ?{}( osacquire & acq, ofstream & os );
81void ^?{}( osacquire & acq );
[829c907]82
[09687aa]83void ?{}( ofstream & os );
[e3fea42]84void ?{}( ofstream & os, const char name[], const char mode[] );
85void ?{}( ofstream & os, const char name[] );
[4cae032]86void ^?{}( ofstream & os );
[09687aa]87
[a87d40b]88extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
[65240bb]89extern ofstream & exit, & abort;
90
[51b7345]91
[8d321f9]92// *********************************** ifstream ***********************************
[5cb2b8c]93
[51b7345]94
[53ba273]95struct ifstream {
[d1a9ff5]96        void * $file;
97        bool $nlOnOff;
[e474cf09]98        multiple_acquisition_lock $lock;
99        bool $acquired;
[53ba273]100}; // ifstream
[6ba0659]101
[09687aa]102// public
[0efb269]103void nlOn( ifstream & );
104void nlOff( ifstream & );
105bool getANL( ifstream & );
[e474cf09]106void ends( ifstream & );
[09687aa]107int fail( ifstream & is );
108int eof( ifstream & is );
[e3fea42]109void open( ifstream & is, const char name[], const char mode[] );
110void open( ifstream & is, const char name[] );
[09687aa]111void close( ifstream & is );
[91d766d]112ifstream & read( ifstream & is, char * data, size_t size );
[09687aa]113ifstream & ungetc( ifstream & is, char c );
[40cac90]114int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
[e474cf09]115void acquire( ifstream & is );
116void release( ifstream & is );
117
118struct isacquire {
119        ifstream & is;
120};
121void ?{}( isacquire & acq, ifstream & is );
122void ^?{}( isacquire & acq );
[09687aa]123
124void ?{}( ifstream & is );
[e3fea42]125void ?{}( ifstream & is, const char name[], const char mode[] );
126void ?{}( ifstream & is, const char name[] );
[4cae032]127void ^?{}( ifstream & is );
[51b7345]128
[a87d40b]129extern ifstream & sin, & stdin;                                                 // aliases
[51b7345]130
[91e52be]131
[8d321f9]132// *********************************** exceptions ***********************************
[91e52be]133
134
[8d321f9]135DATA_EXCEPTION(Open_Failure)(
[91e52be]136        union {
137                ofstream * ostream;
138                ifstream * istream;
139        };
[8d321f9]140        // TEMPORARY: need polymorphic exceptions
141        int tag;                                                                                        // 1 => ostream; 0 => istream
[91e52be]142);
143
[8d321f9]144void ?{}( Open_Failure & this, ofstream & ostream );
145void ?{}( Open_Failure & this, ifstream & istream );
[91e52be]146
[86bd7c1f]147// Local Variables: //
[d3b7937]148// mode: c //
[86bd7c1f]149// tab-width: 4 //
150// End: //
Note: See TracBrowser for help on using the repository browser.