27 |
#include <vector> |
#include <vector> |
28 |
#include "exception.h" |
#include "exception.h" |
29 |
|
|
30 |
|
class vmachine; |
31 |
|
|
32 |
class circuit { |
class circuit { |
33 |
private: |
private: |
34 |
int nin, nout; |
int nin, nout; |
37 |
public: |
public: |
38 |
circuit(int nin, int nout ) |
circuit(int nin, int nout ) |
39 |
: nin(nin), nout(nout), in(nin), out(nout) {} |
: nin(nin), nout(nout), in(nin), out(nout) {} |
40 |
unsigned long get_in( int n ) { |
unsigned long get_in( int n ); |
41 |
if ( n < nin ) |
void set_out_all( unsigned long val ); |
42 |
return in[n]; |
void set_out( int n, unsigned long val ); |
43 |
else |
void link( int n, circuit c, int m ); |
|
throw ex<circuit>("circuit::get_in: " |
|
|
"getting invalid input"); |
|
|
} |
|
|
void set_out( int n, unsigned long val ) { |
|
|
if ( n < nout ) |
|
|
*(out[n]) = val; |
|
|
else |
|
|
throw ex<circuit>("circuit::set_out: " |
|
|
"setting invalid output"); |
|
|
} |
|
|
void link( int n, circuit c, int m ) { |
|
|
if ( n < nout || m < c.nin ) |
|
|
out[n] = &(c.in[m]); |
|
|
else |
|
|
throw ex<circuit>("circuit::link: " |
|
|
"linking to invalid output"); |
|
|
} |
|
44 |
int num_in( void ) {return nin;} |
int num_in( void ) {return nin;} |
45 |
int num_out( void ) {return nout;} |
int num_out( void ) {return nout;} |
46 |
}; |
}; |