// // 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 : Tue Feb 26 16:57:22 2019 // Update Count : 221 // #pragma once #include "iterator.hfa" trait ostream( dtype ostype ) { // private bool sepPrt( ostype & ); // get separator state (on/off) void sepReset( ostype & ); // set separator state to default state void sepReset( ostype &, bool ); // set separator and default state const char * sepGetCur( ostype & ); // get current separator string void sepSetCur( ostype &, const char * ); // set current separator string bool getNL( ostype & ); // check newline void setNL( ostype &, bool ); // saw newline bool getANL( ostype & ); // get auto newline (on/off) bool getPrt( ostype & ); // get fmt called in output cascade void setPrt( ostype &, bool ); // set fmt called in output cascade // public void sepOn( ostype & ); // turn separator state on void sepOff( ostype & ); // turn separator state off bool sepDisable( ostype & ); // set default state to off, and return previous state bool sepEnable( ostype & ); // set default state to on, and return previous state void nlOn( ostype & ); // turn auto-newline state on void nlOff( ostype & ); // turn auto-newline state off const char * sepGet( ostype & ); // get separator string void sepSet( ostype &, const char * ); // set separator to string (15 character maximum) const char * sepGetTuple( ostype & ); // get tuple separator string void sepSetTuple( ostype &, const char * ); // set tuple separator to string (15 character maximum) 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 *, size_t ); int fmt( ostype &, const char format[], ... ); }; // ostream // trait writeable( otype T ) { // forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T ); // }; // writeable trait writeable( otype T, dtype ostype | ostream( ostype ) ) { ostype & ?|?( ostype &, T ); }; // writeable // implement writable for intrinsic types forall( dtype ostype | ostream( ostype ) ) { ostype & ?|?( ostype &, zero_t ); void ?|?( ostype &, zero_t ); ostype & ?|?( ostype &, one_t ); void ?|?( ostype &, one_t ); ostype & ?|?( ostype &, bool ); void ?|?( ostype &, bool ); ostype & ?|?( ostype &, char ); void ?|?( ostype &, char ); ostype & ?|?( ostype &, signed char ); void ?|?( ostype &, signed char ); ostype & ?|?( ostype &, unsigned char ); void ?|?( ostype &, unsigned char ); ostype & ?|?( ostype &, short int ); void ?|?( ostype &, short int ); ostype & ?|?( ostype &, unsigned short int ); void ?|?( ostype &, unsigned short int ); ostype & ?|?( ostype &, int ); void ?|?( ostype &, int ); ostype & ?|?( ostype &, unsigned int ); void ?|?( ostype &, unsigned int ); ostype & ?|?( ostype &, long int ); void ?|?( ostype &, long int ); ostype & ?|?( ostype &, long long int ); void ?|?( ostype &, long long int ); ostype & ?|?( ostype &, unsigned long int ); void ?|?( ostype &, unsigned long int ); ostype & ?|?( ostype &, unsigned long long int ); void ?|?( ostype &, unsigned long long int ); ostype & ?|?( ostype &, float ); // FIX ME: should not be required void ?|?( ostype &, float ); // FIX ME: should not be required ostype & ?|?( ostype &, double ); void ?|?( ostype &, double ); ostype & ?|?( ostype &, long double ); void ?|?( ostype &, long double ); ostype & ?|?( ostype &, float _Complex ); void ?|?( ostype &, float _Complex ); ostype & ?|?( ostype &, double _Complex ); void ?|?( ostype &, double _Complex ); ostype & ?|?( ostype &, long double _Complex ); void ?|?( ostype &, long double _Complex ); ostype & ?|?( ostype &, const char * ); void ?|?( ostype &, const char * ); // ostype & ?|?( ostype &, const char16_t * ); #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous // ostype & ?|?( ostype &, const char32_t * ); #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // ostype & ?|?( ostype &, const wchar_t * ); ostype & ?|?( ostype &, const void * ); void ?|?( ostype &, const void * ); // manipulators ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); void ?|?( ostype &, ostype & (*)( ostype & ) ); ostype & nl( ostype & ); void nl( ostype & ); ostype & nonl( ostype & ); ostype & sep( ostype & ); ostype & sepTuple( ostype & ); ostype & sepOn( ostype & ); ostype & sepOff( ostype & ); ostype & sepDisable( ostype & ); ostype & sepEnable( ostype & ); ostype & nlOn( ostype & ); ostype & nlOff( ostype & ); } // distribution // tuples forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { ostype & ?|?( ostype & os, T arg, Params rest ); void ?|?( ostype & os, T arg, Params rest ); } // distribution // writes the range [begin, end) to the given stream forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) { void write( iterator_type begin, iterator_type end, ostype & os ); void write_reverse( iterator_type begin, iterator_type end, ostype & os ); } // distribution //--------------------------------------- trait istream( dtype istype ) { int fail( istype & ); int eof( istype & ); void open( istype & is, const char * name ); void close( istype & is ); istype & read( istype &, char *, size_t ); istype & ungetc( istype &, char ); int fmt( istype &, const char format[], ... ); }; // istream trait readable( otype T ) { forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T ); }; // readable forall( dtype istype | istream( istype ) ) { istype & ?|?( istype &, bool & ); istype & ?|?( istype &, char & ); istype & ?|?( istype &, signed char & ); istype & ?|?( istype &, unsigned char & ); istype & ?|?( istype &, short int & ); istype & ?|?( istype &, unsigned short int & ); istype & ?|?( istype &, int & ); istype & ?|?( istype &, unsigned int & ); istype & ?|?( istype &, long int & ); istype & ?|?( istype &, long long int & ); istype & ?|?( istype &, unsigned long int & ); istype & ?|?( istype &, unsigned long long int & ); istype & ?|?( istype &, float & ); istype & ?|?( istype &, double & ); istype & ?|?( istype &, long double & ); istype & ?|?( istype &, float _Complex & ); istype & ?|?( istype &, double _Complex & ); istype & ?|?( istype &, long double _Complex & ); // manipulators istype & ?|?( istype &, istype & (*)( istype & ) ); istype & nl( istype & is ); } // distribution 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 ); #include // Duration (constructors) / Time (constructors) forall( dtype ostype | ostream( ostype ) ) { ostype & ?|?( ostype & os, Duration dur ); void ?|?( ostype & os, Duration dur ); ostype & ?|?( ostype & os, Time time ); void ?|?( ostype & os, Time time ); } // distribution // Local Variables: // // mode: c // // tab-width: 4 // // End: //