aboutsummaryrefslogtreecommitdiff
path: root/GateXor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'GateXor.cpp')
-rw-r--r--GateXor.cpp20
1 files changed, 20 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);
+}