diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-13 09:47:15 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-13 09:47:15 +0200 |
commit | 39324cdd8ca253bc9a8030ef55e2a5138bd3c734 (patch) | |
tree | b9f05a31c4aa01c28e61b8e8a931993c1438fb50 | |
parent | 4fa64f6d99cb475e74188c0a270844347a48c59c (diff) |
create SignalLevel to_string function
-rw-r--r-- | Net.h | 7 | ||||
-rw-r--r-- | NodeFactory.cpp | 4 | ||||
-rw-r--r-- | NodeOutputVisitor.cpp | 2 | ||||
-rw-r--r-- | SignalLevel.cpp | 9 | ||||
-rw-r--r-- | SignalLevel.h | 14 |
5 files changed, 28 insertions, 8 deletions
@@ -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); +} + |