source: libcfa/src/fstream.hfa @ 797a193

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 797a193 was 8d321f9, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

adjust / comments, change exception name from IO_OPEN_FAILURE to Open_Failure, add temporary Open_Failure tag in lieu of polymorphic exceptions

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