Last change
on this file since bb336a6 was 6d2b3dc, checked in by JiadaL <j82liang@…>, 15 months 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
|
Rev | Line | |
---|
[c333ed2] | 1 | #include "enum.hfa"
|
---|
[85855b0] | 2 | #include "fstream.hfa"
|
---|
[6d2b3dc] | 3 | #include <string.h>
|
---|
[c333ed2] | 4 |
|
---|
[03ac869] | 5 | #pragma GCC visibility push(default)
|
---|
| 6 |
|
---|
[64eeb06] | 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 );
|
---|
[6d2b3dc] | 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
|
---|
[64eeb06] | 19 | return is;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | forall( ostype & | ostream( ostype ), E, V | CfaEnum( E, V ) ) {
|
---|
| 23 | ostype & ?|?( ostype & os, E e ) {
|
---|
[d5efcb7] | 24 | return os | label( e );
|
---|
| 25 | }
|
---|
| 26 | OSTYPE_VOID_IMPL( E )
|
---|
[85855b0] | 27 | }
|
---|
[c333ed2] | 28 |
|
---|
[64eeb06] | 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 )
|
---|
[259012e] | 34 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.