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 : Sat Apr 24 09:04:03 2021 |
---|
13 | // Update Count : 219 |
---|
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 | |
---|
26 | enum { ofstream_sepSize = 16 }; |
---|
27 | struct 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 |
---|
44 | bool sepPrt$( ofstream & ); |
---|
45 | void sepReset$( ofstream & ); |
---|
46 | void sepReset$( ofstream &, bool ); |
---|
47 | const char * sepGetCur$( ofstream & ); |
---|
48 | void sepSetCur$( ofstream &, const char [] ); |
---|
49 | bool getNL$( ofstream & ); |
---|
50 | void setNL$( ofstream &, bool ); |
---|
51 | bool getANL$( ofstream & ); |
---|
52 | bool getPrt$( ofstream & ); |
---|
53 | void setPrt$( ofstream &, bool ); |
---|
54 | |
---|
55 | // public |
---|
56 | void sepOn( ofstream & ); |
---|
57 | void sepOff( ofstream & ); |
---|
58 | bool sepDisable( ofstream & ); |
---|
59 | bool sepEnable( ofstream & ); |
---|
60 | void nlOn( ofstream & ); |
---|
61 | void nlOff( ofstream & ); |
---|
62 | |
---|
63 | const char * sepGet( ofstream & ); |
---|
64 | void sepSet( ofstream &, const char [] ); |
---|
65 | const char * sepGetTuple( ofstream & ); |
---|
66 | void sepSetTuple( ofstream &, const char [] ); |
---|
67 | |
---|
68 | void ends( ofstream & ); |
---|
69 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
70 | |
---|
71 | bool fail( ofstream & ); |
---|
72 | int flush( ofstream & ); |
---|
73 | void open( ofstream &, const char name[], const char mode[] ); |
---|
74 | void open( ofstream &, const char name[] ); |
---|
75 | void close( ofstream & ); |
---|
76 | ofstream & write( ofstream &, const char data[], size_t size ); |
---|
77 | |
---|
78 | void acquire( ofstream & ); |
---|
79 | void release( ofstream & ); |
---|
80 | |
---|
81 | struct osacquire { |
---|
82 | ofstream & os; |
---|
83 | }; |
---|
84 | void ?{}( osacquire & acq, ofstream & ); |
---|
85 | void ^?{}( osacquire & acq ); |
---|
86 | |
---|
87 | void ?{}( ofstream & ); |
---|
88 | void ?{}( ofstream &, const char name[], const char mode[] ); |
---|
89 | void ?{}( ofstream &, const char name[] ); |
---|
90 | void ^?{}( ofstream & ); |
---|
91 | |
---|
92 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases |
---|
93 | extern ofstream & exit, & abort; |
---|
94 | |
---|
95 | |
---|
96 | // *********************************** ifstream *********************************** |
---|
97 | |
---|
98 | |
---|
99 | struct ifstream { |
---|
100 | void * file$; |
---|
101 | bool nlOnOff$; |
---|
102 | multiple_acquisition_lock lock$; |
---|
103 | bool acquired$; |
---|
104 | }; // ifstream |
---|
105 | |
---|
106 | // Satisfies istream |
---|
107 | |
---|
108 | // public |
---|
109 | void nlOn( ifstream & ); |
---|
110 | void nlOff( ifstream & ); |
---|
111 | bool getANL( ifstream & ); |
---|
112 | void ends( ifstream & ); |
---|
113 | bool fail( ifstream & is ); |
---|
114 | int eof( ifstream & is ); |
---|
115 | void open( ifstream & is, const char name[], const char mode[] ); |
---|
116 | void open( ifstream & is, const char name[] ); |
---|
117 | void close( ifstream & is ); |
---|
118 | ifstream & read( ifstream & is, char * data, size_t size ); |
---|
119 | ifstream & ungetc( ifstream & is, char c ); |
---|
120 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); |
---|
121 | void acquire( ifstream & is ); |
---|
122 | void release( ifstream & is ); |
---|
123 | |
---|
124 | struct isacquire { |
---|
125 | ifstream & is; |
---|
126 | }; |
---|
127 | void ?{}( isacquire & acq, ifstream & is ); |
---|
128 | void ^?{}( isacquire & acq ); |
---|
129 | |
---|
130 | void ?{}( ifstream & is ); |
---|
131 | void ?{}( ifstream & is, const char name[], const char mode[] ); |
---|
132 | void ?{}( ifstream & is, const char name[] ); |
---|
133 | void ^?{}( ifstream & is ); |
---|
134 | |
---|
135 | extern ifstream & sin, & stdin; // aliases |
---|
136 | |
---|
137 | |
---|
138 | // *********************************** exceptions *********************************** |
---|
139 | |
---|
140 | |
---|
141 | EHM_EXCEPTION(Open_Failure)( |
---|
142 | union { |
---|
143 | ofstream * ostream; |
---|
144 | ifstream * istream; |
---|
145 | }; |
---|
146 | // TEMPORARY: need polymorphic exceptions |
---|
147 | int tag; // 1 => ostream; 0 => istream |
---|
148 | ); |
---|
149 | |
---|
150 | void ?{}( Open_Failure & this, ofstream & ); |
---|
151 | void ?{}( Open_Failure & this, ifstream & ); |
---|
152 | |
---|
153 | // Local Variables: // |
---|
154 | // mode: c // |
---|
155 | // tab-width: 4 // |
---|
156 | // End: // |
---|