source: libcfa/src/enum.hfa @ bc48c0d

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

fix enumeration input to use reference type

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#pragma once
2
3#include "iostream.hfa"
4
5forall( E ) trait Bounded {
6    E lowerBound();
7    E upperBound();
8};
9
10forall( E | Bounded( E ) ) trait Serial {
11    unsigned fromInstance( E e );
12    E fromInt( unsigned i );
13    E succ( E e );
14    E pred( E e );
15};
16
17// Design one
18forall( E, V | Serial( E ) ) trait CfaEnum {
19    char * label( E e );
20    unsigned int posn( E e );
21    V value( E e );
22};
23
24// I/O
25
26forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) )
27istype & ?|?( istype &, E & );
28
29forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) {
30        ostype & ?|?( ostype &, E );
31        OSTYPE_VOID( E );
32}
33
34forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) {
35        ostype & ?|?( ostype &, E );
36        OSTYPE_VOID( E );
37}
38
39// Design two <- should go for this if we have change the cost model
40// forall( E | Serial( E ) ) trait CfaEnum {
41//     char * label( E e );
42//     unsigned int posn( E e );
43// };
44
45// forall( E, V| CfaEnum( E)) trait TypedEnum {
46//     V value( E e);
47// };
48
49forall( E, V | CfaEnum( E, V ) ) {                                              // relational operators
50    int ?==?( E, E );
51    int ?!=?( E, E );
52    int ?<?( E, E );
53    int ?<=?( E, E );
54    int ?>?( E, E );
55    int ?>=?( E, E );
56
57    int ++?( E &);
58    int ?++( E &);
59    int --?( E &);
60    int ?--( E &);
61}
Note: See TracBrowser for help on using the repository browser.