source: libcfa/src/enum.hfa @ b9f6791

Last change on this file since b9f6791 was d287f3e, checked in by Peter A. Buhr <pabuhr@…>, 11 days ago

fix selecting wrong input operator for enumeration, first attempt at reading enumerators

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[72713e5]1#pragma once
2
[85855b0]3#include "iostream.hfa"
4
[d5efcb7]5forall( E ) trait Bounded {
[85855b0]6    E lowerBound();
7    E upperBound();
8};
9
[64eeb06]10forall( E | Bounded( E ) ) trait Serial {
[d5efcb7]11    unsigned fromInstance( E e );
12    E fromInt( unsigned i );
13    E succ( E e );
14    E pred( E e );
[85855b0]15};
16
17// Design one
[64eeb06]18forall( E, V | Serial( E ) ) trait CfaEnum {
[d287f3e]19    const char * label( E e );
[d5efcb7]20    unsigned int posn( E e );
21    V value( E e );
[85855b0]22};
23
[d5efcb7]24// I/O
[85855b0]25
[64eeb06]26forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) )
[bc48c0d]27istype & ?|?( istype &, E & );
[64eeb06]28
29forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) {
[d5efcb7]30        ostype & ?|?( ostype &, E );
31        OSTYPE_VOID( E );
32}
33
[64eeb06]34forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
35        ostype & ?|?( ostype &, E );
36        OSTYPE_VOID( E );
37}
[85855b0]38
39// Design two <- should go for this if we have change the cost model
[64eeb06]40// forall( E | Serial( E ) ) trait CfaEnum {
41//     char * label( E e );
42//     unsigned int posn( E e );
[85855b0]43// };
44
[64eeb06]45// forall( E, V| CfaEnum( E)) trait TypedEnum {
46//     V value( E e);
[85855b0]47// };
[525f7ad]48
[062467b]49static inline
50forall( E, V | CfaEnum( E, V ) ) {
51    int ?==?( E l, E r ) { return posn( l ) == posn( r ); }     // relational operators
52    int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }
53    int ?<?( E l, E r ) { return posn( l ) < posn( r ); }
54    int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); }
55    int ?>?( E l, E r ) { return posn( l ) > posn( r ); }
56    int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); }
57
58    E ++?( E & l ) {                                                                    // increment operators
59        l = succ( l );
60        return l;
61    }
62   
63    E ?++( E & l ) {
64        E ret = l;
65        l = succ( l );
66        return ret;
67    }
68
69    E --?( E & l ) {
70        l = pred( l );
71        return l;
72    }
73
74    E ?--( E & l ) {
75        E ret = l;
76        l = pred( l );
77        return ret;
78    }
[64eeb06]79}
Note: See TracBrowser for help on using the repository browser.