diff options
-rw-r--r-- | Node.cpp | 6 | ||||
-rw-r--r-- | Node.h | 2 | ||||
-rw-r--r-- | NodeInput.cpp | 10 | ||||
-rw-r--r-- | NodeInput.h | 54 | ||||
-rw-r--r-- | readme.md | 22 |
5 files changed, 65 insertions, 29 deletions
@@ -16,7 +16,11 @@ void Node::addInput(Net * net) { } void Node::setOutput(Net * net){ - this->output = net; + if (this->output == nullptr) { + this->output = net; + } else { + throw CircuitException("Net already assigned"); + } } void Node::sim() { @@ -29,7 +29,7 @@ protected: string label; vector<Net *> inputs; - Net * output; + Net * output = nullptr; private: int min_inputs = -1; diff --git a/NodeInput.cpp b/NodeInput.cpp index 2d1d517..ea328e3 100644 --- a/NodeInput.cpp +++ b/NodeInput.cpp @@ -1,8 +1,8 @@ #include "NodeInput.h" #include "prut.h" -#include <iostream> +NodeInput NodeInput::instance(NodeInput::type); NodeInputLow NodeInputLow::instance(NodeInputLow::type); NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type); @@ -13,15 +13,15 @@ NodeInput * NodeInput::clone() const { } SignalLevel NodeInput::level() { - prutprint(""); - return UNDEFINED; + prutprint("BaseInput"); + return HIGH; } SignalLevel NodeInputLow::level() { - prutprint(""); + prutprint("LOW"); return LOW; } SignalLevel NodeInputHigh::level() { - prutprint(""); + prutprint("HIGH"); return HIGH; } diff --git a/NodeInput.h b/NodeInput.h index e176fa7..5c13133 100644 --- a/NodeInput.h +++ b/NodeInput.h @@ -6,34 +6,66 @@ class NodeInput : public Node { public: - using Node::Node; + NodeInput() = default; NodeInput(const NodeInput * prototype); - + ~NodeInput() = default; virtual NodeInput * clone() const; +protected: + SignalLevel level(); + private: - NodeInput(const char * type); + using Node::Node; + constexpr static const char * type = "input"; + static NodeInput instance; - SignalLevel input = UNDEFINED; +private: + int min_inputs = -1; + int max_inputs = 0; }; +// 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 { -public: - using NodeInput::NodeInput; - virtual SignalLevel level(); +protected: + SignalLevel level(); private: + using NodeInput::NodeInput; constexpr static const char * type = "input_low"; static NodeInputLow instance; }; class NodeInputHigh : public NodeInput { -public: - using NodeInput::NodeInput; - virtual SignalLevel level(); - private: + SignalLevel level(); + + 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; +// }; + @@ -17,19 +17,19 @@ make ## TODO -- [ ] abstract class Node -- [ ] class CircuitFactory -- [ ] class GateAnd -- [ ] class GateNand -- [ ] class GateNor +- [x] class Node +- [x] class CircuitFactory +- [x] class GateAnd +- [x] class GateNand +- [X] class GateNor - [ ] class GateNot -- [ ] class GateOr +- [x] class GateOr - [ ] class GateXor -- [ ] class Net +- [x] class Net - [ ] class NodeInput - [ ] class NodeOutput -- [ ] class Parser -- [ ] class Subject -- [ ] enum SignalLevel -- [ ] interface Observer +- [x] class Parser +- [x] class Subject +- [x] enum SignalLevel +- [x] interface Observer |