source: libcfa/src/iostream.hfa @ 0050a5f

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 0050a5f was 9d362a0, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

simplify code

  • Property mode set to 100644
File size: 7.4 KB
Line 
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 : Mon Dec 24 18:33:40 2018
13// Update Count     : 220
14//
15
16#pragma once
17
18#include "iterator.hfa"
19
20trait ostream( dtype ostype ) {
21        // private
22        bool sepPrt( ostype & );                                                        // get 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        bool getANL( ostype & );                                                        // get auto newline (on/off)
30        bool getPrt( ostype & );                                                        // get fmt called in output cascade
31        void setPrt( ostype &, bool );                                          // set fmt called in output cascade
32        // public
33        void sepOn( ostype & );                                                         // turn separator state on
34        void sepOff( ostype & );                                                        // turn separator state off
35        bool sepDisable( ostype & );                                            // set default state to off, and return previous state
36        bool sepEnable( ostype & );                                                     // set default state to on, and return previous state
37        void nlOn( ostype & );                                                          // turn auto-newline state on
38        void nlOff( ostype & );                                                         // turn auto-newline state off
39
40        const char * sepGet( ostype & );                                        // get separator string
41        void sepSet( ostype &, const char * );                          // set separator to string (15 character maximum)
42        const char * sepGetTuple( ostype & );                           // get tuple separator string
43        void sepSetTuple( ostype &, const char * );                     // set tuple separator to string (15 character maximum)
44
45        int fail( ostype & );
46        int flush( ostype & );
47        void open( ostype & os, const char * name, const char * mode );
48        void close( ostype & os );
49        ostype & write( ostype &, const char *, size_t );
50        int fmt( ostype &, const char format[], ... );
51}; // ostream
52
53// trait writeable( otype T ) {
54//      forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T );
55// }; // writeable
56
57trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
58        ostype & ?|?( ostype &, T );
59}; // writeable
60
61// implement writable for intrinsic types
62
63forall( dtype ostype | ostream( ostype ) ) {
64        ostype & ?|?( ostype &, bool );
65        void ?|?( ostype &, bool );
66
67        ostype & ?|?( ostype &, char );
68        void ?|?( ostype &, char );
69        ostype & ?|?( ostype &, signed char );
70        void ?|?( ostype &, signed char );
71        ostype & ?|?( ostype &, unsigned char );
72        void ?|?( ostype &, unsigned char );
73
74        ostype & ?|?( ostype &, short int );
75        void ?|?( ostype &, short int );
76        ostype & ?|?( ostype &, unsigned short int );
77        void ?|?( ostype &, unsigned short int );
78        ostype & ?|?( ostype &, int );
79        void ?|?( ostype &, int );
80        ostype & ?|?( ostype &, unsigned int );
81        void ?|?( ostype &, unsigned int );
82        ostype & ?|?( ostype &, long int );
83        void ?|?( ostype &, long int );
84        ostype & ?|?( ostype &, long long int );
85        void ?|?( ostype &, long long int );
86        ostype & ?|?( ostype &, unsigned long int );
87        void ?|?( ostype &, unsigned long int );
88        ostype & ?|?( ostype &, unsigned long long int );
89        void ?|?( ostype &, unsigned long long int );
90
91        ostype & ?|?( ostype &, float ); // FIX ME: should not be required
92        void ?|?( ostype &, float ); // FIX ME: should not be required
93        ostype & ?|?( ostype &, double );
94        void ?|?( ostype &, double );
95        ostype & ?|?( ostype &, long double );
96        void ?|?( ostype &, long double );
97
98        ostype & ?|?( ostype &, float _Complex );
99        void ?|?( ostype &, float _Complex );
100        ostype & ?|?( ostype &, double _Complex );
101        void ?|?( ostype &, double _Complex );
102        ostype & ?|?( ostype &, long double _Complex );
103        void ?|?( ostype &, long double _Complex );
104
105        ostype & ?|?( ostype &, const char * );
106        void ?|?( ostype &, const char * );
107        // ostype & ?|?( ostype &, const char16_t * );
108#if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
109        // ostype & ?|?( ostype &, const char32_t * );
110#endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
111        // ostype & ?|?( ostype &, const wchar_t * );
112        ostype & ?|?( ostype &, const void * );
113        void ?|?( ostype &, const void * );
114
115        // manipulators
116        ostype & ?|?( ostype &, ostype & (*)( ostype & ) );
117        void ?|?( ostype &, ostype & (*)( ostype & ) );
118        ostype & nl( ostype & );
119        void nl( ostype & );
120        ostype & nonl( ostype & );
121        ostype & sep( ostype & );
122        ostype & sepTuple( ostype & );
123        ostype & sepOn( ostype & );
124        ostype & sepOff( ostype & );
125        ostype & sepDisable( ostype & );
126        ostype & sepEnable( ostype & );
127        ostype & nlOn( ostype & );
128        ostype & nlOff( ostype & );
129} // distribution
130
131// tuples
132forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
133        ostype & ?|?( ostype & os, T arg, Params rest );
134        void ?|?( ostype & os, T arg, Params rest );
135} // distribution
136
137// writes the range [begin, end) to the given stream
138forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
139        void write( iterator_type begin, iterator_type end, ostype & os );
140        void write_reverse( iterator_type begin, iterator_type end, ostype & os );
141} // distribution
142
143//---------------------------------------
144
145trait istream( dtype istype ) {
146        int fail( istype & );
147        int eof( istype & );
148        void open( istype & is, const char * name );
149        void close( istype & is );
150        istype & read( istype &, char *, size_t );
151        istype & ungetc( istype &, char );
152        int fmt( istype &, const char format[], ... );
153}; // istream
154
155trait readable( otype T ) {
156        forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T );
157}; // readable
158
159forall( dtype istype | istream( istype ) ) {
160        istype & ?|?( istype &, bool & );
161
162        istype & ?|?( istype &, char & );
163        istype & ?|?( istype &, signed char & );
164        istype & ?|?( istype &, unsigned char & );
165
166        istype & ?|?( istype &, short int & );
167        istype & ?|?( istype &, unsigned short int & );
168        istype & ?|?( istype &, int & );
169        istype & ?|?( istype &, unsigned int & );
170        istype & ?|?( istype &, long int & );
171        istype & ?|?( istype &, long long int & );
172        istype & ?|?( istype &, unsigned long int & );
173        istype & ?|?( istype &, unsigned long long int & );
174
175        istype & ?|?( istype &, float & );
176        istype & ?|?( istype &, double & );
177        istype & ?|?( istype &, long double & );
178
179        istype & ?|?( istype &, float _Complex & );
180        istype & ?|?( istype &, double _Complex & );
181        istype & ?|?( istype &, long double _Complex & );
182
183        // manipulators
184        istype & ?|?( istype &, istype & (*)( istype & ) );
185        istype & nl( istype & is );
186} // distribution
187
188struct _Istream_cstrUC { char * s; };
189_Istream_cstrUC cstr( char * );
190forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC );
191
192struct _Istream_cstrC { char * s; int size; };
193_Istream_cstrC cstr( char *, int size );
194forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC );
195
196
197#include <time_t.hfa>                                                                   // Duration (constructors) / Time (constructors)
198
199forall( dtype ostype | ostream( ostype ) ) {
200        ostype & ?|?( ostype & os, Duration dur );
201        void ?|?( ostype & os, Duration dur );
202        ostype & ?|?( ostype & os, Time time );
203        void ?|?( ostype & os, Time time );
204} // distribution
205
206// Local Variables: //
207// mode: c //
208// tab-width: 4 //
209// End: //
Note: See TracBrowser for help on using the repository browser.