Last change
on this file since c015e2d was
6d2b3dc,
checked in by JiadaL <j82liang@…>, 7 weeks ago
|
Change (enum) range loop so that it works on any type that define succ() and upperBound()
|
-
Property mode set to
100644
|
File size:
917 bytes
|
Line | |
---|
1 | #include "enum.hfa" |
---|
2 | #include "fstream.hfa" |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | #pragma GCC visibility push(default) |
---|
6 | |
---|
7 | forall( istype & | istream( istype ), E, V | CfaEnum( E, V ) ) |
---|
8 | istype & ?|?( istype & is, E & e ) { |
---|
9 | if ( eof( is ) ) throwResume ExceptionInst( missing_data ); |
---|
10 | char val[256]; |
---|
11 | int args = fmt( is, "%255s", val ); |
---|
12 | if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data ); |
---|
13 | for ( s; E ) { |
---|
14 | if ( strcmp(val, label( s )) == 0 ) { e = s; break; } |
---|
15 | } else { |
---|
16 | fprintf( stderr, "invalid enumeration constant\n" ); |
---|
17 | abort(); // cannot use abort stream |
---|
18 | } // for |
---|
19 | return is; |
---|
20 | } |
---|
21 | |
---|
22 | forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) { |
---|
23 | ostype & ?|?( ostype & os, E e ) { |
---|
24 | return os | label( e ); |
---|
25 | } |
---|
26 | OSTYPE_VOID_IMPL( E ) |
---|
27 | } |
---|
28 | |
---|
29 | forall( ostype & | ostream( ostype ), E | CfaEnum( E, quasi_void ) ) { |
---|
30 | ostype & ?|?( ostype & os, E e ) { |
---|
31 | return os | label( e ); |
---|
32 | } |
---|
33 | OSTYPE_VOID_IMPL( E ) |
---|
34 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.