From 39324cdd8ca253bc9a8030ef55e2a5138bd3c734 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 13 Jun 2024 09:47:15 +0200 Subject: create SignalLevel to_string function --- Net.h | 7 +------ NodeFactory.cpp | 4 +++- NodeOutputVisitor.cpp | 2 +- SignalLevel.cpp | 9 +++++++++ SignalLevel.h | 14 ++++++++++++++ 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 SignalLevel.cpp create mode 100644 SignalLevel.h 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 #include #include #include @@ -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 + +enum SignalLevel { + LOW, + HIGH, + UNDEFINED +}; + +namespace std { + std::string to_string(SignalLevel level); +} + -- cgit v1.2.3