Changes in libcfa/src/iostream.hfa [61c7239:3c5dee4]
- File:
-
- 1 edited
-
libcfa/src/iostream.hfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.hfa
r61c7239 r3c5dee4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // iostream .hfa--7 // iostream -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 8 17:28:44201913 // Update Count : 31212 // Last Modified On : Sat May 11 10:31:27 2019 13 // Update Count : 232 14 14 // 15 15 … … 17 17 18 18 #include "iterator.hfa" 19 20 21 //*********************************** Ostream ***********************************22 23 19 24 20 trait ostream( dtype ostype ) { … … 150 146 } // distribution 151 147 152 //*********************************** Manipulators *********************************** 153 154 forall( otype T ) 155 struct _Ostream_Manip { 156 T val; // polymorphic base-type 157 unsigned char wd, pc; // width, precision 158 char base; // numeric base / floating-point style 159 union { 160 unsigned char all; 161 struct { 162 unsigned char pc:1; // precision specified 163 unsigned char left:1; // left justify 164 unsigned char nobsdp:1; // base prefix / decimal point 165 unsigned char sign:1; // plus / minus sign 166 unsigned char pad0:1; // zero pad 167 } flags; 168 }; 169 }; // _Ostream_Manip 170 171 //*********************************** Integral *********************************** 172 173 // See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular 174 // subobject overriding any previously listed initializer for the same subobject; ***all subobjects that are not 175 // initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.*** 176 177 #define IntegralFMTDecl( T, CODE ) \ 178 static inline { \ 179 _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \ 180 _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'o', { .all : 0 } }; } \ 181 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \ 182 _Ostream_Manip(T) wd( unsigned char w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \ 183 _Ostream_Manip(T) wd( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \ 184 _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 185 _Ostream_Manip(T) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 186 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 187 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \ 188 _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 189 _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \ 190 _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \ 191 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 192 } \ 193 forall( dtype ostype | ostream( ostype ) ) { \ 194 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 195 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ 196 } // ?|? 197 198 IntegralFMTDecl( signed char, 'd' ) 199 IntegralFMTDecl( unsigned char, 'u' ) 200 IntegralFMTDecl( signed short int, 'd' ) 201 IntegralFMTDecl( unsigned short int, 'u' ) 202 IntegralFMTDecl( signed int, 'd' ) 203 IntegralFMTDecl( unsigned int, 'u' ) 204 IntegralFMTDecl( signed long int, 'd' ) 205 IntegralFMTDecl( unsigned long int, 'u' ) 206 IntegralFMTDecl( signed long long int, 'd' ) 207 IntegralFMTDecl( unsigned long long int, 'u' ) 208 209 //*********************************** Floating Point *********************************** 210 211 // Default suffix for values with no fraction is "." 212 #define FloatingPointFMTDecl( T ) \ 213 static inline { \ 214 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \ 215 _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \ 216 _Ostream_Manip(T) wd( unsigned char w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'f', { .all : 0 } }; } \ 217 _Ostream_Manip(T) wd( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \ 218 _Ostream_Manip(T) ws( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \ 219 _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 220 _Ostream_Manip(T) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 221 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 222 _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \ 223 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \ 224 _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \ 225 _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.sign : true } }; } \ 226 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 227 _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \ 228 _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 229 } \ 230 forall( dtype ostype | ostream( ostype ) ) { \ 231 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 232 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ 233 } // ?|? 234 235 FloatingPointFMTDecl( double ) 236 FloatingPointFMTDecl( long double ) 237 238 //*********************************** Character *********************************** 239 240 static inline { 241 _Ostream_Manip(char) bin( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'b', { .all : 0 } }; } 242 _Ostream_Manip(char) oct( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'o', { .all : 0 } }; } 243 _Ostream_Manip(char) hex( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'x', { .all : 0 } }; } 244 _Ostream_Manip(char) wd( unsigned char w, char val ) { return (_Ostream_Manip(char))@{ val, w, 0, 'c', { .all : 0 } }; } 245 _Ostream_Manip(char) & wd( unsigned char w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; } 246 _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; } 247 _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } 248 _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 249 } // distribution 250 forall( dtype ostype | ostream( ostype ) ) { 251 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 252 void ?|?( ostype & os, _Ostream_Manip(char) f ); 253 } // ?|? 254 255 //*********************************** C String *********************************** 256 257 static inline { 258 _Ostream_Manip(const char *) bin( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'b', { .all : 0 } }; } 259 _Ostream_Manip(const char *) oct( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'o', { .all : 0 } }; } 260 _Ostream_Manip(const char *) hex( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'x', { .all : 0 } }; } 261 _Ostream_Manip(const char *) wd( unsigned char w, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, 0, 's', { .all : 0 } }; } 262 _Ostream_Manip(const char *) wd( unsigned char w, unsigned char pc, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, pc, 's', { .flags.pc : true } }; } 263 _Ostream_Manip(const char *) & wd( unsigned char w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; } 264 _Ostream_Manip(const char *) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } 265 _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; } 266 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } 267 } // distribution 268 forall( dtype ostype | ostream( ostype ) ) { 269 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 270 void ?|?( ostype & os, _Ostream_Manip(const char *) f ); 271 } // ?|? 272 273 274 //*********************************** Istream *********************************** 275 148 //--------------------------------------- 276 149 277 150 trait istream( dtype istype ) { … … 316 189 istype & ?|?( istype &, long double _Complex & ); 317 190 318 // Cannot have char & and char * => cstr manipulator319 // istype & ?|?( istype &, char * );320 321 191 // manipulators 322 192 istype & ?|?( istype &, istype & (*)( istype & ) ); … … 326 196 } // distribution 327 197 328 //*********************************** Manipulators *********************************** 329 330 struct _Istream_Cstr { 331 char * s; 332 const char * scanset; 333 int wd; // width 334 union { 335 unsigned char all; 336 struct { 337 unsigned char ignore:1; // do not change input argument 338 unsigned char inex:1; // include/exclude characters in scanset 339 } flags; 340 }; 341 }; // _Istream_Cstr 342 343 static inline _Istream_Cstr skip( const char * scanset ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; } 344 static inline _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; } 345 static inline _Istream_Cstr incl( const char * scanset, _Istream_Cstr & fmt ) { fmt.flags.inex = false; return fmt; } 346 static inline _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; } 347 static inline _Istream_Cstr excl( const char * scanset, _Istream_Cstr & fmt ) { fmt.flags.inex = true; return fmt; } 348 static inline _Istream_Cstr cstr( char * s ) { return (_Istream_Cstr){ s, 0p, -1, { .all : 0 } }; } 349 static inline _Istream_Cstr ignore( const char * s ) { return (_Istream_Cstr)@{ s, 0p, -1, { .flags.ignore : true } }; } 350 static inline _Istream_Cstr ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; } 351 static inline _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; } 352 static inline _Istream_Cstr wd( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; } 353 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_Cstr ); 354 355 forall( otype T ) 356 struct _Istream_Manip { 357 T & val; // polymorphic base-type 358 int wd; // width 359 bool ignore; // do not change input argument 360 }; // _Istream_Manip 361 362 #define InputFMTDecl( T ) \ 363 static inline _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \ 364 static inline _Istream_Manip(T) ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \ 365 static inline _Istream_Manip(T) wd( unsigned int w, T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \ 366 forall( dtype istype | istream( istype ) ) { \ 367 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 368 } // ?|? 369 370 InputFMTDecl( char ) 371 InputFMTDecl( signed char ) 372 InputFMTDecl( unsigned char ) 373 InputFMTDecl( signed short int ) 374 InputFMTDecl( unsigned short int ) 375 InputFMTDecl( signed int ) 376 InputFMTDecl( unsigned int ) 377 InputFMTDecl( signed long int ) 378 InputFMTDecl( unsigned long int ) 379 InputFMTDecl( signed long long int ) 380 InputFMTDecl( unsigned long long int ) 381 382 InputFMTDecl( float ) 383 InputFMTDecl( double ) 384 InputFMTDecl( long double ) 385 386 InputFMTDecl( float _Complex ) 387 InputFMTDecl( double _Complex ) 388 InputFMTDecl( long double _Complex ) 389 390 391 //*********************************** Time *********************************** 198 struct _Istream_cstrUC { char * s; }; 199 _Istream_cstrUC cstr( char * ); 200 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC ); 201 202 struct _Istream_cstrC { char * s; int size; }; 203 _Istream_cstrC cstr( char *, int size ); 204 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC ); 392 205 393 206
Note:
See TracChangeset
for help on using the changeset viewer.