diff options
-rw-r--r-- | GateAnd.cpp | 2 | ||||
-rw-r--r-- | GateAnd.h | 2 | ||||
-rw-r--r-- | Net.cpp | 7 | ||||
-rw-r--r-- | Node.cpp | 4 | ||||
-rw-r--r-- | NodeInput.cpp | 13 | ||||
-rw-r--r-- | NodeInput.h | 18 | ||||
-rw-r--r-- | NodeOutput.cpp | 6 | ||||
-rw-r--r-- | Observer.cpp | 13 | ||||
-rw-r--r-- | Observer.h | 10 | ||||
-rw-r--r-- | prut.h | 6 |
10 files changed, 38 insertions, 43 deletions
diff --git a/GateAnd.cpp b/GateAnd.cpp index 487f8bc..987d5e4 100644 --- a/GateAnd.cpp +++ b/GateAnd.cpp @@ -3,8 +3,6 @@ GateAnd GateAnd::instance(GateAnd::type); -GateAnd::GateAnd(const char * type) : Node(type) { } - SignalLevel GateAnd::level() { if (this->inputs.size() < 1) throw CircuitException("AndGate input size error"); @@ -13,7 +13,7 @@ public: private: SignalLevel level(); - GateAnd(const char * type); + using Node::Node; constexpr static const char * type = "and"; static GateAnd instance; }; @@ -1,9 +1,14 @@ #include "Net.h" #include <iostream> +#include "prut.h" + void Net::setLevel(SignalLevel level){ this->level = level; - std::cout << this->size() << std::endl; + // std::cout << this->size() << std::endl; + prutprintf("%u", this->size()); + + this->notify(); } @@ -4,6 +4,8 @@ #include "NodeFactory.h" #include "Net.h" +#include "prut.h" + Node::Node(const char * type) { NodeFactory::assign(type, this); } @@ -18,7 +20,7 @@ void Node::setOutput(Net * net){ } void Node::update(){ - std::cout << "updated" << std::endl; + prutprint("updated"); this->sim(); } diff --git a/NodeInput.cpp b/NodeInput.cpp index 17f9ed5..618ed31 100644 --- a/NodeInput.cpp +++ b/NodeInput.cpp @@ -2,12 +2,13 @@ #include <iostream> -NodeInput::NodeInput(const char * type) : Node(type) { } +NodeInputLow NodeInputLow::instance(NodeInputLow::type); +NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type); void NodeInput::sim() { - if (this->output == nullptr) return; - std::cout << this->level << " bar\n"; - this->output->setLevel(this->level); + if (this->output == nullptr) return; + // std::cout << this->level << " bar\n"; + this->output->setLevel(this->level); } NodeInput::NodeInput(const NodeInput * prototype) : Node() { } @@ -16,10 +17,6 @@ NodeInput * NodeInput::clone() const { return new NodeInput(this); } -// INPUT_LOW -NodeInputLow NodeInputLow::instance(NodeInputLow::type); -NodeInputLow::NodeInputLow(const char * type) : NodeInput() { } - // NodeInputLow::NodeInputLow(const NodeInputLow * prototype) : NodeInput() { } // // INPUT_HIGH diff --git a/NodeInput.h b/NodeInput.h index bcca8f4..e6206b9 100644 --- a/NodeInput.h +++ b/NodeInput.h @@ -4,21 +4,22 @@ class NodeInput : public Node { public: - NodeInput() = default; + NodeInput() = default; NodeInput(const NodeInput * prototype); ~NodeInput() = default; virtual void sim(); virtual NodeInput * clone() const; -private: - NodeInput(const char * type); - - SignalLevel level = UNDEFINED; +protected: + using Node::Node; + SignalLevel level = UNDEFINED; }; // Input LOW and HIGH unicorns: class NodeInputLow : public NodeInput { + using NodeInput::NodeInput; + public: // NodeInputLow(const NodeInputLow * prototype); // ~NodeInputLow() = default; @@ -26,18 +27,17 @@ public: // virtual NodeInputLow * clone() const; private: - NodeInputLow(const char * type); constexpr static const char * type = "input_low"; static NodeInputLow instance; - SignalLevel level = LOW; + SignalLevel level = LOW; }; class NodeInputHigh : public NodeInput { private: - NodeInputHigh(const char * type); + using NodeInput::NodeInput; constexpr static const char * type = "input_high"; static NodeInputHigh instance; - SignalLevel level = HIGH; + SignalLevel level = HIGH; }; diff --git a/NodeOutput.cpp b/NodeOutput.cpp index 00ca006..a02ba1f 100644 --- a/NodeOutput.cpp +++ b/NodeOutput.cpp @@ -1,7 +1,7 @@ #include "NodeOutput.h" #include "Exception.h" -#include <iostream> +#include "prut.h" NodeOutput NodeOutput::instance(NodeOutput::type); @@ -11,11 +11,11 @@ void NodeOutput::sim() { if (this->inputs.size() == 0) throw CircuitException("No inputs on probe"); - std::cout << this->inputs[0]->getLevel() << "foo" << std::endl; + prutprintf("level: %u", this->inputs[0]->getLevel()); } NodeOutput::NodeOutput(const NodeOutput * prototype) : Node() { } NodeOutput * NodeOutput::clone() const { return new NodeOutput(this); -}
\ No newline at end of file +} diff --git a/Observer.cpp b/Observer.cpp index ff523b8..39a8245 100644 --- a/Observer.cpp +++ b/Observer.cpp @@ -2,12 +2,8 @@ #include "Observer.h" -void Observer::update(){ - std::cout << 'a' << std::endl; -} - void Subject::attach(Observer * obs){ - std::cout << "added" << std::endl; + // std::cout << "added" << std::endl; this->observers.push_back(obs); } @@ -16,13 +12,12 @@ void Subject::detach(Observer *){ } int Subject::size() { - std::cout << "subject list size " << this->observers.size() << std::endl; + // 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(); + for (auto observer : this->observers) + observer->update(); } @@ -2,11 +2,8 @@ #include <vector> class Observer { -private: - public: - virtual void update(); - + virtual void update() = 0; }; class Subject { @@ -18,11 +15,6 @@ public: virtual void detach(Observer*); virtual int size(); - // TODO possibly add foo input as update value? virtual void notify(); - // virtual void notify() { - // for (int i = 0; i < observers.size(); i++) - // observers.at(i)->update(); - // } }; @@ -0,0 +1,6 @@ +#pragma once + +#define prutprintf(fmt, ...) printf("\x1b[37m%s (%s:%d):\x1b[0m " fmt "\n", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, __VA_ARGS__) + +#define prutprint(s) prutprintf("%s", s) + |