From 40c827da8e00a88a095f99786254493450a57065 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:53:22 +0200 Subject: nand --- GateAnd.h | 6 +++++- GateNand.cpp | 19 +++++++++++++++++++ GateNand.h | 15 +++++++++++++++ NodeInput.h | 2 +- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 GateNand.cpp create mode 100644 GateNand.h diff --git a/GateAnd.h b/GateAnd.h index a8cc3d0..639a93b 100644 --- a/GateAnd.h +++ b/GateAnd.h @@ -9,10 +9,14 @@ public: ~GateAnd() = default; virtual GateAnd * clone() const; -private: +protected: SignalLevel level(); + int min_inputs = 0; + int max_inputs = -1; GateAnd(const char * type); + +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/NodeInput.h b/NodeInput.h index 71cf36c..82dfd4c 100644 --- a/NodeInput.h +++ b/NodeInput.h @@ -14,7 +14,7 @@ public: private: NodeInput(const char * type); -SignalLevel input = UNDEFINED; + SignalLevel input = UNDEFINED; }; // Input LOW and HIGH unicorns: -- cgit v1.2.3 From 26a7c785113e4e8343685b33d8ac4aa2023380f3 Mon Sep 17 00:00:00 2001 From: UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> Date: Wed, 12 Jun 2024 18:06:24 +0200 Subject: nor/or --- GateNor.cpp | 19 +++++++++++++++++++ GateNor.h | 15 +++++++++++++++ GateNot.cpp | 20 ++++++++++++++++++++ GateNot.h | 22 ++++++++++++++++++++++ GateOr.cpp | 3 --- GateOr.h | 7 ++++++- 6 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 GateNor.cpp create mode 100644 GateNor.h create mode 100644 GateNot.cpp create mode 100644 GateNot.h 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; +}; diff --git a/GateOr.cpp b/GateOr.cpp index db1e04a..0aafe50 100644 --- a/GateOr.cpp +++ b/GateOr.cpp @@ -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); } - diff --git a/GateOr.h b/GateOr.h index de694be..0668148 100644 --- a/GateOr.h +++ b/GateOr.h @@ -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; }; -- cgit v1.2.3