[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
|
---|
[8d321f9] | 12 | // Last Modified On : Fri Jun 19 16:29:17 2020
|
---|
| 13 | // Update Count : 189
|
---|
[86bd7c1f] | 14 | //
|
---|
| 15 |
|
---|
[53a6c2a] | 16 | #pragma once
|
---|
[51b73452] | 17 |
|
---|
[58b6d1b] | 18 | #include "iostream.hfa"
|
---|
[91e52be] | 19 | #include <exception.hfa>
|
---|
[51b73452] | 20 |
|
---|
[65240bb] | 21 |
|
---|
[8d321f9] | 22 | // *********************************** ofstream ***********************************
|
---|
[65240bb] | 23 |
|
---|
| 24 |
|
---|
[53a6c2a] | 25 | enum { sepSize = 16 };
|
---|
[53ba273] | 26 | struct ofstream {
|
---|
[d1a9ff5] | 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];
|
---|
[53ba273] | 36 | }; // ofstream
|
---|
[90c3b1c] | 37 |
|
---|
[9ebd778] | 38 | // private
|
---|
[d1a9ff5] | 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 );
|
---|
[9ebd778] | 49 |
|
---|
| 50 | // public
|
---|
[09687aa] | 51 | void sepOn( ofstream & );
|
---|
| 52 | void sepOff( ofstream & );
|
---|
[93c2e0a] | 53 | bool sepDisable( ofstream & );
|
---|
| 54 | bool sepEnable( ofstream & );
|
---|
[200fcb3] | 55 | void nlOn( ofstream & );
|
---|
| 56 | void nlOff( ofstream & );
|
---|
[9ebd778] | 57 |
|
---|
[09687aa] | 58 | const char * sepGet( ofstream & );
|
---|
[e3fea42] | 59 | void sepSet( ofstream &, const char [] );
|
---|
[09687aa] | 60 | const char * sepGetTuple( ofstream & );
|
---|
[e3fea42] | 61 | void sepSetTuple( ofstream &, const char [] );
|
---|
[6152c81] | 62 |
|
---|
[65240bb] | 63 | void ends( ofstream & os );
|
---|
[09687aa] | 64 | int fail( ofstream & );
|
---|
| 65 | int flush( ofstream & );
|
---|
[e3fea42] | 66 | void open( ofstream &, const char name[], const char mode[] );
|
---|
| 67 | void open( ofstream &, const char name[] );
|
---|
[09687aa] | 68 | void close( ofstream & );
|
---|
[e3fea42] | 69 | ofstream & write( ofstream &, const char data[], size_t size );
|
---|
[40cac90] | 70 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
|
---|
[829c907] | 71 |
|
---|
[09687aa] | 72 | void ?{}( ofstream & os );
|
---|
[e3fea42] | 73 | void ?{}( ofstream & os, const char name[], const char mode[] );
|
---|
| 74 | void ?{}( ofstream & os, const char name[] );
|
---|
[4cae032] | 75 | void ^?{}( ofstream & os );
|
---|
[09687aa] | 76 |
|
---|
[a87d40b] | 77 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases
|
---|
[65240bb] | 78 | extern ofstream & exit, & abort;
|
---|
| 79 |
|
---|
[51b73452] | 80 |
|
---|
[8d321f9] | 81 | // *********************************** ifstream ***********************************
|
---|
[5cb2b8c] | 82 |
|
---|
[51b73452] | 83 |
|
---|
[53ba273] | 84 | struct ifstream {
|
---|
[d1a9ff5] | 85 | void * $file;
|
---|
| 86 | bool $nlOnOff;
|
---|
[53ba273] | 87 | }; // ifstream
|
---|
[6ba0659] | 88 |
|
---|
[09687aa] | 89 | // public
|
---|
[0efb269] | 90 | void nlOn( ifstream & );
|
---|
| 91 | void nlOff( ifstream & );
|
---|
| 92 | bool getANL( ifstream & );
|
---|
[09687aa] | 93 | int fail( ifstream & is );
|
---|
| 94 | int eof( ifstream & is );
|
---|
[e3fea42] | 95 | void open( ifstream & is, const char name[], const char mode[] );
|
---|
| 96 | void open( ifstream & is, const char name[] );
|
---|
[09687aa] | 97 | void close( ifstream & is );
|
---|
[91d766d] | 98 | ifstream & read( ifstream & is, char * data, size_t size );
|
---|
[09687aa] | 99 | ifstream & ungetc( ifstream & is, char c );
|
---|
[40cac90] | 100 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
|
---|
[09687aa] | 101 |
|
---|
| 102 | void ?{}( ifstream & is );
|
---|
[e3fea42] | 103 | void ?{}( ifstream & is, const char name[], const char mode[] );
|
---|
| 104 | void ?{}( ifstream & is, const char name[] );
|
---|
[4cae032] | 105 | void ^?{}( ifstream & is );
|
---|
[51b73452] | 106 |
|
---|
[a87d40b] | 107 | extern ifstream & sin, & stdin; // aliases
|
---|
[51b73452] | 108 |
|
---|
[91e52be] | 109 |
|
---|
[8d321f9] | 110 | // *********************************** exceptions ***********************************
|
---|
[91e52be] | 111 |
|
---|
| 112 |
|
---|
[8d321f9] | 113 | DATA_EXCEPTION(Open_Failure)(
|
---|
[91e52be] | 114 | union {
|
---|
| 115 | ofstream * ostream;
|
---|
| 116 | ifstream * istream;
|
---|
| 117 | };
|
---|
[8d321f9] | 118 | // TEMPORARY: need polymorphic exceptions
|
---|
| 119 | int tag; // 1 => ostream; 0 => istream
|
---|
[91e52be] | 120 | );
|
---|
| 121 |
|
---|
[8d321f9] | 122 | void ?{}( Open_Failure & this, ofstream & ostream );
|
---|
| 123 | void ?{}( Open_Failure & this, ifstream & istream );
|
---|
[91e52be] | 124 |
|
---|
[86bd7c1f] | 125 | // Local Variables: //
|
---|
[d3b7937] | 126 | // mode: c //
|
---|
[86bd7c1f] | 127 | // tab-width: 4 //
|
---|
| 128 | // End: //
|
---|