source: libcfa/src/fstream.hfa @ 9509d67a

Last change on this file since 9509d67a was d0cfcbe1, checked in by Peter A. Buhr <pabuhr@…>, 12 months ago

change setter routines in basic_i/ostream to return previous state

  • Property mode set to 100644
File size: 4.9 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
[d0cfcbe1]12// Last Modified On : Fri Aug 18 10:41:15 2023
13// Update Count     : 258
[86bd7c1f]14//
15
[53a6c2a]16#pragma once
[51b7345]17
[e474cf09]18#include "bits/weakso_locks.hfa"                                                // mutex_lock
[58b6d1b]19#include "iostream.hfa"
[51b7345]20
[65240bb]21
[8d321f9]22// *********************************** ofstream ***********************************
[65240bb]23
24
[b431515]25enum { ofstream_sepSize = 16 };
[53ba273]26struct ofstream {
[6c5d92f]27        void * file$;
28        bool sepDefault$;
29        bool sepOnOff$;
30        bool nlOnOff$;
31        bool prt$;                                                                                      // print text
32        bool sawNL$;
33        const char * sepCur$;
[b431515]34        char separator$[ofstream_sepSize];
35        char tupleSeparator$[ofstream_sepSize];
[502a107]36        multiple_acquisition_lock lock$;                                        // used by trait is_lock for mutex statement
[53ba273]37}; // ofstream
[90c3b1c]38
[b431515]39// Satisfies ostream
40
[9ebd778]41// private
[f5d9c37]42bool getNL$( ofstream & );
[d0cfcbe1]43bool setNL$( ofstream &, bool );
[f5d9c37]44bool getANL$( ofstream & );
[d0cfcbe1]45bool setANL$( ofstream &, bool );
[f5d9c37]46
[6c5d92f]47bool sepPrt$( ofstream & );
48void sepReset$( ofstream & );
49void sepReset$( ofstream &, bool );
50const char * sepGetCur$( ofstream & );
51void sepSetCur$( ofstream &, const char [] );
[f5d9c37]52
[6c5d92f]53bool getPrt$( ofstream & );
[d0cfcbe1]54bool setPrt$( ofstream &, bool );
[9ebd778]55
[7ce2483]56void lock( ofstream & );
57void unlock( ofstream & );
58
[9ebd778]59// public
[200fcb3]60void nlOn( ofstream & );
61void nlOff( ofstream & );
[9ebd778]62
[f5d9c37]63void sep( ofstream & );
64void nosep( ofstream & );
65bool sepOn( ofstream & );
66bool sepOff( ofstream & );
[09687aa]67const char * sepGet( ofstream & );
[e3fea42]68void sepSet( ofstream &, const char [] );
[09687aa]69const char * sepGetTuple( ofstream & );
[e3fea42]70void sepSetTuple( ofstream &, const char [] );
[6152c81]71
[b431515]72void ends( ofstream & );
73int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
74
75bool fail( ofstream & );
[00e9be9]76void clear( ofstream & );
[09687aa]77int flush( ofstream & );
[f451177]78void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
[e3fea42]79void open( ofstream &, const char name[] );
[09687aa]80void close( ofstream & );
[c8371b5]81
[e3fea42]82ofstream & write( ofstream &, const char data[], size_t size );
[b431515]83
84void ?{}( ofstream & );
[f451177]85void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
[b431515]86void ?{}( ofstream &, const char name[] );
87void ^?{}( ofstream & );
[09687aa]88
[f451177]89// private
90static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
91// public
92ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
93
[a87d40b]94extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
[65240bb]95extern ofstream & exit, & abort;
96
[51b7345]97
[8d321f9]98// *********************************** ifstream ***********************************
[5cb2b8c]99
[51b7345]100
[53ba273]101struct ifstream {
[6c5d92f]102        void * file$;
103        bool nlOnOff$;
[502a107]104        multiple_acquisition_lock lock$;                                        // used by trait is_lock for mutex statement
[53ba273]105}; // ifstream
[6ba0659]106
[b431515]107// Satisfies istream
108
[7ce2483]109// private
[c8371b5]110bool getANL$( ifstream & );
[d0cfcbe1]111bool setANL$( ifstream &, bool );
[c8371b5]112
[7ce2483]113void lock( ifstream & );
114void unlock( ifstream & );
115
[09687aa]116// public
[0efb269]117void nlOn( ifstream & );
118void nlOff( ifstream & );
[e474cf09]119void ends( ifstream & );
[f451177]120int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
121
[b431515]122bool fail( ifstream & is );
[00e9be9]123void clear( ifstream & );
124bool eof( ifstream & is );
[f451177]125void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
[e3fea42]126void open( ifstream & is, const char name[] );
[09687aa]127void close( ifstream & is );
[c8371b5]128
[00e9be9]129ifstream & read( ifstream & is, char data[], size_t size );
[09687aa]130ifstream & ungetc( ifstream & is, char c );
[f451177]131
[09687aa]132void ?{}( ifstream & is );
[f451177]133void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
[e3fea42]134void ?{}( ifstream & is, const char name[] );
[4cae032]135void ^?{}( ifstream & is );
[51b7345]136
[a87d40b]137extern ifstream & sin, & stdin;                                                 // aliases
[51b7345]138
[91e52be]139
[8d321f9]140// *********************************** exceptions ***********************************
[91e52be]141
142
[874b16e]143exception open_failure {
[91e52be]144        union {
145                ofstream * ostream;
146                ifstream * istream;
147        };
[8d321f9]148        // TEMPORARY: need polymorphic exceptions
149        int tag;                                                                                        // 1 => ostream; 0 => istream
[f9d8755]150};
[91e52be]151
[874b16e]152void ?{}( open_failure & this, ofstream & );
153void ?{}( open_failure & this, ifstream & );
[91e52be]154
[874b16e]155exception close_failure {
[ba0d2ea]156        union {
157                ofstream * ostream;
158                ifstream * istream;
159        };
160        // TEMPORARY: need polymorphic exceptions
161        int tag;                                                                                        // 1 => ostream; 0 => istream
162};
163
[874b16e]164void ?{}( close_failure & this, ofstream & );
165void ?{}( close_failure & this, ifstream & );
[ba0d2ea]166
[874b16e]167exception write_failure {
[ba0d2ea]168        union {
169                ofstream * ostream;
170                ifstream * istream;
171        };
172        // TEMPORARY: need polymorphic exceptions
173        int tag;                                                                                        // 1 => ostream; 0 => istream
174};
175
[874b16e]176void ?{}( write_failure & this, ofstream & );
177void ?{}( write_failure & this, ifstream & );
[ba0d2ea]178
[874b16e]179exception read_failure {
[ba0d2ea]180        union {
181                ofstream * ostream;
182                ifstream * istream;
183        };
184        // TEMPORARY: need polymorphic exceptions
185        int tag;                                                                                        // 1 => ostream; 0 => istream
186};
187
[874b16e]188void ?{}( read_failure & this, ofstream & );
189void ?{}( read_failure & this, ifstream & );
[ba0d2ea]190
[86bd7c1f]191// Local Variables: //
[d3b7937]192// mode: c //
[86bd7c1f]193// tab-width: 4 //
194// End: //
Note: See TracBrowser for help on using the repository browser.