#pragma once #include "iostream.hfa" forall( E ) trait Bounded { E lowerBound(); E upperBound(); }; forall( E | Bounded( E ) ) trait Serial { unsigned fromInstance( E e ); E fromInt( unsigned i ); E succ( E e ); E pred( E e ); }; // Design one forall( E, V | Serial( E ) ) trait CfaEnum { char * label( E e ); unsigned int posn( E e ); V value( E e ); }; // I/O forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) ) istype & ?|?( istype &, E & ); forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) { ostype & ?|?( ostype &, E ); OSTYPE_VOID( E ); } forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) { ostype & ?|?( ostype &, E ); OSTYPE_VOID( E ); } // Design two <- should go for this if we have change the cost model // forall( E | Serial( E ) ) trait CfaEnum { // char * label( E e ); // unsigned int posn( E e ); // }; // forall( E, V| CfaEnum( E)) trait TypedEnum { // V value( E e); // }; static inline forall( E, V | CfaEnum( E, V ) ) { int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators int ?!=?( E l, E r ) { return posn( l ) != posn( r ); } int ??( E l, E r ) { return posn( l ) > posn( r ); } int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); } E ++?( E & l ) { // increment operators l = succ( l ); return l; } E ?++( E & l ) { E ret = l; l = succ( l ); return ret; } E --?( E & l ) { l = pred( l ); return l; } E ?--( E & l ) { E ret = l; l = pred( l ); return ret; } }