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