source: libcfa/src/iostream.hfa @ 5ea5b28

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

update iostream

  • Property mode set to 100644
File size: 7.3 KB
RevLine 
[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
[5ea5b28]12// Last Modified On : Sat Dec 22 17:00:39 2018
13// Update Count     : 218
[86bd7c1f]14//
15
[53a6c2a]16#pragma once
[51b7345]17
[58b6d1b]18#include "iterator.hfa"
[e56cfdb0]19
[4040425]20trait 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
[200fcb3]27        bool getNL( ostype & );                                                         // check newline
[93c2e0a]28        void setNL( ostype &, bool );                                           // saw newline
[200fcb3]29        bool getANL( ostype & );                                                        // check auto newline
[5ea5b28]30        bool getPrt( ostype & );                                                        // check ignore auto NL
31        void setPrt( ostype &, bool );                                          // set ignore auto NL
[9ebd778]32        // public
[09687aa]33        void sepOn( ostype & );                                                         // turn separator state on
34        void sepOff( ostype & );                                                        // turn separator state off
[93c2e0a]35        bool sepDisable( ostype & );                                            // set default state to off, and return previous state
[200fcb3]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
[09687aa]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 );
[7c919446]49        ostype & write( ostype &, const char *, size_t );
[09687aa]50        int fmt( ostype &, const char fmt[], ... );
[86f384b]51}; // ostream
[90c3b1c]52
[e1780a2]53// trait writeable( otype T ) {
[09687aa]54//      forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, T );
[e1780a2]55// }; // writeable
56
57trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
[09687aa]58        ostype & ?|?( ostype &, T );
[86f384b]59}; // writeable
[51b7345]60
[4e06c1e]61// implement writable for intrinsic types
[51b7345]62
[3ce0d440]63forall( dtype ostype | ostream( ostype ) ) {
[93c2e0a]64        ostype & ?|?( ostype &, bool );
[5ea5b28]65        void ?|?( ostype &, bool );
[1e6e08de]66
[3ce0d440]67        ostype & ?|?( ostype &, char );
[5ea5b28]68        void ?|?( ostype &, char );
[3ce0d440]69        ostype & ?|?( ostype &, signed char );
[5ea5b28]70        void ?|?( ostype &, signed char );
[3ce0d440]71        ostype & ?|?( ostype &, unsigned char );
[5ea5b28]72        void ?|?( ostype &, unsigned char );
[09687aa]73
[3ce0d440]74        ostype & ?|?( ostype &, short int );
[5ea5b28]75        void ?|?( ostype &, short int );
[3ce0d440]76        ostype & ?|?( ostype &, unsigned short int );
[5ea5b28]77        void ?|?( ostype &, unsigned short int );
[3ce0d440]78        ostype & ?|?( ostype &, int );
[5ea5b28]79        void ?|?( ostype &, int );
[3ce0d440]80        ostype & ?|?( ostype &, unsigned int );
[5ea5b28]81        void ?|?( ostype &, unsigned int );
[3ce0d440]82        ostype & ?|?( ostype &, long int );
[5ea5b28]83        void ?|?( ostype &, long int );
[3ce0d440]84        ostype & ?|?( ostype &, long long int );
[5ea5b28]85        void ?|?( ostype &, long long int );
[3ce0d440]86        ostype & ?|?( ostype &, unsigned long int );
[5ea5b28]87        void ?|?( ostype &, unsigned long int );
[3ce0d440]88        ostype & ?|?( ostype &, unsigned long long int );
[5ea5b28]89        void ?|?( ostype &, unsigned long long int );
[09687aa]90
[3ce0d440]91        ostype & ?|?( ostype &, float ); // FIX ME: should not be required
[5ea5b28]92        void ?|?( ostype &, float ); // FIX ME: should not be required
[3ce0d440]93        ostype & ?|?( ostype &, double );
[5ea5b28]94        void ?|?( ostype &, double );
[3ce0d440]95        ostype & ?|?( ostype &, long double );
[5ea5b28]96        void ?|?( ostype &, long double );
[09687aa]97
[3ce0d440]98        ostype & ?|?( ostype &, float _Complex );
[5ea5b28]99        void ?|?( ostype &, float _Complex );
[3ce0d440]100        ostype & ?|?( ostype &, double _Complex );
[5ea5b28]101        void ?|?( ostype &, double _Complex );
[3ce0d440]102        ostype & ?|?( ostype &, long double _Complex );
[5ea5b28]103        void ?|?( ostype &, long double _Complex );
[09687aa]104
[3ce0d440]105        ostype & ?|?( ostype &, const char * );
[5ea5b28]106        void ?|?( ostype &, const char * );
[3ce0d440]107        // ostype & ?|?( ostype &, const char16_t * );
[0db817e]108#if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
[3ce0d440]109        // ostype & ?|?( ostype &, const char32_t * );
[0db817e]110#endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
[3ce0d440]111        // ostype & ?|?( ostype &, const wchar_t * );
112        ostype & ?|?( ostype &, const void * );
[5ea5b28]113        void ?|?( ostype &, const void * );
[3ce0d440]114
115        // manipulators
116        ostype & ?|?( ostype &, ostype & (*)( ostype & ) );
[200fcb3]117        void ?|?( ostype &, ostype & (*)( ostype & ) );
118        ostype & nl( ostype & );
119        ostype & nonl( ostype & );
[3ce0d440]120        ostype & sep( ostype & );
121        ostype & sepTuple( ostype & );
122        ostype & sepOn( ostype & );
123        ostype & sepOff( ostype & );
124        ostype & sepDisable( ostype & );
125        ostype & sepEnable( ostype & );
[200fcb3]126        ostype & nlOn( ostype & );
127        ostype & nlOff( ostype & );
[3ce0d440]128} // distribution
[cf16f94]129
[c443d1d]130// tuples
[200fcb3]131forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
132        ostype & ?|?( ostype & os, T arg, Params rest );
133        void ?|?( ostype & os, T arg, Params rest );
134} // distribution
[c443d1d]135
[e56cfdb0]136// writes the range [begin, end) to the given stream
[200fcb3]137forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
138        void write( iterator_type begin, iterator_type end, ostype & os );
139        void write_reverse( iterator_type begin, iterator_type end, ostype & os );
140} // distribution
[51b7345]141
[6ba0659]142//---------------------------------------
[51b7345]143
[4040425]144trait istream( dtype istype ) {
[09687aa]145        int fail( istype & );
146        int eof( istype & );
147        void open( istype & is, const char * name );
148        void close( istype & is );
[9428d52]149        istype & read( istype &, char *, size_t );
[09687aa]150        istype & ungetc( istype &, char );
151        int fmt( istype &, const char fmt[], ... );
[86f384b]152}; // istream
[51b7345]153
[4040425]154trait readable( otype T ) {
[09687aa]155        forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, T );
[86f384b]156}; // readable
[51b7345]157
[3ce0d440]158forall( dtype istype | istream( istype ) ) {
[93c2e0a]159        istype & ?|?( istype &, bool & );
[3ce0d440]160
161        istype & ?|?( istype &, char & );
162        istype & ?|?( istype &, signed char & );
163        istype & ?|?( istype &, unsigned char & );
164
165        istype & ?|?( istype &, short int & );
166        istype & ?|?( istype &, unsigned short int & );
167        istype & ?|?( istype &, int & );
168        istype & ?|?( istype &, unsigned int & );
169        istype & ?|?( istype &, long int & );
170        istype & ?|?( istype &, long long int & );
171        istype & ?|?( istype &, unsigned long int & );
172        istype & ?|?( istype &, unsigned long long int & );
173
174        istype & ?|?( istype &, float & );
175        istype & ?|?( istype &, double & );
176        istype & ?|?( istype &, long double & );
177
178        istype & ?|?( istype &, float _Complex & );
179        istype & ?|?( istype &, double _Complex & );
180        istype & ?|?( istype &, long double _Complex & );
181
182        // manipulators
183        istype & ?|?( istype &, istype & (*)( istype & ) );
[200fcb3]184        istype & nl( istype & is );
[3ce0d440]185} // distribution
[44574f2]186
[53ba273]187struct _Istream_cstrUC { char * s; };
188_Istream_cstrUC cstr( char * );
[09687aa]189forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC );
[51b7345]190
[53ba273]191struct _Istream_cstrC { char * s; int size; };
192_Istream_cstrC cstr( char *, int size );
[09687aa]193forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC );
[51b7345]194
[10a97ad]195
[200fcb3]196#include <time_t.hfa>                                                                   // Duration (constructors) / Time (constructors)
[10a97ad]197
[200fcb3]198forall( dtype ostype | ostream( ostype ) ) {
199        ostype & ?|?( ostype & os, Duration dur );
200        void ?|?( ostype & os, Duration dur );
201        ostype & ?|?( ostype & os, Time time );
202        void ?|?( ostype & os, Time time );
203} // distribution
[10a97ad]204
[86bd7c1f]205// Local Variables: //
[d3b7937]206// mode: c //
[86bd7c1f]207// tab-width: 4 //
208// End: //
Note: See TracBrowser for help on using the repository browser.