| 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 "bits/weakso_locks.hfa"
|
|---|
| 19 | #include "iostream.hfa"
|
|---|
| 20 | #include <exception.hfa>
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | // *********************************** ofstream ***********************************
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | enum { 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[sepSize];
|
|---|
| 36 | char $tupleSeparator[sepSize];
|
|---|
| 37 | // multiple_acquisition_lock lock;
|
|---|
| 38 | }; // ofstream
|
|---|
| 39 |
|
|---|
| 40 | // private
|
|---|
| 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 );
|
|---|
| 51 |
|
|---|
| 52 | // public
|
|---|
| 53 | void sepOn( ofstream & );
|
|---|
| 54 | void sepOff( ofstream & );
|
|---|
| 55 | bool sepDisable( ofstream & );
|
|---|
| 56 | bool sepEnable( ofstream & );
|
|---|
| 57 | void nlOn( ofstream & );
|
|---|
| 58 | void nlOff( ofstream & );
|
|---|
| 59 |
|
|---|
| 60 | const char * sepGet( ofstream & );
|
|---|
| 61 | void sepSet( ofstream &, const char [] );
|
|---|
| 62 | const char * sepGetTuple( ofstream & );
|
|---|
| 63 | void sepSetTuple( ofstream &, const char [] );
|
|---|
| 64 |
|
|---|
| 65 | void ends( ofstream & os );
|
|---|
| 66 | int fail( ofstream & );
|
|---|
| 67 | int flush( ofstream & );
|
|---|
| 68 | void open( ofstream &, const char name[], const char mode[] );
|
|---|
| 69 | void open( ofstream &, const char name[] );
|
|---|
| 70 | void close( ofstream & );
|
|---|
| 71 | ofstream & write( ofstream &, const char data[], size_t size );
|
|---|
| 72 | int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
|
|---|
| 73 |
|
|---|
| 74 | void ?{}( ofstream & os );
|
|---|
| 75 | void ?{}( ofstream & os, const char name[], const char mode[] );
|
|---|
| 76 | void ?{}( ofstream & os, const char name[] );
|
|---|
| 77 | void ^?{}( ofstream & os );
|
|---|
| 78 |
|
|---|
| 79 | extern ofstream & sout, & stdout, & serr, & stderr; // aliases
|
|---|
| 80 | extern ofstream & exit, & abort;
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | // *********************************** ifstream ***********************************
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | struct ifstream {
|
|---|
| 87 | void * $file;
|
|---|
| 88 | bool $nlOnOff;
|
|---|
| 89 | }; // ifstream
|
|---|
| 90 |
|
|---|
| 91 | // public
|
|---|
| 92 | void nlOn( ifstream & );
|
|---|
| 93 | void nlOff( ifstream & );
|
|---|
| 94 | bool getANL( ifstream & );
|
|---|
| 95 | int fail( ifstream & is );
|
|---|
| 96 | int eof( ifstream & is );
|
|---|
| 97 | void open( ifstream & is, const char name[], const char mode[] );
|
|---|
| 98 | void open( ifstream & is, const char name[] );
|
|---|
| 99 | void close( ifstream & is );
|
|---|
| 100 | ifstream & read( ifstream & is, char * data, size_t size );
|
|---|
| 101 | ifstream & ungetc( ifstream & is, char c );
|
|---|
| 102 | int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
|
|---|
| 103 |
|
|---|
| 104 | void ?{}( ifstream & is );
|
|---|
| 105 | void ?{}( ifstream & is, const char name[], const char mode[] );
|
|---|
| 106 | void ?{}( ifstream & is, const char name[] );
|
|---|
| 107 | void ^?{}( ifstream & is );
|
|---|
| 108 |
|
|---|
| 109 | extern ifstream & sin, & stdin; // aliases
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | // *********************************** exceptions ***********************************
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | DATA_EXCEPTION(Open_Failure)(
|
|---|
| 116 | union {
|
|---|
| 117 | ofstream * ostream;
|
|---|
| 118 | ifstream * istream;
|
|---|
| 119 | };
|
|---|
| 120 | // TEMPORARY: need polymorphic exceptions
|
|---|
| 121 | int tag; // 1 => ostream; 0 => istream
|
|---|
| 122 | );
|
|---|
| 123 |
|
|---|
| 124 | void ?{}( Open_Failure & this, ofstream & ostream );
|
|---|
| 125 | void ?{}( Open_Failure & this, ifstream & istream );
|
|---|
| 126 |
|
|---|
| 127 | // Local Variables: //
|
|---|
| 128 | // mode: c //
|
|---|
| 129 | // tab-width: 4 //
|
|---|
| 130 | // End: //
|
|---|