// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // fstream -- // // Author : Peter A. Buhr // Created On : Wed May 27 17:56:53 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Mon Mar 1 22:45:08 2021 // Update Count : 217 // #pragma once #include "bits/weakso_locks.hfa" // mutex_lock #include "iostream.hfa" #include // *********************************** ofstream *********************************** enum { sepSize = 16 }; struct ofstream { void * $file; bool $sepDefault; bool $sepOnOff; bool $nlOnOff; bool $prt; // print text bool $sawNL; const char * $sepCur; char $separator[sepSize]; char $tupleSeparator[sepSize]; multiple_acquisition_lock $lock; bool $acquired; }; // ofstream // private bool $sepPrt( ofstream & ); void $sepReset( ofstream & ); void $sepReset( ofstream &, bool ); const char * $sepGetCur( ofstream & ); void $sepSetCur( ofstream &, const char [] ); bool $getNL( ofstream & ); void $setNL( ofstream &, bool ); bool $getANL( ofstream & ); bool $getPrt( ofstream & ); void $setPrt( ofstream &, bool ); // public void sepOn( ofstream & ); void sepOff( ofstream & ); bool sepDisable( ofstream & ); bool sepEnable( ofstream & ); void nlOn( ofstream & ); void nlOff( ofstream & ); const char * sepGet( ofstream & ); void sepSet( ofstream &, const char [] ); const char * sepGetTuple( ofstream & ); void sepSetTuple( ofstream &, const char [] ); void ends( ofstream & os ); int fail( ofstream & ); int flush( ofstream & ); void open( ofstream &, const char name[], const char mode[] ); void open( ofstream &, const char name[] ); void close( ofstream & ); ofstream & write( ofstream &, const char data[], size_t size ); int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) )); void acquire( ofstream & os ); void release( ofstream & os ); struct osacquire { ofstream & os; }; void ?{}( osacquire & acq, ofstream & os ); void ^?{}( osacquire & acq ); void ?{}( ofstream & os ); void ?{}( ofstream & os, const char name[], const char mode[] ); void ?{}( ofstream & os, const char name[] ); void ^?{}( ofstream & os ); extern ofstream & sout, & stdout, & serr, & stderr; // aliases extern ofstream & exit, & abort; // *********************************** ifstream *********************************** struct ifstream { void * $file; bool $nlOnOff; multiple_acquisition_lock $lock; bool $acquired; }; // ifstream // public void nlOn( ifstream & ); void nlOff( ifstream & ); bool getANL( ifstream & ); void ends( ifstream & ); int fail( ifstream & is ); int eof( ifstream & is ); void open( ifstream & is, const char name[], const char mode[] ); void open( ifstream & is, const char name[] ); void close( ifstream & is ); ifstream & read( ifstream & is, char * data, size_t size ); ifstream & ungetc( ifstream & is, char c ); int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) )); void acquire( ifstream & is ); void release( ifstream & is ); struct isacquire { ifstream & is; }; void ?{}( isacquire & acq, ifstream & is ); void ^?{}( isacquire & acq ); void ?{}( ifstream & is ); void ?{}( ifstream & is, const char name[], const char mode[] ); void ?{}( ifstream & is, const char name[] ); void ^?{}( ifstream & is ); extern ifstream & sin, & stdin; // aliases // *********************************** exceptions *********************************** DATA_EXCEPTION(Open_Failure)( union { ofstream * ostream; ifstream * istream; }; // TEMPORARY: need polymorphic exceptions int tag; // 1 => ostream; 0 => istream ); void ?{}( Open_Failure & this, ofstream & ostream ); void ?{}( Open_Failure & this, ifstream & istream ); // Local Variables: // // mode: c // // tab-width: 4 // // End: //