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