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 | //
|
---|
7 | // iostream --
|
---|
8 | //
|
---|
9 | // Author : Peter A. Buhr
|
---|
10 | // Created On : Wed May 27 17:56:53 2015
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Wed Sep 13 12:53:46 2017
|
---|
13 | // Update Count : 138
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include "iterator"
|
---|
19 |
|
---|
20 | trait ostream( dtype ostype ) {
|
---|
21 | // private
|
---|
22 | _Bool sepPrt( ostype * ); // return separator state (on/off)
|
---|
23 | void sepReset( ostype * ); // set separator state to default state
|
---|
24 | void sepReset( ostype *, _Bool ); // set separator and default state
|
---|
25 | const char * sepGetCur( ostype * ); // get current separator string
|
---|
26 | void sepSetCur( ostype *, const char * ); // set current separator string
|
---|
27 | _Bool getNL( ostype * ); // check newline
|
---|
28 | void setNL( ostype *, _Bool ); // saw newline
|
---|
29 | // public
|
---|
30 | void sepOn( ostype * ); // turn separator state on
|
---|
31 | void sepOff( ostype * ); // turn separator state off
|
---|
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
|
---|
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 );
|
---|
44 | ostype * write( ostype *, const char *, unsigned long int );
|
---|
45 | int fmt( ostype *, const char fmt[], ... );
|
---|
46 | }; // ostream
|
---|
47 |
|
---|
48 | // trait writeable( otype T ) {
|
---|
49 | // forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
|
---|
50 | // }; // writeable
|
---|
51 |
|
---|
52 | trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
|
---|
53 | ostype * ?|?( ostype *, T );
|
---|
54 | }; // writeable
|
---|
55 |
|
---|
56 | // implement writable for intrinsic types
|
---|
57 |
|
---|
58 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char );
|
---|
59 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, signed char );
|
---|
60 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned char );
|
---|
61 |
|
---|
62 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, short int );
|
---|
63 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned short int );
|
---|
64 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int );
|
---|
65 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned int );
|
---|
66 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long int );
|
---|
67 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long long int );
|
---|
68 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long int );
|
---|
69 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, unsigned long long int );
|
---|
70 |
|
---|
71 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float ); // FIX ME: should not be required
|
---|
72 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double );
|
---|
73 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double );
|
---|
74 |
|
---|
75 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, float _Complex );
|
---|
76 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double _Complex );
|
---|
77 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, long double _Complex );
|
---|
78 |
|
---|
79 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * );
|
---|
80 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char16_t * );
|
---|
81 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char32_t * );
|
---|
82 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const wchar_t * );
|
---|
83 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * );
|
---|
84 |
|
---|
85 | // tuples
|
---|
86 | forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } )
|
---|
87 | ostype * ?|?( ostype * os, T arg, Params rest );
|
---|
88 |
|
---|
89 | // manipulators
|
---|
90 | forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) );
|
---|
91 | forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
|
---|
92 | forall( dtype ostype | ostream( ostype ) ) ostype * sep( ostype * );
|
---|
93 | forall( dtype ostype | ostream( ostype ) ) ostype * sepTuple( ostype * );
|
---|
94 | forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * );
|
---|
95 | forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * );
|
---|
96 | forall( dtype ostype | ostream( ostype ) ) ostype * sepDisable( ostype * );
|
---|
97 | forall( dtype ostype | ostream( ostype ) ) ostype * sepEnable( ostype * );
|
---|
98 |
|
---|
99 | // writes the range [begin, end) to the given stream
|
---|
100 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
|
---|
101 | void write( iterator_type begin, iterator_type end, ostype * os );
|
---|
102 |
|
---|
103 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
|
---|
104 | void write_reverse( iterator_type begin, iterator_type end, ostype * os );
|
---|
105 |
|
---|
106 | //---------------------------------------
|
---|
107 |
|
---|
108 | trait istream( dtype istype ) {
|
---|
109 | int fail( istype * );
|
---|
110 | int eof( istype * );
|
---|
111 | void open( istype * is, const char * name, const char * mode );
|
---|
112 | void close( istype * is );
|
---|
113 | istype * read( istype *, char *, unsigned long int );
|
---|
114 | istype * ungetc( istype *, char );
|
---|
115 | int fmt( istype *, const char fmt[], ... );
|
---|
116 | }; // istream
|
---|
117 |
|
---|
118 | trait readable( otype T ) {
|
---|
119 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
|
---|
120 | }; // readable
|
---|
121 |
|
---|
122 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char & );
|
---|
123 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, signed char & );
|
---|
124 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned char & );
|
---|
125 |
|
---|
126 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, short int & );
|
---|
127 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned short int & );
|
---|
128 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, int & );
|
---|
129 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned int & );
|
---|
130 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long int & );
|
---|
131 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long long int & );
|
---|
132 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long int & );
|
---|
133 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, unsigned long long int & );
|
---|
134 |
|
---|
135 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float & );
|
---|
136 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double & );
|
---|
137 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double & );
|
---|
138 |
|
---|
139 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, float _Complex & );
|
---|
140 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, double _Complex & );
|
---|
141 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex & );
|
---|
142 |
|
---|
143 | struct _Istream_cstrUC { char * s; };
|
---|
144 | _Istream_cstrUC cstr( char * );
|
---|
145 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrUC );
|
---|
146 |
|
---|
147 | struct _Istream_cstrC { char * s; int size; };
|
---|
148 | _Istream_cstrC cstr( char *, int size );
|
---|
149 | forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC );
|
---|
150 |
|
---|
151 | // Local Variables: //
|
---|
152 | // mode: c //
|
---|
153 | // tab-width: 4 //
|
---|
154 | // End: //
|
---|