source: libcfa/src/fstream.hfa @ ecfd758

arm-ehjacob/cs343-translation
Last change on this file since ecfd758 was ecfd758, checked in by Andrew Beach <ajbeach@…>, 4 months ago

Major exception update, seperating type-ids from virtual tables. The major interface changes are done. There is a regression of ?Cancelled(T) to Some?Cancelled. There is some bits of code for the new verion of the ?Cancelled(T) interface already there. Not connected yet but I just reached the limit of what I wanted to do in one commit and then spent over a day cleaning up, so it will replace Some?Cancelled in a future commit.

  • Property mode set to 100644
File size: 3.9 KB
Line 
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//
7// fstream --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Mar  1 22:45:08 2021
13// Update Count     : 217
14//
15
16#pragma once
17
18#include "bits/weakso_locks.hfa"                                                // mutex_lock
19#include "iostream.hfa"
20#include <exception.hfa>
21
22
23// *********************************** ofstream ***********************************
24
25
26enum { sepSize = 16 };
27struct ofstream {
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];
37        multiple_acquisition_lock $lock;
38        bool $acquired;
39}; // ofstream
40
41// private
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 );
52
53// public
54void sepOn( ofstream & );
55void sepOff( ofstream & );
56bool sepDisable( ofstream & );
57bool sepEnable( ofstream & );
58void nlOn( ofstream & );
59void nlOff( ofstream & );
60
61const char * sepGet( ofstream & );
62void sepSet( ofstream &, const char [] );
63const char * sepGetTuple( ofstream & );
64void sepSetTuple( ofstream &, const char [] );
65
66void ends( ofstream & os );
67int fail( ofstream & );
68int flush( ofstream & );
69void open( ofstream &, const char name[], const char mode[] );
70void open( ofstream &, const char name[] );
71void close( ofstream & );
72ofstream & write( ofstream &, const char data[], size_t size );
73int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
74void acquire( ofstream & os );
75void release( ofstream & os );
76
77struct osacquire {
78        ofstream & os;
79};
80void ?{}( osacquire & acq, ofstream & os );
81void ^?{}( osacquire & acq );
82
83void ?{}( ofstream & os );
84void ?{}( ofstream & os, const char name[], const char mode[] );
85void ?{}( ofstream & os, const char name[] );
86void ^?{}( ofstream & os );
87
88extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
89extern ofstream & exit, & abort;
90
91
92// *********************************** ifstream ***********************************
93
94
95struct ifstream {
96        void * $file;
97        bool $nlOnOff;
98        multiple_acquisition_lock $lock;
99        bool $acquired;
100}; // ifstream
101
102// public
103void nlOn( ifstream & );
104void nlOff( ifstream & );
105bool getANL( ifstream & );
106void ends( ifstream & );
107int fail( ifstream & is );
108int eof( ifstream & is );
109void open( ifstream & is, const char name[], const char mode[] );
110void open( ifstream & is, const char name[] );
111void close( ifstream & is );
112ifstream & read( ifstream & is, char * data, size_t size );
113ifstream & ungetc( ifstream & is, char c );
114int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
115void acquire( ifstream & is );
116void release( ifstream & is );
117
118struct isacquire {
119        ifstream & is;
120};
121void ?{}( isacquire & acq, ifstream & is );
122void ^?{}( isacquire & acq );
123
124void ?{}( ifstream & is );
125void ?{}( ifstream & is, const char name[], const char mode[] );
126void ?{}( ifstream & is, const char name[] );
127void ^?{}( ifstream & is );
128
129extern ifstream & sin, & stdin;                                                 // aliases
130
131
132// *********************************** exceptions ***********************************
133
134
135EHM_EXCEPTION(Open_Failure)(
136        union {
137                ofstream * ostream;
138                ifstream * istream;
139        };
140        // TEMPORARY: need polymorphic exceptions
141        int tag;                                                                                        // 1 => ostream; 0 => istream
142);
143
144void ?{}( Open_Failure & this, ofstream & ostream );
145void ?{}( Open_Failure & this, ifstream & istream );
146
147// Local Variables: //
148// mode: c //
149// tab-width: 4 //
150// End: //
Note: See TracBrowser for help on using the repository browser.