diff options
Diffstat (limited to 'GateAnd.cpp')
-rw-r--r-- | GateAnd.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/GateAnd.cpp b/GateAnd.cpp index 93edacb..d14d7f6 100644 --- a/GateAnd.cpp +++ b/GateAnd.cpp @@ -1,27 +1,32 @@ #include "GateAnd.h" +#include "Exception.h" GateAnd GateAnd::instance(GateAnd::type); GateAnd::GateAnd(const char * type) : Node(type) { } -void GateAnd::sim() { - SignalLevel new_out = HIGH; - // TODO: fix segfault somewhere below +SignalLevel GateAnd::level() { + if (this->inputs.size() < 1) throw CircuitException("AndGate input size error"); + for (int i = 0; i < this->inputs.size(); i++){ - switch (this->inputs[i]->getLevel()){ - case LOW: - new_out = LOW; - break; - case HIGH: - continue; - break; - case UNDEFINED: - default: - new_out = UNDEFINED; - // TODO: exception!! - break; - } + SignalLevel l this->inputs[i]->getLevel(); + + if (l == UNDEFINED) return UNDEFINED; + if (l == LOW) return LOW; } + return HIGH; +} + +// Concrete Nodes: +void GateAnd::sim() { + SignalLevel new_out = this->level(); + + if (new_out == UNDEFINED) return; + + printf("io size: %lu\n", this->inputs.size()); + // TODO: fix segfault somewhere below + + if (this->output->getLevel() == new_out) return; |