diff options
-rw-r--r-- | Node.cpp | 5 | ||||
-rw-r--r-- | Node.h | 1 | ||||
-rw-r--r-- | NodeInput.cpp | 2 | ||||
-rw-r--r-- | NodeOutput.cpp | 26 | ||||
-rw-r--r-- | NodeOutput.h | 6 | ||||
-rw-r--r-- | readme.md | 2 |
6 files changed, 31 insertions, 11 deletions
@@ -30,10 +30,15 @@ void Node::sim() { throw CircuitException("Too few inputs"); if (this->max_inputs >= 0 && input_size > max_inputs) throw CircuitException("Too many inputs"); + + // NodeOutput does not have an output itself + if (this->output == nullptr) return; SignalLevel new_out = this->level(); + // don't propagate if undefined if (new_out == UNDEFINED) return; + // don't propagate if unchanged if (this->output->getLevel() == new_out) return; this->output->setLevel(new_out); @@ -17,6 +17,7 @@ public: virtual Node * clone() const = 0; public: + //! alias to \p sim() for Observer void update(); virtual void addInput(Net *); virtual void setOutput(Net *); diff --git a/NodeInput.cpp b/NodeInput.cpp index 41d5352..a106319 100644 --- a/NodeInput.cpp +++ b/NodeInput.cpp @@ -5,7 +5,7 @@ NodeInputLow NodeInputLow::instance(NodeInputLow::type); NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type); NodeInput::NodeInput() { - this->max_inputs = -1; + this->min_inputs = -1; this->max_inputs = 0; } diff --git a/NodeOutput.cpp b/NodeOutput.cpp index a02ba1f..cf1b979 100644 --- a/NodeOutput.cpp +++ b/NodeOutput.cpp @@ -1,21 +1,31 @@ #include "NodeOutput.h" #include "Exception.h" -#include "prut.h" - NodeOutput NodeOutput::instance(NodeOutput::type); -NodeOutput::NodeOutput(const char * type) : Node(type) { } +NodeOutput::NodeOutput(const char * type) : Node(type) { init(); } -void NodeOutput::sim() { - if (this->inputs.size() == 0) - throw CircuitException("No inputs on probe"); +void NodeOutput::init() { + this->min_inputs = 1; + this->max_inputs = 1; +} - prutprintf("level: %u", this->inputs[0]->getLevel()); +void NodeOutput::sim() { + Node::sim(); + this->input = this->inputs[0]->getLevel(); } -NodeOutput::NodeOutput(const NodeOutput * prototype) : Node() { } +NodeOutput::NodeOutput(const NodeOutput * prototype) : Node() { init(); } NodeOutput * NodeOutput::clone() const { return new NodeOutput(this); } + +void NodeOutput::setOutput(Net *) { + throw CircuitException("NodeOutput cannot have an output"); +} + +SignalLevel NodeOutput::level() { + return this->input; +} + diff --git a/NodeOutput.h b/NodeOutput.h index cd25055..d2319f1 100644 --- a/NodeOutput.h +++ b/NodeOutput.h @@ -4,16 +4,20 @@ class NodeOutput : public Node { public: + NodeOutput(); NodeOutput(const NodeOutput * prototype); ~NodeOutput() = default; virtual void sim(); - SignalLevel level() { return UNDEFINED; }; + virtual SignalLevel level(); virtual NodeOutput * clone() const; + virtual void setOutput(Net *); private: + virtual void init(); NodeOutput(const char * type); constexpr static const char * type = "probe"; static NodeOutput instance; + SignalLevel input; public: virtual void accept(NodeVisitor & visitor) { visitor.visit(*this); } @@ -20,7 +20,7 @@ make Functions: - [ ] loop detection (JOSHUA) -- [ ] final output format (LOEK) +- [x] final output format (LOEK) Schoonheid: |