source: libcfa/src/fstream.hfa@ adaee12

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since adaee12 was f451177, checked in by Peter A. Buhr <pabuhr@…>, 4 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
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 : Tue Apr 27 22:00:30 2021
13// Update Count : 226
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 { ofstream_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$[ofstream_sepSize];
36 char tupleSeparator$[ofstream_sepSize];
37 multiple_acquisition_lock lock$;
38 bool acquired$;
39}; // ofstream
40
41// Satisfies ostream
42
43// private
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 );
54
55// public
56void sepOn( ofstream & );
57void sepOff( ofstream & );
58bool sepDisable( ofstream & );
59bool sepEnable( ofstream & );
60void nlOn( ofstream & );
61void nlOff( ofstream & );
62
63const char * sepGet( ofstream & );
64void sepSet( ofstream &, const char [] );
65const char * sepGetTuple( ofstream & );
66void sepSetTuple( ofstream &, const char [] );
67
68void ends( ofstream & );
69int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
70
71bool fail( ofstream & );
72int flush( ofstream & );
73void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
74void open( ofstream &, const char name[] );
75void close( ofstream & );
76ofstream & write( ofstream &, const char data[], size_t size );
77
78void acquire( ofstream & );
79void release( ofstream & );
80
81struct osacquire {
82 ofstream & os;
83};
84void ?{}( osacquire & acq, ofstream & );
85void ^?{}( osacquire & acq );
86
87void ?{}( ofstream & );
88void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
89void ?{}( ofstream &, const char name[] );
90void ^?{}( ofstream & );
91
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
97extern ofstream & sout, & stdout, & serr, & stderr; // aliases
98extern ofstream & exit, & abort;
99
100
101// *********************************** ifstream ***********************************
102
103
104struct ifstream {
105 void * file$;
106 bool nlOnOff$;
107 multiple_acquisition_lock lock$;
108 bool acquired$;
109}; // ifstream
110
111// Satisfies istream
112
113// public
114void nlOn( ifstream & );
115void nlOff( ifstream & );
116bool getANL( ifstream & );
117void ends( ifstream & );
118int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
119
120bool fail( ifstream & is );
121int eof( ifstream & is );
122void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
123void open( ifstream & is, const char name[] );
124void close( ifstream & is );
125ifstream & read( ifstream & is, char * data, size_t size );
126ifstream & ungetc( ifstream & is, char c );
127
128void acquire( ifstream & is );
129void release( ifstream & is );
130
131struct isacquire {
132 ifstream & is;
133};
134void ?{}( isacquire & acq, ifstream & is );
135void ^?{}( isacquire & acq );
136
137void ?{}( ifstream & is );
138void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
139void ?{}( ifstream & is, const char name[] );
140void ^?{}( ifstream & is );
141
142extern ifstream & sin, & stdin; // aliases
143
144
145// *********************************** exceptions ***********************************
146
147
148EHM_EXCEPTION(Open_Failure)(
149 union {
150 ofstream * ostream;
151 ifstream * istream;
152 };
153 // TEMPORARY: need polymorphic exceptions
154 int tag; // 1 => ostream; 0 => istream
155);
156
157void ?{}( Open_Failure & this, ofstream & );
158void ?{}( Open_Failure & this, ifstream & );
159
160// Local Variables: //
161// mode: c //
162// tab-width: 4 //
163// End: //
Note: See TracBrowser for help on using the repository browser.