diff options
-rw-r--r-- | GateXor.cpp | 20 | ||||
-rw-r--r-- | GateXor.h | 22 |
2 files changed, 42 insertions, 0 deletions
diff --git a/GateXor.cpp b/GateXor.cpp new file mode 100644 index 0000000..84fb1ec --- /dev/null +++ b/GateXor.cpp @@ -0,0 +1,20 @@ +#include "GateXor.h" + +GateXor GateXor::instance(GateXor::type); + +SignalLevel GateXor::level() { + int highCount = 0; + for (int i = 0; i < this->inputs.size(); i++) { + SignalLevel l = this->inputs[i]->getLevel(); + + if (l == UNDEFINED) return UNDEFINED; + if (l == HIGH) highCount++; + } + return (highCount % 2 == 1) ? HIGH : LOW; +} + +GateXor::GateXor(const GateXor *prototype) : Node() {} + +GateXor *GateXor::clone() const { + return new GateXor(this); +} diff --git a/GateXor.h b/GateXor.h new file mode 100644 index 0000000..37903e0 --- /dev/null +++ b/GateXor.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Node.h" + +class GateXor : public Node { +public: + GateXor() = default; + GateXor(const GateXor * prototype); + ~GateXor() = default; + virtual GateXor * clone() const; + +private: + SignalLevel level(); + + using Node::Node; + constexpr static const char * type = "xor"; + static GateXor instance; + +private: + int min_inputs = 1; + int max_inputs = -1; +}; |