From 8d64376c70e4f291f1a8fb24488cb713216eb1f9 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:01:30 +0200 Subject: WIP And gate w/ crack main function --- GateAnd.cpp | 2 +- Node.cpp | 1 + main.cpp | 24 ++++++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/GateAnd.cpp b/GateAnd.cpp index d14d7f6..487f8bc 100644 --- a/GateAnd.cpp +++ b/GateAnd.cpp @@ -9,7 +9,7 @@ SignalLevel GateAnd::level() { if (this->inputs.size() < 1) throw CircuitException("AndGate input size error"); for (int i = 0; i < this->inputs.size(); i++){ - SignalLevel l this->inputs[i]->getLevel(); + SignalLevel l = this->inputs[i]->getLevel(); if (l == UNDEFINED) return UNDEFINED; if (l == LOW) return LOW; diff --git a/Node.cpp b/Node.cpp index d3564da..75f94e5 100644 --- a/Node.cpp +++ b/Node.cpp @@ -10,6 +10,7 @@ Node::Node(const char * type) { void Node::addInput(Net * net) { net->attach(this); + inputs.push_back(net); } void Node::setOutput(Net * net){ diff --git a/main.cpp b/main.cpp index 5fcfb3e..032a812 100644 --- a/main.cpp +++ b/main.cpp @@ -15,16 +15,20 @@ int main() { // Observer ob(); Net n, n1, o; Node *g = new GateAnd; - g->addInput(&n); - g->addInput(&n1); - g->setOutput(&o); - - // o.setLevel(UNDEFINED); - n.setLevel(LOW); - n1.setLevel(LOW); - int level = 22; - level = o.getLevel(); - printf("hello world! %d\n", level); + try { + g->addInput(&n); + g->addInput(&n1); + g->setOutput(&o); + + // o.setLevel(UNDEFINED); + n.setLevel(HIGH); + n1.setLevel(HIGH); + int level = 22; + level = o.getLevel(); + printf("hello world! %d\n", level); + } catch(Exception& e) { + std::cerr << e.what() << '\n'; + } return 0; } -- cgit v1.2.3