diff options
-rw-r--r-- | GateAnd.cpp | 37 | ||||
-rw-r--r-- | GateAnd.h | 2 | ||||
-rw-r--r-- | Observer.cpp | 7 | ||||
-rw-r--r-- | Observer.h | 2 | ||||
-rw-r--r-- | main.cpp | 22 |
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; @@ -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(); @@ -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(); @@ -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 |