diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2024-06-12 16:01:30 +0200 |
---|---|---|
committer | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2024-06-12 16:01:30 +0200 |
commit | 8d64376c70e4f291f1a8fb24488cb713216eb1f9 (patch) | |
tree | b79ec04598f1fd3f0b675b9dc4bef0afe5128c77 | |
parent | 8dafb610811a34f0ec49e7484942341cf78bb6f6 (diff) |
WIP And gate w/ crack main function
-rw-r--r-- | GateAnd.cpp | 2 | ||||
-rw-r--r-- | Node.cpp | 1 | ||||
-rw-r--r-- | 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; @@ -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){ @@ -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; } |