aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GateAnd.cpp2
-rw-r--r--Node.cpp1
-rw-r--r--main.cpp24
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;
}