// // 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. // // iostream -- // // Author : Peter A. Buhr // Created On : Wed May 27 17:56:53 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Thu Feb 23 22:27:53 2017 // Update Count : 94 // #ifndef __IOSTREAM_H__ #define __IOSTREAM_H__ #include "iterator" trait ostream( dtype ostype ) { _Bool sepPrt( ostype * ); // return separator state (on/off) void sepOn( ostype * ); // turn separator state on void sepOff( ostype * ); // turn separator state off void sepReset( ostype * ); // set separator state to default state void sepReset( ostype *, _Bool ); // set separator and default state void sepSet( ostype *, const char * ); // set separator to string (15 character maximum) const char * sepGet( ostype * ); // get separator string _Bool sepDisable( ostype * ); // set default state to off, and return previous state _Bool sepEnable( ostype * ); // set default state to on, and return previous state int fail( ostype * ); int flush( ostype * ); void open( ostype * os, const char * name, const char * mode ); void close( ostype * os ); ostype * write( ostype *, const char *, unsigned long int ); int prtfmt( ostype *, const char fmt[], ... ); }; trait writeable( otype T ) { forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); }; // implement writable for intrinsic types forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, signed char ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned char ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, short int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned short int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long long int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long long int ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float ); // FIX ME: should not be required forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float _Complex ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double _Complex ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double _Complex ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * ); forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) ); // manipulators forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * ); forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * ); forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * ); forall( dtype ostype | ostream( ostype ) ) ostype * sepDisable( ostype * ); forall( dtype ostype | ostream( ostype ) ) ostype * sepEnable( ostype * ); // writes the range [begin, end) to the given stream forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) ) void write( iterator_type begin, iterator_type end, os_type *os ); forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) ) void write_reverse( iterator_type begin, iterator_type end, os_type *os ); //--------------------------------------- trait istream( dtype istype ) { int fail( istype * ); int eof( istype * ); void open( istype * is, const char * name, const char * mode ); void close( istype * is ); istype * read( istype *, char *, unsigned long int ); istype * ungetc( istype *, char ); int scanfmt( istype *, const char fmt[], ... ); }; trait readable( otype T ) { forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T ); }; forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * ); struct _Istream_cstrUC { char * s; }; _Istream_cstrUC cstr( char * ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrUC ); struct _Istream_cstrC { char * s; int size; }; _Istream_cstrC cstr( char *, int size ); forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC ); #endif // __IOSTREAM_H // Local Variables: // // mode: c // // tab-width: 4 // // End: //