source: libcfa/src/enum.cfa @ 64eeb06

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

change basic_ostream to ostream, first attempt of enumeration input

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include "enum.hfa"
2#include "fstream.hfa"
3
4#pragma GCC visibility push(default)
5
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 ) {
23                return os | label( e );
24        }
25        OSTYPE_VOID_IMPL( E )
26}
27
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 )
33}
34
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 ); }
42
43    E ++?( E & l ) {
44        l = succ( l );
45        return l;
46    }
47   
48    E ?++( E & l ) {
49        E ret = l;
50        l = succ( l );
51        return ret;
52    }
53
54    E --?( E & l ) {
55        l = pred( l );
56        return l;
57    }
58
59    E ?--( E & l ) {
60        E ret = l;
61        l = pred( l );
62        return ret;
63    }
64}
Note: See TracBrowser for help on using the repository browser.