#include "circuit.h" #include "assert.h" int Gate::cal_value() { int res; switch(type) { case NOT: res = !inputs[0]->value; break; case BUF: res = inputs[0]->value; break; case AND: res = inputs[0]->value; for(int i=1; ivalue; } break; case NAND: res = inputs[0]->value; for(int i=1; ivalue; } res = !res; break; case OR: res = inputs[0]->value; for(int i=1; ivalue; } break; case NOR: res = inputs[0]->value; for(int i=1; ivalue; } res = !res; break; case XOR: res = inputs[0]->value; for(int i=1; ivalue; } break; case XNOR: res = inputs[0]->value; for(int i=1; ivalue; } res = !res; break; case INPUT: res = value; break; default: assert(false); break; } return res; }