aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-13 09:47:15 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-13 09:47:15 +0200
commit39324cdd8ca253bc9a8030ef55e2a5138bd3c734 (patch)
treeb9f05a31c4aa01c28e61b8e8a931993c1438fb50
parent4fa64f6d99cb475e74188c0a270844347a48c59c (diff)
create SignalLevel to_string function
-rw-r--r--Net.h7
-rw-r--r--NodeFactory.cpp4
-rw-r--r--NodeOutputVisitor.cpp2
-rw-r--r--SignalLevel.cpp9
-rw-r--r--SignalLevel.h14
5 files changed, 28 insertions, 8 deletions
diff --git a/Net.h b/Net.h
index 7168186..edd3dfe 100644
--- a/Net.h
+++ b/Net.h
@@ -1,12 +1,7 @@
#pragma once
#include "Observer.h"
-
-enum SignalLevel {
- LOW,
- HIGH,
- UNDEFINED
-};
+#include "SignalLevel.h"
class Net : public Subject {
private:
diff --git a/NodeFactory.cpp b/NodeFactory.cpp
index c9d4f20..6105c2d 100644
--- a/NodeFactory.cpp
+++ b/NodeFactory.cpp
@@ -1,3 +1,4 @@
+#include <cassert>
#include <locale>
#include <ranges>
#include <algorithm>
@@ -22,7 +23,8 @@ void NodeFactory::assign(const char * _type, const Node * node) {
string type = _type;
type = normalize_type(type);
- if (has_type(type)) return; // TODO: exception?
+ // ensure there is only one class that registers a type
+ assert(!has_type(type));
// printf("map[\"%s\"] = %p\n", type.c_str(), node);
map[type] = node;
diff --git a/NodeOutputVisitor.cpp b/NodeOutputVisitor.cpp
index ca00fd4..e92224c 100644
--- a/NodeOutputVisitor.cpp
+++ b/NodeOutputVisitor.cpp
@@ -2,7 +2,7 @@
void NodeOutputVisitor::visit(Node & node) { }
void NodeOutputVisitor::visit(NodeOutput & node) {
- level = node.level(); // TODO: dit klopt niet
+ level = node.level();
output_node = true;
}
diff --git a/SignalLevel.cpp b/SignalLevel.cpp
new file mode 100644
index 0000000..daba33c
--- /dev/null
+++ b/SignalLevel.cpp
@@ -0,0 +1,9 @@
+#include "SignalLevel.h"
+
+std::string std::to_string(SignalLevel level) {
+ if (level == HIGH) return "HIGH";
+ if (level == LOW) return "LOW";
+ if (level == UNDEFINED) return "UNDEFINED";
+ return "???";
+}
+
diff --git a/SignalLevel.h b/SignalLevel.h
new file mode 100644
index 0000000..81c7ff8
--- /dev/null
+++ b/SignalLevel.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <string>
+
+enum SignalLevel {
+ LOW,
+ HIGH,
+ UNDEFINED
+};
+
+namespace std {
+ std::string to_string(SignalLevel level);
+}
+