aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GateAnd.cpp37
-rw-r--r--GateAnd.h2
-rw-r--r--Observer.cpp7
-rw-r--r--Observer.h2
-rw-r--r--main.cpp22
5 files changed, 52 insertions, 18 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;
diff --git a/GateAnd.h b/GateAnd.h
index 12dad53..142c628 100644
--- a/GateAnd.h
+++ b/GateAnd.h
@@ -11,6 +11,8 @@ public:
virtual GateAnd * clone() const;
private:
+ SignalLevel level();
+
GateAnd(const char * type);
constexpr static const char * type = "and";
static GateAnd instance;
diff --git a/Observer.cpp b/Observer.cpp
index 8d9823b..ff523b8 100644
--- a/Observer.cpp
+++ b/Observer.cpp
@@ -15,7 +15,12 @@ void Subject::detach(Observer *){
}
-// TODO: possibly add foo input as update value?
+int Subject::size() {
+ std::cout << "subject list size " << this->observers.size() << std::endl;
+ return this->observers.size();
+}
+
+// TODO possibly add foo input as update value?
void Subject::notify() {
for (int i = 0; i < this->observers.size(); i++)
this->observers[i]->update();
diff --git a/Observer.h b/Observer.h
index 7b2db7e..580d539 100644
--- a/Observer.h
+++ b/Observer.h
@@ -16,7 +16,7 @@ public:
// virtual void attach(Observer* obs) { observers.push_back(obs);}
virtual void attach(Observer* obs);
virtual void detach(Observer*);
- virtual int size() { return this->observers.size(); }
+ virtual int size();
// TODO possibly add foo input as update value?
virtual void notify();
diff --git a/main.cpp b/main.cpp
index e2721b1..5fcfb3e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,6 +8,27 @@ using std::cout;
using std::endl;
using std::ifstream;
+#include "Node.h"
+#include "GateAnd.h"
+
+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);
+ return 0;
+}
+
+/*
int main(int argc, char** argv) {
Parser main_parser;
Circuit circuit;
@@ -36,3 +57,4 @@ int main(int argc, char** argv) {
return EXIT_SUCCESS;
}
+*/ \ No newline at end of file