diff options
-rw-r--r-- | GateAnd.h | 6 | ||||
-rw-r--r-- | GateNand.cpp | 19 | ||||
-rw-r--r-- | GateNand.h | 15 | ||||
-rw-r--r-- | GateNor.cpp | 19 | ||||
-rw-r--r-- | GateNor.h | 15 | ||||
-rw-r--r-- | GateNot.cpp | 20 | ||||
-rw-r--r-- | GateNot.h | 22 | ||||
-rw-r--r-- | GateOr.cpp | 3 | ||||
-rw-r--r-- | GateOr.h | 7 | ||||
-rw-r--r-- | NodeInput.h | 6 |
10 files changed, 125 insertions, 7 deletions
@@ -9,10 +9,14 @@ public: ~GateAnd() = default; virtual GateAnd * clone() const; -private: +protected: SignalLevel level(); + int min_inputs = 0; + int max_inputs = -1; using Node::Node; + +private: constexpr static const char * type = "and"; static GateAnd instance; }; diff --git a/GateNand.cpp b/GateNand.cpp new file mode 100644 index 0000000..8ecb90f --- /dev/null +++ b/GateNand.cpp @@ -0,0 +1,19 @@ +#include "GateNand.h" + +GateNand GateNand::instance(GateNand::type); + +// GateNand::GateNand(const char * type) : GateAnd(type) { } + +SignalLevel GateNand::level() { + SignalLevel lvl = GateAnd::level(); + if (lvl == LOW) return HIGH; + if (lvl == HIGH) return LOW; + return UNDEFINED; +} + +// GateNand::GateNand(const GateNand * prototype) : GateAnd() { } + +// GateNand * GateNand::clone() const { +// return new GateNand(this); +// } + diff --git a/GateNand.h b/GateNand.h new file mode 100644 index 0000000..7158040 --- /dev/null +++ b/GateNand.h @@ -0,0 +1,15 @@ +#pragma once + +// #include "Node.h" +#include "GateAnd.h" + +class GateNand : public GateAnd { +private: + SignalLevel level(); + + // GateNand(const char * type); + using GateAnd::GateAnd; + constexpr static const char * type = "nand"; + static GateNand instance; +}; + diff --git a/GateNor.cpp b/GateNor.cpp new file mode 100644 index 0000000..cb70236 --- /dev/null +++ b/GateNor.cpp @@ -0,0 +1,19 @@ +#include "GateNor.h" + +GateNor GateNor::instance(GateNor::type); + +// GateNor::GateNor(const char * type) : Node(type) { } + +SignalLevel GateNor::level() { + SignalLevel lvl = GateOr::level(); + if (lvl == LOW) return HIGH; + if (lvl == HIGH) return LOW; + return UNDEFINED; +} + +// GateNor::GateNor(const GateNor * prototype) : Node() { } + +// GateNor * GateNor::clone() const { +// return new GateNor(this); +// } + diff --git a/GateNor.h b/GateNor.h new file mode 100644 index 0000000..2c2760d --- /dev/null +++ b/GateNor.h @@ -0,0 +1,15 @@ +#pragma once + +// #include "Node.h" +#include "GateOr.h" + +class GateNor : public GateOr { +private: + SignalLevel level(); + + // GateNor(const char * type); + using GateOr::GateOr; + constexpr static const char * type = "nor"; + static GateNor instance; +}; + diff --git a/GateNot.cpp b/GateNot.cpp new file mode 100644 index 0000000..c272022 --- /dev/null +++ b/GateNot.cpp @@ -0,0 +1,20 @@ +#include "GateNot.h" + +GateNot GateNot::instance(GateNot::type); + +SignalLevel GateNot::level() { + SignalLevel new_level = LOW; + for (int i = 0; i < this->inputs.size(); i++){ + SignalLevel l = this->inputs[i]->getLevel(); + + if (l == UNDEFINED) return UNDEFINED; + if (l == HIGH) new_level = HIGH; + } + return new_level; +} + +GateNot::GateNot(const GateNot * prototype) : Node() { } + +GateNot * GateNot::clone() const { + return new GateNot(this); +} diff --git a/GateNot.h b/GateNot.h new file mode 100644 index 0000000..55fd9ce --- /dev/null +++ b/GateNot.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Node.h" + +class GateNot : public Node { +public: + GateNot() = default; + GateNot(const GateNot * prototype); + ~GateNot() = default; + virtual GateNot * clone() const; + +private: + SignalLevel level(); + + using Node::Node; + constexpr static const char * type = "Not"; + static GateNot instance; + +private: + int min_inputs = 1; + int max_inputs = 1; +}; @@ -3,8 +3,6 @@ GateOr GateOr::instance(GateOr::type); SignalLevel GateOr::level() { - if (this->inputs.size() < 1) throw CircuitException("Or-gate input size error"); - SignalLevel new_level = LOW; for (int i = 0; i < this->inputs.size(); i++){ SignalLevel l = this->inputs[i]->getLevel(); @@ -20,4 +18,3 @@ GateOr::GateOr(const GateOr * prototype) : Node() { } GateOr * GateOr::clone() const { return new GateOr(this); } - @@ -9,11 +9,16 @@ public: ~GateOr() = default; virtual GateOr * clone() const; -private: +protected: SignalLevel level(); +private: using Node::Node; constexpr static const char * type = "or"; static GateOr instance; + +private: + int min_inputs = 0; + int max_inputs = -1; }; diff --git a/NodeInput.h b/NodeInput.h index 7ec296b..e176fa7 100644 --- a/NodeInput.h +++ b/NodeInput.h @@ -11,8 +11,10 @@ public: virtual NodeInput * clone() const; -protected: - virtual SignalLevel level(); +private: + NodeInput(const char * type); + + SignalLevel input = UNDEFINED; }; class NodeInputLow : public NodeInput { |