source: libcfa/src/iostream.hfa@ 8a1d62b6

stuck-waitfor-destruct
Last change on this file since 8a1d62b6 was c635047, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

more convertion to new void-creation stream macros

  • Property mode set to 100644
File size: 20.9 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//
[3c573e9]7// iostream.hfa --
[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
[c635047]12// Last Modified On : Tue Jul 18 15:57:21 2023
13// Update Count : 462
[86bd7c1f]14//
15
[53a6c2a]16#pragma once
[51b73452]17
[58b6d1b]18#include "iterator.hfa"
[e56cfdb0]19
[3c573e9]20
[8d321f9]21// *********************************** ostream ***********************************
[3c573e9]22
23
[8a97248]24forall( ostype & )
25trait basic_ostream {
[9ebd778]26 // private
[6c5d92f]27 bool sepPrt$( ostype & ); // get separator state (on/off)
28 void sepReset$( ostype & ); // set separator state to default state
29 void sepReset$( ostype &, bool ); // set separator and default state
30 const char * sepGetCur$( ostype & ); // get current separator string
31 void sepSetCur$( ostype &, const char [] ); // set current separator string
32 bool getNL$( ostype & ); // check newline
33 void setNL$( ostype &, bool ); // saw newline
34 bool getANL$( ostype & ); // get auto newline (on/off)
35 bool getPrt$( ostype & ); // get fmt called in output cascade
36 void setPrt$( ostype &, bool ); // set fmt called in output cascade
[9ebd778]37 // public
[200fcb3]38 void nlOn( ostype & ); // turn auto-newline state on
39 void nlOff( ostype & ); // turn auto-newline state off
[09687aa]40
[f5d9c37]41 void sep( ostype & ); // turn separator state on
42 void nosep( ostype & ); // turn separator state off
43 bool sepOn( ostype & ); // set default state to on, and return previous state
44 bool sepOff( ostype & ); // set default state to off, and return previous state
[09687aa]45 const char * sepGet( ostype & ); // get separator string
[e3fea42]46 void sepSet( ostype &, const char [] ); // set separator to string (15 character maximum)
[09687aa]47 const char * sepGetTuple( ostype & ); // get tuple separator string
[e3fea42]48 void sepSetTuple( ostype &, const char [] ); // set tuple separator to string (15 character maximum)
[09687aa]49
[85d8153]50 void ends( ostype & ); // end of output statement
51 int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
52}; // basic_ostream
[a0bd9a2]53
[8a97248]54forall( ostype & | basic_ostream( ostype ) )
55trait ostream {
[85d8153]56 bool fail( ostype & ); // operation failed?
[00e9be9]57 void clear( ostype & );
58 int flush( ostype & );
[85d8153]59 void open( ostype &, const char name[], const char mode[] );
60 void close( ostype & );
[e3fea42]61 ostype & write( ostype &, const char [], size_t );
[86f384b]62}; // ostream
[90c3b1c]63
[8a97248]64// forall( T )
65// trait writeable {
[fd54fef]66// forall( ostype & | ostream( ostype ) ) ostype & ?|?( ostype &, T );
[e1780a2]67// }; // writeable
68
[8a97248]69forall( T, ostype & | ostream( ostype ) )
[dc9dd94]70trait writeable {
[09687aa]71 ostype & ?|?( ostype &, T );
[86f384b]72}; // writeable
[51b73452]73
[4e06c1e]74// implement writable for intrinsic types
[51b73452]75
[94d2544]76#define OSTYPE_VOID( T ) void ?|?( ostype &, T )
77#define OSTYPE_VOID_IMPL( T ) \
78 void ?|?( ostype & os, T t ) { \
79 (ostype &)(os | t); ends( os ); \
80 } // ?|?
81
[85d8153]82forall( ostype & | basic_ostream( ostype ) ) {
[93c2e0a]83 ostype & ?|?( ostype &, bool );
[94d2544]84 OSTYPE_VOID( bool );
[1e6e08de]85
[3ce0d440]86 ostype & ?|?( ostype &, char );
[94d2544]87 OSTYPE_VOID( char );
[3ce0d440]88 ostype & ?|?( ostype &, signed char );
[94d2544]89 OSTYPE_VOID( signed char );
[3ce0d440]90 ostype & ?|?( ostype &, unsigned char );
[94d2544]91 OSTYPE_VOID( unsigned char );
[09687aa]92
[3ce0d440]93 ostype & ?|?( ostype &, short int );
[94d2544]94 OSTYPE_VOID( short int );
[3ce0d440]95 ostype & ?|?( ostype &, unsigned short int );
[94d2544]96 OSTYPE_VOID( unsigned short int );
[3ce0d440]97 ostype & ?|?( ostype &, int );
[94d2544]98 OSTYPE_VOID( int );
[3ce0d440]99 ostype & ?|?( ostype &, unsigned int );
[94d2544]100 OSTYPE_VOID( unsigned int );
[3ce0d440]101 ostype & ?|?( ostype &, long int );
[94d2544]102 OSTYPE_VOID( long int );
[3ce0d440]103 ostype & ?|?( ostype &, long long int );
[94d2544]104 OSTYPE_VOID( long long int );
[3ce0d440]105 ostype & ?|?( ostype &, unsigned long int );
[94d2544]106 OSTYPE_VOID( unsigned long int );
[3ce0d440]107 ostype & ?|?( ostype &, unsigned long long int );
[94d2544]108 OSTYPE_VOID( unsigned long long int );
[ef3ac46]109 #if defined( __SIZEOF_INT128__ )
[bd5b443]110 ostype & ?|?( ostype &, int128 );
[94d2544]111 OSTYPE_VOID( int128 );
[bd5b443]112 ostype & ?|?( ostype &, unsigned int128 );
[94d2544]113 OSTYPE_VOID( unsigned int128 );
[ef3ac46]114 #endif // __SIZEOF_INT128__
[09687aa]115
[65240bb]116 ostype & ?|?( ostype &, float );
[94d2544]117 OSTYPE_VOID( float );
[3ce0d440]118 ostype & ?|?( ostype &, double );
[94d2544]119 OSTYPE_VOID( double );
[3ce0d440]120 ostype & ?|?( ostype &, long double );
[94d2544]121 OSTYPE_VOID( long double );
[09687aa]122
[3ce0d440]123 ostype & ?|?( ostype &, float _Complex );
[94d2544]124 OSTYPE_VOID( float _Complex );
[3ce0d440]125 ostype & ?|?( ostype &, double _Complex );
[94d2544]126 OSTYPE_VOID( double _Complex );
[3ce0d440]127 ostype & ?|?( ostype &, long double _Complex );
[94d2544]128 OSTYPE_VOID( long double _Complex );
[09687aa]129
[e3fea42]130 ostype & ?|?( ostype &, const char [] );
[94d2544]131 OSTYPE_VOID( const char [] );
[3ce0d440]132 // ostype & ?|?( ostype &, const char16_t * );
[ef3ac46]133 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
[3ce0d440]134 // ostype & ?|?( ostype &, const char32_t * );
[ef3ac46]135 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
[3ce0d440]136 // ostype & ?|?( ostype &, const wchar_t * );
137 ostype & ?|?( ostype &, const void * );
[94d2544]138 OSTYPE_VOID( const void * );
[3ce0d440]139
[c635047]140 // forall( T | { ostype & ?|?( ostype &, T ); } )
141 // void ?|?( ostype & os, T );
142
[3ce0d440]143 // manipulators
144 ostype & ?|?( ostype &, ostype & (*)( ostype & ) );
[94d2544]145 OSTYPE_VOID( ostype & (*)( ostype & ) );
[f5d9c37]146
[200fcb3]147 ostype & nl( ostype & );
148 ostype & nonl( ostype & );
[f5d9c37]149 ostype & nlOn( ostype & );
150 ostype & nlOff( ostype & );
151
152 ostype & sepVal( ostype & );
153 ostype & sepTupleVal( ostype & );
[3ce0d440]154 ostype & sep( ostype & );
[f5d9c37]155 ostype & nosep( ostype & );
[3ce0d440]156 ostype & sepOn( ostype & );
157 ostype & sepOff( ostype & );
[85d8153]158} // distribution
159
[c443d1d]160// tuples
[fd54fef]161forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
[200fcb3]162 ostype & ?|?( ostype & os, T arg, Params rest );
163 void ?|?( ostype & os, T arg, Params rest );
164} // distribution
[c443d1d]165
[e56cfdb0]166// writes the range [begin, end) to the given stream
[fd54fef]167forall( ostype &, elt_type | writeable( elt_type, ostype ), iterator_type | iterator( iterator_type, elt_type ) ) {
[200fcb3]168 void write( iterator_type begin, iterator_type end, ostype & os );
169 void write_reverse( iterator_type begin, iterator_type end, ostype & os );
170} // distribution
[51b73452]171
[8d321f9]172// *********************************** manipulators ***********************************
[3c573e9]173
[a0bd9a2]174struct _Ostream_Flags {
[dc9dd94]175 unsigned char eng:1; // engineering notation
176 unsigned char neg:1; // val is negative
177 unsigned char pc:1; // precision specified
178 unsigned char left:1; // left justify
179 unsigned char nobsdp:1; // base prefix / decimal point
180 unsigned char sign:1; // plus / minus sign
181 unsigned char pad0:1; // zero pad
[a0bd9a2]182};
183
[fd54fef]184forall( T )
[3c573e9]185struct _Ostream_Manip {
186 T val; // polymorphic base-type
[424dfc4]187 int wd, pc; // width, precision: signed for computations
[3c573e9]188 char base; // numeric base / floating-point style
189 union {
190 unsigned char all;
[a0bd9a2]191 _Ostream_Flags flags;
[3c573e9]192 };
193}; // _Ostream_Manip
194
[8d321f9]195// *********************************** integral ***********************************
[3c573e9]196
[61c7239]197// See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular
198// subobject overriding any previously listed initializer for the same subobject; ***all subobjects that are not
199// initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.***
200
[94d2544]201#define INTEGRAL_FMT_DECL( T, CODE ) \
[3c573e9]202static inline { \
[61c7239]203 _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \
204 _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'o', { .all : 0 } }; } \
205 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \
[891b827]206 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \
[424dfc4]207 _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \
[891b827]208 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
[424dfc4]209 _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
[3c573e9]210 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
211 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \
212 _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
213 _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
[61c7239]214 _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \
[3c573e9]215 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
[04396aa]216} /* distribution */ \
[85d8153]217forall( ostype & | basic_ostream( ostype ) ) { \
[3c573e9]218 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
[c635047]219 OSTYPE_VOID( _Ostream_Manip(T) ); \
[61c7239]220} // ?|?
[3c573e9]221
[94d2544]222INTEGRAL_FMT_DECL( signed char, 'd' )
223INTEGRAL_FMT_DECL( unsigned char, 'u' )
224INTEGRAL_FMT_DECL( signed short int, 'd' )
225INTEGRAL_FMT_DECL( unsigned short int, 'u' )
226INTEGRAL_FMT_DECL( signed int, 'd' )
227INTEGRAL_FMT_DECL( unsigned int, 'u' )
228INTEGRAL_FMT_DECL( signed long int, 'd' )
229INTEGRAL_FMT_DECL( unsigned long int, 'u' )
230INTEGRAL_FMT_DECL( signed long long int, 'd' )
231INTEGRAL_FMT_DECL( unsigned long long int, 'u' )
[bd5b443]232#if defined( __SIZEOF_INT128__ )
[94d2544]233INTEGRAL_FMT_DECL( int128, 'd' )
234INTEGRAL_FMT_DECL( unsigned int128, 'u' )
[2b22b5c4]235#endif // __SIZEOF_INT128__
[3c573e9]236
[8d321f9]237// *********************************** floating point ***********************************
[3c573e9]238
239// Default suffix for values with no fraction is "."
[94d2544]240#define FLOATING_POINT_FMT_DECL( T ) \
[3c573e9]241static inline { \
[61c7239]242 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \
243 _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \
[fd4c009]244 _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.eng : true } }; } \
245 _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'g', { .all : 0 } }; } \
[424dfc4]246 _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
247 _Ostream_Manip(T) ws( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
[fd4c009]248 _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; return fmt; } \
[424dfc4]249 _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
250 _Ostream_Manip(T) & ws( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
[3c573e9]251 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
[61c7239]252 _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \
[3c573e9]253 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \
254 _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
[61c7239]255 _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.sign : true } }; } \
[3c573e9]256 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
[61c7239]257 _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
[3c573e9]258 _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
[fd4c009]259 _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
260 _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
[04396aa]261} /* distribution */ \
[85d8153]262forall( ostype & | basic_ostream( ostype ) ) { \
[3c573e9]263 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
[c635047]264 OSTYPE_VOID( _Ostream_Manip(T) ); \
[61c7239]265} // ?|?
[3c573e9]266
[94d2544]267FLOATING_POINT_FMT_DECL( double )
268FLOATING_POINT_FMT_DECL( long double )
[3c573e9]269
[8d321f9]270// *********************************** character ***********************************
[3c573e9]271
272static inline {
[04396aa]273 _Ostream_Manip(char) bin( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'b', { .all : 0 } }; }
274 _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'o', { .all : 0 } }; }
275 _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'x', { .all : 0 } }; }
276 _Ostream_Manip(char) wd( unsigned int w, char c ) { return (_Ostream_Manip(char))@{ c, w, 0, 'c', { .all : 0 } }; }
[891b827]277 _Ostream_Manip(char) & wd( unsigned int w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; }
[3c573e9]278 _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; }
279 _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
280 _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
281} // distribution
[85d8153]282forall( ostype & | basic_ostream( ostype ) ) {
[3c573e9]283 ostype & ?|?( ostype & os, _Ostream_Manip(char) f );
[c635047]284 OSTYPE_VOID( _Ostream_Manip(char) ); \
[61c7239]285} // ?|?
[3c573e9]286
[8d321f9]287// *********************************** C string ***********************************
[3c573e9]288
289static inline {
[e3fea42]290 _Ostream_Manip(const char *) bin( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'b', { .all : 0 } }; }
291 _Ostream_Manip(const char *) oct( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'o', { .all : 0 } }; }
292 _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; }
293 _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; }
[424dfc4]294 _Ostream_Manip(const char *) wd( unsigned int w, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }
[891b827]295 _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
[424dfc4]296 _Ostream_Manip(const char *) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
[3c573e9]297 _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; }
298 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
299} // distribution
[85d8153]300forall( ostype & | basic_ostream( ostype ) ) {
[3c573e9]301 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f );
[c635047]302 OSTYPE_VOID( _Ostream_Manip(const char *) ); \
[61c7239]303} // ?|?
[3c573e9]304
305
[8d321f9]306// *********************************** istream ***********************************
[3c573e9]307
[51b73452]308
[94d2544]309#define ISTYPE_VOID( T ) void ?|?( istype &, T )
310#define ISTYPE_VOID_IMPL( T ) \
[c635047]311 void ?|?( istype & is, T t ) { \
[94d2544]312 (istype &)(is | t); ends( is ); \
313 } // ?|?
314
[8a97248]315forall( istype & )
316trait basic_istream {
[c8371b5]317 // private
318 bool getANL$( istype & ); // get scan newline (on/off)
319 // public
[0efb269]320 void nlOn( istype & ); // read newline
321 void nlOff( istype & ); // scan newline
[e474cf09]322 void ends( istype & os ); // end of output statement
[ef3ac46]323 int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
324 istype & ungetc( istype &, char );
[00e9be9]325 bool eof( istype & );
[ef3ac46]326}; // basic_istream
327
[8a97248]328forall( istype & | basic_istream( istype ) )
329trait istream {
[ef3ac46]330 bool fail( istype & );
[00e9be9]331 void clear( istype & );
[e3fea42]332 void open( istype & is, const char name[] );
[09687aa]333 void close( istype & is );
[00e9be9]334 istype & read( istype &, char [], size_t );
[86f384b]335}; // istream
[51b73452]336
[8a97248]337forall( T )
338trait readable {
[fd54fef]339 forall( istype & | istream( istype ) ) istype & ?|?( istype &, T );
[86f384b]340}; // readable
[51b73452]341
[ef3ac46]342forall( istype & | basic_istream( istype ) ) {
[93c2e0a]343 istype & ?|?( istype &, bool & );
[94d2544]344 ISTYPE_VOID( bool & );
[3ce0d440]345
346 istype & ?|?( istype &, char & );
[94d2544]347 ISTYPE_VOID( char & );
[3ce0d440]348 istype & ?|?( istype &, signed char & );
[94d2544]349 ISTYPE_VOID( signed char & );
[3ce0d440]350 istype & ?|?( istype &, unsigned char & );
[94d2544]351 ISTYPE_VOID( unsigned char & );
[3ce0d440]352
353 istype & ?|?( istype &, short int & );
[94d2544]354 ISTYPE_VOID( short int & );
[3ce0d440]355 istype & ?|?( istype &, unsigned short int & );
[94d2544]356 ISTYPE_VOID( unsigned short int & );
[3ce0d440]357 istype & ?|?( istype &, int & );
[94d2544]358 ISTYPE_VOID( int & );
[3ce0d440]359 istype & ?|?( istype &, unsigned int & );
[94d2544]360 ISTYPE_VOID( unsigned int & );
[3ce0d440]361 istype & ?|?( istype &, long int & );
[94d2544]362 ISTYPE_VOID( long int & );
[3ce0d440]363 istype & ?|?( istype &, unsigned long int & );
[94d2544]364 ISTYPE_VOID( unsigned long int & );
[21baa40]365 istype & ?|?( istype &, long long int & );
[94d2544]366 ISTYPE_VOID( long long int & );
[3ce0d440]367 istype & ?|?( istype &, unsigned long long int & );
[94d2544]368 ISTYPE_VOID( unsigned long long int & );
[ef3ac46]369 #if defined( __SIZEOF_INT128__ )
[21baa40]370 istype & ?|?( istype &, int128 & );
[94d2544]371 ISTYPE_VOID( int128 & );
[21baa40]372 istype & ?|?( istype &, unsigned int128 & );
[94d2544]373 ISTYPE_VOID( unsigned int128 & );
[ef3ac46]374 #endif // __SIZEOF_INT128__
[3ce0d440]375
376 istype & ?|?( istype &, float & );
[94d2544]377 ISTYPE_VOID( float & );
[3ce0d440]378 istype & ?|?( istype &, double & );
[94d2544]379 ISTYPE_VOID( double & );
[3ce0d440]380 istype & ?|?( istype &, long double & );
[94d2544]381 ISTYPE_VOID( long double & );
[3ce0d440]382
383 istype & ?|?( istype &, float _Complex & );
[94d2544]384 ISTYPE_VOID( float _Complex & );
[3ce0d440]385 istype & ?|?( istype &, double _Complex & );
[94d2544]386 ISTYPE_VOID( double _Complex & );
[3ce0d440]387 istype & ?|?( istype &, long double _Complex & );
[94d2544]388 ISTYPE_VOID( long double _Complex & );
[3ce0d440]389
[e3fea42]390// istype & ?|?( istype &, const char [] );
[e474cf09]391 istype & ?|?( istype &, char [] );
[c635047]392 ISTYPE_VOID( char * );
[61c7239]393
[3ce0d440]394 // manipulators
395 istype & ?|?( istype &, istype & (*)( istype & ) );
[94d2544]396 ISTYPE_VOID( istype & (*)( istype & ) );
[200fcb3]397 istype & nl( istype & is );
[3c5dee4]398 istype & nlOn( istype & );
399 istype & nlOff( istype & );
[ef3ac46]400} // distribution
401
[8d321f9]402// *********************************** manipulators ***********************************
[51b73452]403
[3c573e9]404struct _Istream_Cstr {
[61c7239]405 char * s;
406 const char * scanset;
[3c573e9]407 int wd; // width
[61c7239]408 union {
409 unsigned char all;
410 struct {
411 unsigned char ignore:1; // do not change input argument
412 unsigned char inex:1; // include/exclude characters in scanset
413 } flags;
414 };
415}; // _Istream_Cstr
416
[04396aa]417static inline {
[e3fea42]418 _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
[424dfc4]419 _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; }
[e3fea42]420 _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; }
421 _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
422 _Istream_Cstr excl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; }
423 _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
[b81fd95]424 _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, 0p, -1, { .flags.ignore : true } }; }
[04396aa]425 _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; }
[e3fea42]426 _Istream_Cstr wdi( unsigned int w, char s[] ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; }
[dc5072f]427 _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
[04396aa]428} // distribution
[ef3ac46]429forall( istype & | basic_istream( istype ) ) {
[e474cf09]430 istype & ?|?( istype & is, _Istream_Cstr f );
[c635047]431 ISTYPE_VOID( _Istream_Cstr );
[e474cf09]432}
[86a8be5]433
434struct _Istream_Char {
435 bool ignore; // do not change input argument
436}; // _Istream_Char
437
[04396aa]438static inline {
[2c60c644]439 _Istream_Char ignore( const char ) { return (_Istream_Char)@{ true }; }
[04396aa]440 _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
441} // distribution
[ef3ac46]442forall( istype & | basic_istream( istype ) ) {
[e474cf09]443 istype & ?|?( istype & is, _Istream_Char f );
[c635047]444 ISTYPE_VOID( _Istream_Char );
[e474cf09]445}
[3c573e9]446
[fd54fef]447forall( T & | sized( T ) )
[3c573e9]448struct _Istream_Manip {
449 T & val; // polymorphic base-type
450 int wd; // width
[61c7239]451 bool ignore; // do not change input argument
[3c573e9]452}; // _Istream_Manip
453
[94d2544]454#define INPUT_FMT_DECL( T ) \
[04396aa]455static inline { \
456 _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \
457 _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
458 _Istream_Manip(T) wdi( unsigned int w, T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \
[dc5072f]459 _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
[04396aa]460} /* distribution */ \
[ef3ac46]461forall( istype & | basic_istream( istype ) ) { \
[3c573e9]462 istype & ?|?( istype & is, _Istream_Manip(T) f ); \
[c635047]463 ISTYPE_VOID( _Istream_Manip(T) ); \
[61c7239]464} // ?|?
[3c573e9]465
[94d2544]466INPUT_FMT_DECL( signed char )
467INPUT_FMT_DECL( unsigned char )
468INPUT_FMT_DECL( signed short int )
469INPUT_FMT_DECL( unsigned short int )
470INPUT_FMT_DECL( signed int )
471INPUT_FMT_DECL( unsigned int )
472INPUT_FMT_DECL( signed long int )
473INPUT_FMT_DECL( unsigned long int )
474INPUT_FMT_DECL( signed long long int )
475INPUT_FMT_DECL( unsigned long long int )
476
477INPUT_FMT_DECL( float )
478INPUT_FMT_DECL( double )
479INPUT_FMT_DECL( long double )
480
481INPUT_FMT_DECL( float _Complex )
482INPUT_FMT_DECL( double _Complex )
483INPUT_FMT_DECL( long double _Complex )
[3c573e9]484
485
[8d321f9]486// *********************************** time ***********************************
[3c573e9]487
[10a97adb]488
[200fcb3]489#include <time_t.hfa> // Duration (constructors) / Time (constructors)
[10a97adb]490
[fd54fef]491forall( ostype & | ostream( ostype ) ) {
[200fcb3]492 ostype & ?|?( ostype & os, Duration dur );
[c635047]493 OSTYPE_VOID( Duration );
[200fcb3]494 ostype & ?|?( ostype & os, Time time );
[c635047]495 OSTYPE_VOID( Time );
[200fcb3]496} // distribution
[10a97adb]497
[86bd7c1f]498// Local Variables: //
499// tab-width: 4 //
500// End: //
Note: See TracBrowser for help on using the repository browser.