// // 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 : Sat Aug 11 08:22:49 2018 // Update Count : 156 // #pragma once #include "iterator" trait ostream( dtype ostype ) { // private bool sepPrt( ostype & ); // return 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 // 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 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 fmt[], ... ); }; // 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 &, bool ); ostype & ?|?( ostype &, char ); ostype & ?|?( ostype &, signed char ); ostype & ?|?( ostype &, unsigned char ); ostype & ?|?( ostype &, short int ); ostype & ?|?( ostype &, unsigned short int ); ostype & ?|?( ostype &, int ); ostype & ?|?( ostype &, unsigned int ); ostype & ?|?( ostype &, long int ); ostype & ?|?( ostype &, long long int ); ostype & ?|?( ostype &, unsigned long int ); ostype & ?|?( ostype &, unsigned long long int ); ostype & ?|?( ostype &, float ); // FIX ME: should not be required ostype & ?|?( ostype &, double ); ostype & ?|?( ostype &, long double ); ostype & ?|?( ostype &, float _Complex ); ostype & ?|?( ostype &, double _Complex ); ostype & ?|?( ostype &, long double _Complex ); ostype & ?|?( 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 * ); // manipulators ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); ostype & endl( ostype & ); ostype & sep( ostype & ); ostype & sepTuple( ostype & ); ostype & sepOn( ostype & ); ostype & sepOff( ostype & ); ostype & sepDisable( ostype & ); ostype & sepEnable( ostype & ); } // distribution // tuples forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) ostype & ?|?( ostype & os, T arg, Params rest ); // 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 ); forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) void write_reverse( iterator_type begin, iterator_type end, ostype & os ); //--------------------------------------- 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 fmt[], ... ); }; // 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 & endl( 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 ); forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time ); // Local Variables: // // mode: c // // tab-width: 4 // // End: //