source: libcfa/src/enum.hfa@ 10a9479d

Last change on this file since 10a9479d was b006c51e, checked in by JiadaL <j82liang@…>, 12 months ago

Move enum trait declaration to builtin/c

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#pragma once
2
3#include "iostream.hfa"
4
5forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial(E) )
6istype & ?|?( istype &, E & );
7
8forall( ostype & | ostream( ostype ), E | CfaEnum( E ) ) {
9 ostype & ?|?( ostype &, E );
10 OSTYPE_VOID( E );
11}
12
13static inline
14forall( E | CfaEnum(E) | Serial(E) ) {
15 int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators
16 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); }
17 int ?<?( E l, E r ) { return posn( l ) < posn( r ); }
18 int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); }
19 int ?>?( E l, E r ) { return posn( l ) > posn( r ); }
20 int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); }
21
22 E ++?( E & l ) { // increment operators
23 int pos = posn(l);
24 l = fromInt_unsafe(pos+1);
25 return l;
26 }
27
28 E --?( E & l ) {
29 int pos = posn(l);
30 l = fromInt_unsafe(pos-1);
31 return l;
32 }
33
34 E ?+=? ( E & l, one_t ) {
35 int pos = posn(l);
36 l = fromInt_unsafe(pos+1);
37 return l;
38 }
39
40 E ?-=? ( E & l, one_t ) {
41 int pos = posn(l);
42 l = fromInt_unsafe(pos-1);
43 return l;
44 }
45
46 E ?+=? ( E & l, int i ) {
47 int pos = posn(l);
48 l = fromInt_unsafe(pos+i);
49 return l;
50 }
51
52 E ?-=? ( E & l, int i ) {
53 int pos = posn(l);
54 l = fromInt_unsafe(pos-i);
55 return l;
56 }
57
58 E ?++( E & l ) {
59 int pos = posn(l);
60 l = fromInt_unsafe(pos+1);
61 return fromInt_unsafe(pos);
62 }
63
64 E ?--( E & l ) {
65 int pos = posn(l);
66 l = fromInt_unsafe(pos-1);
67 return fromInt_unsafe(pos);
68 }
69}
Note: See TracBrowser for help on using the repository browser.