diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2024-06-12 18:06:24 +0200 |
---|---|---|
committer | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2024-06-12 18:06:24 +0200 |
commit | 26a7c785113e4e8343685b33d8ac4aa2023380f3 (patch) | |
tree | 285afe6ea1b9f2a4f2a552cd28ae87b889b20bc0 | |
parent | 40c827da8e00a88a095f99786254493450a57065 (diff) |
nor/or
-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 |
6 files changed, 82 insertions, 4 deletions
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; }; |