diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-12 20:40:29 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-12 20:40:29 +0200 |
commit | 068a4971084bd1e415c6523c3b5eb5a48de520ca (patch) | |
tree | dfadac49c27f22dc0ada6dcfa464be99afb1827b | |
parent | 9270528a26cfd9f19d79519a61712c9d2f426106 (diff) |
fix NodeInput stuff
-rw-r--r-- | Circuit.cpp | 3 | ||||
-rw-r--r-- | GateAnd.h | 2 | ||||
-rw-r--r-- | Net.cpp | 1 | ||||
-rw-r--r-- | Node.h | 2 | ||||
-rw-r--r-- | NodeInput.cpp | 18 | ||||
-rw-r--r-- | NodeInput.h | 49 |
6 files changed, 23 insertions, 52 deletions
diff --git a/Circuit.cpp b/Circuit.cpp index d6a5375..62dfae4 100644 --- a/Circuit.cpp +++ b/Circuit.cpp @@ -43,9 +43,8 @@ void Circuit::new_net(string src, vector<string> dests) { } void Circuit::sim() { - for (auto & node : nodes) { + for (auto & node : nodes) node.second->sim(); - } } Node * Circuit::find_node(string label) { @@ -5,7 +5,6 @@ class GateAnd : public Node { public: GateAnd() = default; - GateAnd(const GateAnd * prototype); ~GateAnd() = default; virtual GateAnd * clone() const; @@ -17,6 +16,7 @@ protected: using Node::Node; private: + GateAnd(const GateAnd * prototype); constexpr static const char * type = "and"; static GateAnd instance; }; @@ -4,6 +4,7 @@ #include "prut.h" void Net::setLevel(SignalLevel level){ + // if (this->level == level) return; this->level = level; this->notify(); } @@ -31,7 +31,7 @@ protected: vector<Net *> inputs; Net * output = nullptr; -private: +protected: int min_inputs = -1; int max_inputs = -1; }; diff --git a/NodeInput.cpp b/NodeInput.cpp index 2fae505..6ee0db4 100644 --- a/NodeInput.cpp +++ b/NodeInput.cpp @@ -1,25 +1,25 @@ #include "NodeInput.h" #include "prut.h" - -NodeInput NodeInput::instance(NodeInput::type); NodeInputLow NodeInputLow::instance(NodeInputLow::type); NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type); -NodeInput::NodeInput(const NodeInput * prototype) : Node() { } - -NodeInput * NodeInput::clone() const { - return new NodeInput(this); +NodeInput::NodeInput() { + this->max_inputs = -1; + this->max_inputs = 0; } -SignalLevel NodeInput::level() { - prutprint("BaseInput"); - return UNDEFINED; +NodeInputLow * NodeInputLow::clone() const { + return new NodeInputLow(this); } SignalLevel NodeInputLow::level() { prutprint("LOW"); return LOW; } + +NodeInputHigh * NodeInputHigh::clone() const { + return new NodeInputHigh(this); +} SignalLevel NodeInputHigh::level() { prutprint("HIGH"); return HIGH; diff --git a/NodeInput.h b/NodeInput.h index 5c13133..f277130 100644 --- a/NodeInput.h +++ b/NodeInput.h @@ -6,66 +6,37 @@ class NodeInput : public Node { public: - NodeInput() = default; - NodeInput(const NodeInput * prototype); + NodeInput(); ~NodeInput() = default; - virtual NodeInput * clone() const; protected: - SignalLevel level(); - -private: - using Node::Node; - constexpr static const char * type = "input"; - static NodeInput instance; - -private: - int min_inputs = -1; - int max_inputs = 0; + NodeInput(const char * type) : Node(type) {} }; -// class NodeInput : public Node { -// public: -// using Node::Node; -// NodeInput(const NodeInput * prototype); - -// virtual NodeInput * clone() const; - -// protected: -// SignalLevel level() = 0; - -// private: -// NodeInput(const char * type); - -// SignalLevel input = UNDEFINED; -// }; - class NodeInputLow : public NodeInput { protected: SignalLevel level(); + NodeInputLow(const char * type) : NodeInput(type) {} + NodeInputLow * clone() const; private: + NodeInputLow(const NodeInputLow *) : NodeInput() {} using NodeInput::NodeInput; constexpr static const char * type = "input_low"; static NodeInputLow instance; }; class NodeInputHigh : public NodeInput { +protected: + NodeInputHigh(const char * type) : NodeInput(type) {} + private: SignalLevel level(); + NodeInputHigh(const NodeInputHigh *) : NodeInput() {} + NodeInputHigh * clone() const; using NodeInput::NodeInput; constexpr static const char * type = "input_high"; static NodeInputHigh instance; }; -// class NodeInputHigh : public NodeInput { -// public: -// using NodeInput::NodeInput; -// virtual SignalLevel level(); - -// private: -// constexpr static const char * type = "input_high"; -// static NodeInputHigh instance; -// }; - |