source: libcfa/src/enum.cfa@ c40a982

Last change on this file since c40a982 was 64eeb06, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

change basic_ostream to ostream, first attempt of enumeration input

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[c333ed2]1#include "enum.hfa"
[85855b0]2#include "fstream.hfa"
[c333ed2]3
[03ac869]4#pragma GCC visibility push(default)
5
[64eeb06]6forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) )
7istype & ?|?( istype & is, E & e ) {
8 if ( eof( is ) ) throwResume ExceptionInst( missing_data );
9 char val[256];
10 int args = fmt( is, "%255s", val );
11 if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
12 for ( s; E ) {
13 if ( val == label( s ) ) { e = s; break; }
14 } else {
15 fprintf( stderr, "invalid enumeration constant\n" );
16 abort(); // cannot use abort stream
17 } // for
18 return is;
19}
20
21forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) {
22 ostype & ?|?( ostype & os, E e ) {
[d5efcb7]23 return os | label( e );
24 }
25 OSTYPE_VOID_IMPL( E )
[85855b0]26}
[c333ed2]27
[64eeb06]28forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
29 ostype & ?|?( ostype & os, E e ) {
30 return os | label( e );
31 }
32 OSTYPE_VOID_IMPL( E )
[259012e]33}
[525f7ad]34
[64eeb06]35forall( E, V | CfaEnum( E, V ) ) { // relational operators
36 int ?==?( E l, E r ) { return posn( l ) == posn( r ); }
37 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }
38 int ?<?( E l, E r ) { return posn( l ) < posn( r ); }
39 int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); }
40 int ?>?( E l, E r ) { return posn( l ) > posn( r ); }
41 int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); }
[73d0e3f4]42
[64eeb06]43 E ++?( E & l ) {
44 l = succ( l );
[73d0e3f4]45 return l;
46 }
47
[64eeb06]48 E ?++( E & l ) {
[73d0e3f4]49 E ret = l;
[64eeb06]50 l = succ( l );
[73d0e3f4]51 return ret;
52 }
53
[64eeb06]54 E --?( E & l ) {
55 l = pred( l );
[73d0e3f4]56 return l;
57 }
58
[64eeb06]59 E ?--( E & l ) {
[73d0e3f4]60 E ret = l;
[64eeb06]61 l = pred( l );
[73d0e3f4]62 return ret;
63 }
[525f7ad]64}
Note: See TracBrowser for help on using the repository browser.