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 : Fri Jun 19 16:29:17 2020 |
---|
13 | // Update Count : 189 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include "iostream.hfa" |
---|
19 | #include <exception.hfa> |
---|
20 | |
---|
21 | |
---|
22 | // *********************************** ofstream *********************************** |
---|
23 | |
---|
24 | |
---|
25 | enum { sepSize = 16 }; |
---|
26 | struct ofstream { |
---|
27 | void * $file; |
---|
28 | bool $sepDefault; |
---|
29 | bool $sepOnOff; |
---|
30 | bool $nlOnOff; |
---|
31 | bool $prt; // print text |
---|
32 | bool $sawNL; |
---|
33 | const char * $sepCur; |
---|
34 | char $separator[sepSize]; |
---|
35 | char $tupleSeparator[sepSize]; |
---|
36 | }; // ofstream |
---|
37 | |
---|
38 | // private |
---|
39 | bool $sepPrt( ofstream & ); |
---|
40 | void $sepReset( ofstream & ); |
---|
41 | void $sepReset( ofstream &, bool ); |
---|
42 | const char * $sepGetCur( ofstream & ); |
---|
43 | void $sepSetCur( ofstream &, const char [] ); |
---|
44 | bool $getNL( ofstream & ); |
---|
45 | void $setNL( ofstream &, bool ); |
---|
46 | bool $getANL( ofstream & ); |
---|
47 | bool $getPrt( ofstream & ); |
---|
48 | void $setPrt( ofstream &, bool ); |
---|
49 | |
---|
50 | // public |
---|
51 | void sepOn( ofstream & ); |
---|
52 | void sepOff( ofstream & ); |
---|
53 | bool sepDisable( ofstream & ); |
---|
54 | bool sepEnable( ofstream & ); |
---|
55 | void nlOn( ofstream & ); |
---|
56 | void nlOff( ofstream & ); |
---|
57 | |
---|
58 | const char * sepGet( ofstream & ); |
---|
59 | void sepSet( ofstream &, const char [] ); |
---|
60 | const char * sepGetTuple( ofstream & ); |
---|
61 | void sepSetTuple( ofstream &, const char [] ); |
---|
62 | |
---|
63 | void ends( ofstream & os ); |
---|
64 | int fail( ofstream & ); |
---|
65 | int flush( ofstream & ); |
---|
66 | void open( ofstream &, const char name[], const char mode[] ); |
---|
67 | void open( ofstream &, const char name[] ); |
---|
68 | void close( ofstream & ); |
---|
69 | ofstream & write( ofstream &, const char data[], size_t size ); |
---|
70 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); |
---|
71 | |
---|
72 | void ?{}( ofstream & os ); |
---|
73 | void ?{}( ofstream & os, const char name[], const char mode[] ); |
---|
74 | void ?{}( ofstream & os, const char name[] ); |
---|
75 | void ^?{}( ofstream & os ); |
---|
76 | |
---|
77 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases |
---|
78 | extern ofstream & exit, & abort; |
---|
79 | |
---|
80 | |
---|
81 | // *********************************** ifstream *********************************** |
---|
82 | |
---|
83 | |
---|
84 | struct ifstream { |
---|
85 | void * $file; |
---|
86 | bool $nlOnOff; |
---|
87 | }; // ifstream |
---|
88 | |
---|
89 | // public |
---|
90 | void nlOn( ifstream & ); |
---|
91 | void nlOff( ifstream & ); |
---|
92 | bool getANL( ifstream & ); |
---|
93 | int fail( ifstream & is ); |
---|
94 | int eof( ifstream & is ); |
---|
95 | void open( ifstream & is, const char name[], const char mode[] ); |
---|
96 | void open( ifstream & is, const char name[] ); |
---|
97 | void close( ifstream & is ); |
---|
98 | ifstream & read( ifstream & is, char * data, size_t size ); |
---|
99 | ifstream & ungetc( ifstream & is, char c ); |
---|
100 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); |
---|
101 | |
---|
102 | void ?{}( ifstream & is ); |
---|
103 | void ?{}( ifstream & is, const char name[], const char mode[] ); |
---|
104 | void ?{}( ifstream & is, const char name[] ); |
---|
105 | void ^?{}( ifstream & is ); |
---|
106 | |
---|
107 | extern ifstream & sin, & stdin; // aliases |
---|
108 | |
---|
109 | |
---|
110 | // *********************************** exceptions *********************************** |
---|
111 | |
---|
112 | |
---|
113 | DATA_EXCEPTION(Open_Failure)( |
---|
114 | union { |
---|
115 | ofstream * ostream; |
---|
116 | ifstream * istream; |
---|
117 | }; |
---|
118 | // TEMPORARY: need polymorphic exceptions |
---|
119 | int tag; // 1 => ostream; 0 => istream |
---|
120 | ); |
---|
121 | |
---|
122 | void ?{}( Open_Failure & this, ofstream & ostream ); |
---|
123 | void ?{}( Open_Failure & this, ifstream & istream ); |
---|
124 | |
---|
125 | // Local Variables: // |
---|
126 | // mode: c // |
---|
127 | // tab-width: 4 // |
---|
128 | // End: // |
---|