From 4fa64f6d99cb475e74188c0a270844347a48c59c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 13 Jun 2024 09:10:41 +0200 Subject: actually print right output values --- Node.cpp | 5 +++++ Node.h | 1 + NodeInput.cpp | 2 +- NodeOutput.cpp | 26 ++++++++++++++++++-------- NodeOutput.h | 6 +++++- readme.md | 2 +- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Node.cpp b/Node.cpp index e837d06..7832d30 100644 --- a/Node.cpp +++ b/Node.cpp @@ -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); diff --git a/Node.h b/Node.h index 46a06e4..f2eb497 100644 --- a/Node.h +++ b/Node.h @@ -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); } diff --git a/readme.md b/readme.md index 789010b..57cd870 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ make Functions: - [ ] loop detection (JOSHUA) -- [ ] final output format (LOEK) +- [x] final output format (LOEK) Schoonheid: -- cgit v1.2.3