[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 | // iostream -- |
---|
[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 |
---|
[93c2e0a] | 12 | // Last Modified On : Sat Aug 11 08:22:49 2018 |
---|
| 13 | // Update Count : 156 |
---|
[86bd7c1f] | 14 | // |
---|
| 15 | |
---|
[53a6c2a] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[58b6d1b] | 18 | #include "iterator.hfa" |
---|
[e56cfdb0] | 19 | |
---|
[4040425] | 20 | trait ostream( dtype ostype ) { |
---|
[9ebd778] | 21 | // private |
---|
[93c2e0a] | 22 | bool sepPrt( ostype & ); // return separator state (on/off) |
---|
[09687aa] | 23 | void sepReset( ostype & ); // set separator state to default state |
---|
[93c2e0a] | 24 | void sepReset( ostype &, bool ); // set separator and default state |
---|
[09687aa] | 25 | const char * sepGetCur( ostype & ); // get current separator string |
---|
| 26 | void sepSetCur( ostype &, const char * ); // set current separator string |
---|
[93c2e0a] | 27 | bool getNL( ostype & ); // check newline |
---|
| 28 | void setNL( ostype &, bool ); // saw newline |
---|
[9ebd778] | 29 | // public |
---|
[09687aa] | 30 | void sepOn( ostype & ); // turn separator state on |
---|
| 31 | void sepOff( ostype & ); // turn separator state off |
---|
[93c2e0a] | 32 | bool sepDisable( ostype & ); // set default state to off, and return previous state |
---|
| 33 | bool sepEnable( ostype & ); // set default state to on, and return previous state |
---|
[09687aa] | 34 | |
---|
| 35 | const char * sepGet( ostype & ); // get separator string |
---|
| 36 | void sepSet( ostype &, const char * ); // set separator to string (15 character maximum) |
---|
| 37 | const char * sepGetTuple( ostype & ); // get tuple separator string |
---|
| 38 | void sepSetTuple( ostype &, const char * ); // set tuple separator to string (15 character maximum) |
---|
| 39 | |
---|
| 40 | int fail( ostype & ); |
---|
| 41 | int flush( ostype & ); |
---|
| 42 | void open( ostype & os, const char * name, const char * mode ); |
---|
| 43 | void close( ostype & os ); |
---|
[7c919446] | 44 | ostype & write( ostype &, const char *, size_t ); |
---|
[09687aa] | 45 | int fmt( ostype &, const char fmt[], ... ); |
---|
[86f384b] | 46 | }; // ostream |
---|
[90c3b1c] | 47 | |
---|
[e1780a2] | 48 | // trait writeable( otype T ) { |
---|
[09687aa] | 49 | // forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T ); |
---|
[e1780a2] | 50 | // }; // writeable |
---|
| 51 | |
---|
| 52 | trait writeable( otype T, dtype ostype | ostream( ostype ) ) { |
---|
[09687aa] | 53 | ostype & ?|?( ostype &, T ); |
---|
[86f384b] | 54 | }; // writeable |
---|
[51b7345] | 55 | |
---|
[4e06c1e] | 56 | // implement writable for intrinsic types |
---|
[51b7345] | 57 | |
---|
[3ce0d440] | 58 | forall( dtype ostype | ostream( ostype ) ) { |
---|
[93c2e0a] | 59 | ostype & ?|?( ostype &, bool ); |
---|
[1e6e08de] | 60 | |
---|
[3ce0d440] | 61 | ostype & ?|?( ostype &, char ); |
---|
| 62 | ostype & ?|?( ostype &, signed char ); |
---|
| 63 | ostype & ?|?( ostype &, unsigned char ); |
---|
[09687aa] | 64 | |
---|
[3ce0d440] | 65 | ostype & ?|?( ostype &, short int ); |
---|
| 66 | ostype & ?|?( ostype &, unsigned short int ); |
---|
| 67 | ostype & ?|?( ostype &, int ); |
---|
| 68 | ostype & ?|?( ostype &, unsigned int ); |
---|
| 69 | ostype & ?|?( ostype &, long int ); |
---|
| 70 | ostype & ?|?( ostype &, long long int ); |
---|
| 71 | ostype & ?|?( ostype &, unsigned long int ); |
---|
| 72 | ostype & ?|?( ostype &, unsigned long long int ); |
---|
[09687aa] | 73 | |
---|
[3ce0d440] | 74 | ostype & ?|?( ostype &, float ); // FIX ME: should not be required |
---|
| 75 | ostype & ?|?( ostype &, double ); |
---|
| 76 | ostype & ?|?( ostype &, long double ); |
---|
[09687aa] | 77 | |
---|
[3ce0d440] | 78 | ostype & ?|?( ostype &, float _Complex ); |
---|
| 79 | ostype & ?|?( ostype &, double _Complex ); |
---|
| 80 | ostype & ?|?( ostype &, long double _Complex ); |
---|
[09687aa] | 81 | |
---|
[3ce0d440] | 82 | ostype & ?|?( ostype &, const char * ); |
---|
| 83 | // ostype & ?|?( ostype &, const char16_t * ); |
---|
[0db817e] | 84 | #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous |
---|
[3ce0d440] | 85 | // ostype & ?|?( ostype &, const char32_t * ); |
---|
[0db817e] | 86 | #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) |
---|
[3ce0d440] | 87 | // ostype & ?|?( ostype &, const wchar_t * ); |
---|
| 88 | ostype & ?|?( ostype &, const void * ); |
---|
| 89 | |
---|
| 90 | // manipulators |
---|
| 91 | ostype & ?|?( ostype &, ostype & (*)( ostype & ) ); |
---|
| 92 | ostype & endl( ostype & ); |
---|
| 93 | ostype & sep( ostype & ); |
---|
| 94 | ostype & sepTuple( ostype & ); |
---|
| 95 | ostype & sepOn( ostype & ); |
---|
| 96 | ostype & sepOff( ostype & ); |
---|
| 97 | ostype & sepDisable( ostype & ); |
---|
| 98 | ostype & sepEnable( ostype & ); |
---|
| 99 | } // distribution |
---|
[cf16f94] | 100 | |
---|
[c443d1d] | 101 | // tuples |
---|
[09687aa] | 102 | forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) |
---|
| 103 | ostype & ?|?( ostype & os, T arg, Params rest ); |
---|
[c443d1d] | 104 | |
---|
[e56cfdb0] | 105 | // writes the range [begin, end) to the given stream |
---|
[e1780a2] | 106 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) |
---|
[09687aa] | 107 | void write( iterator_type begin, iterator_type end, ostype & os ); |
---|
[e56cfdb0] | 108 | |
---|
[e1780a2] | 109 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) |
---|
[09687aa] | 110 | void write_reverse( iterator_type begin, iterator_type end, ostype & os ); |
---|
[51b7345] | 111 | |
---|
[6ba0659] | 112 | //--------------------------------------- |
---|
[51b7345] | 113 | |
---|
[4040425] | 114 | trait istream( dtype istype ) { |
---|
[09687aa] | 115 | int fail( istype & ); |
---|
| 116 | int eof( istype & ); |
---|
| 117 | void open( istype & is, const char * name ); |
---|
| 118 | void close( istype & is ); |
---|
[9428d52] | 119 | istype & read( istype &, char *, size_t ); |
---|
[09687aa] | 120 | istype & ungetc( istype &, char ); |
---|
| 121 | int fmt( istype &, const char fmt[], ... ); |
---|
[86f384b] | 122 | }; // istream |
---|
[51b7345] | 123 | |
---|
[4040425] | 124 | trait readable( otype T ) { |
---|
[09687aa] | 125 | forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T ); |
---|
[86f384b] | 126 | }; // readable |
---|
[51b7345] | 127 | |
---|
[3ce0d440] | 128 | forall( dtype istype | istream( istype ) ) { |
---|
[93c2e0a] | 129 | istype & ?|?( istype &, bool & ); |
---|
[3ce0d440] | 130 | |
---|
| 131 | istype & ?|?( istype &, char & ); |
---|
| 132 | istype & ?|?( istype &, signed char & ); |
---|
| 133 | istype & ?|?( istype &, unsigned char & ); |
---|
| 134 | |
---|
| 135 | istype & ?|?( istype &, short int & ); |
---|
| 136 | istype & ?|?( istype &, unsigned short int & ); |
---|
| 137 | istype & ?|?( istype &, int & ); |
---|
| 138 | istype & ?|?( istype &, unsigned int & ); |
---|
| 139 | istype & ?|?( istype &, long int & ); |
---|
| 140 | istype & ?|?( istype &, long long int & ); |
---|
| 141 | istype & ?|?( istype &, unsigned long int & ); |
---|
| 142 | istype & ?|?( istype &, unsigned long long int & ); |
---|
| 143 | |
---|
| 144 | istype & ?|?( istype &, float & ); |
---|
| 145 | istype & ?|?( istype &, double & ); |
---|
| 146 | istype & ?|?( istype &, long double & ); |
---|
| 147 | |
---|
| 148 | istype & ?|?( istype &, float _Complex & ); |
---|
| 149 | istype & ?|?( istype &, double _Complex & ); |
---|
| 150 | istype & ?|?( istype &, long double _Complex & ); |
---|
| 151 | |
---|
| 152 | // manipulators |
---|
| 153 | istype & ?|?( istype &, istype & (*)( istype & ) ); |
---|
| 154 | istype & endl( istype & is ); |
---|
| 155 | } // distribution |
---|
[44574f2] | 156 | |
---|
[53ba273] | 157 | struct _Istream_cstrUC { char * s; }; |
---|
| 158 | _Istream_cstrUC cstr( char * ); |
---|
[09687aa] | 159 | forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC ); |
---|
[51b7345] | 160 | |
---|
[53ba273] | 161 | struct _Istream_cstrC { char * s; int size; }; |
---|
| 162 | _Istream_cstrC cstr( char *, int size ); |
---|
[09687aa] | 163 | forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC ); |
---|
[51b7345] | 164 | |
---|
[10a97adb] | 165 | |
---|
[73abe95] | 166 | #include <time_t.hfa> // Duration (constructors) / Time (constructors) |
---|
[10a97adb] | 167 | |
---|
| 168 | forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur ); |
---|
| 169 | forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time ); |
---|
| 170 | |
---|
| 171 | |
---|
[86bd7c1f] | 172 | // Local Variables: // |
---|
[d3b7937] | 173 | // mode: c // |
---|
[86bd7c1f] | 174 | // tab-width: 4 // |
---|
| 175 | // End: // |
---|