aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-12 18:03:07 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-12 18:03:07 +0200
commit50d3fb09278d57b5a35e15074cc025a62476c5a7 (patch)
treedbd7c9f62e49c0ef01e5d970758f08450e2a2af5
parenta6eb3c69badee386579fba82cae5b29cfb3e8171 (diff)
WIP NodeInput kinda not really working
-rw-r--r--Circuit.cpp5
-rw-r--r--Net.cpp4
-rw-r--r--Node.cpp1
-rw-r--r--NodeInput.cpp26
-rw-r--r--NodeInput.h33
-rw-r--r--main.cpp3
6 files changed, 30 insertions, 42 deletions
diff --git a/Circuit.cpp b/Circuit.cpp
index 8137939..d6a5375 100644
--- a/Circuit.cpp
+++ b/Circuit.cpp
@@ -2,6 +2,8 @@
#include "Exception.h"
#include "NodeFactory.h"
+#include "prut.h"
+
void Circuit::create(string label, vector<string> nodes) {
if (nodes.size() == 1 && NodeFactory::has_type(nodes[0]))
return new_node(label, nodes[0]);
@@ -19,7 +21,7 @@ void Circuit::new_node(string label, string type) {
nodes[label] = node;
- printf("[%s] (%s)\n", label.c_str(), type.c_str());
+ prutprintf("[%s] (%s)", label.c_str(), type.c_str());
}
void Circuit::new_net(string src, vector<string> dests) {
@@ -36,6 +38,7 @@ void Circuit::new_net(string src, vector<string> dests) {
if (node == nullptr)
throw CircuitException("unknown destination node \"%s\"", dest.c_str());
node->addInput(net);
+ prutprintf("%s -> %s", src.c_str(), dest.c_str());
}
}
diff --git a/Net.cpp b/Net.cpp
index 801210b..9797796 100644
--- a/Net.cpp
+++ b/Net.cpp
@@ -5,10 +5,6 @@
void Net::setLevel(SignalLevel level){
this->level = level;
- // std::cout << this->size() << std::endl;
- prutprintf("%u", this->size());
-
-
this->notify();
}
diff --git a/Node.cpp b/Node.cpp
index 3a9f6f3..092d05d 100644
--- a/Node.cpp
+++ b/Node.cpp
@@ -35,7 +35,6 @@ void Node::sim() {
}
void Node::update(){
- prutprint("updated");
this->sim();
}
diff --git a/NodeInput.cpp b/NodeInput.cpp
index fafbd3b..2d1d517 100644
--- a/NodeInput.cpp
+++ b/NodeInput.cpp
@@ -1,18 +1,11 @@
#include "NodeInput.h"
+#include "prut.h"
#include <iostream>
NodeInputLow NodeInputLow::instance(NodeInputLow::type);
NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type);
-NodeInput::NodeInput(const char * type) : Node(type) { };
-
-void NodeInput::sim() {
- if (this->output == nullptr) return;
- // std::cout << this->level << " bar\n";
- this->output->setLevel(this->input);
-}
-
NodeInput::NodeInput(const NodeInput * prototype) : Node() { }
NodeInput * NodeInput::clone() const {
@@ -20,12 +13,15 @@ NodeInput * NodeInput::clone() const {
}
SignalLevel NodeInput::level() {
+ prutprint("");
return UNDEFINED;
-};
-
-// NodeInputLow::NodeInputLow(const NodeInputLow * prototype) : NodeInput() { }
+}
+SignalLevel NodeInputLow::level() {
+ prutprint("");
+ return LOW;
+}
+SignalLevel NodeInputHigh::level() {
+ prutprint("");
+ return HIGH;
+}
-// // INPUT_HIGH
-// NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type);
-// NodeInputHigh::NodeInputHigh(const char * type) : NodeInput(type) { }
-// NodeInputHigh::NodeInputHigh(const NodeInputHigh * prototype) : NodeInput() { }
diff --git a/NodeInput.h b/NodeInput.h
index 23a5e14..7ec296b 100644
--- a/NodeInput.h
+++ b/NodeInput.h
@@ -2,45 +2,36 @@
#include "Node.h"
+#include "prut.h"
+
class NodeInput : public Node {
public:
- NodeInput() = default;
+ using Node::Node;
NodeInput(const NodeInput * prototype);
- ~NodeInput() = default;
- virtual void sim();
- SignalLevel level();
+
virtual NodeInput * clone() const;
protected:
- NodeInput(const char * type);
-
-private:
- SignalLevel input = UNDEFINED;
+ virtual SignalLevel level();
};
-// Input LOW and HIGH unicorns:
-
class NodeInputLow : public NodeInput {
- using NodeInput::NodeInput;
-
public:
- // NodeInputLow(const NodeInputLow * prototype);
- // ~NodeInputLow() = default;
- // virtual void compare();
- // virtual NodeInputLow * clone() const;
+ using NodeInput::NodeInput;
+ virtual SignalLevel level();
private:
constexpr static const char * type = "input_low";
static NodeInputLow instance;
-
- SignalLevel input = LOW;
};
class NodeInputHigh : public NodeInput {
-private:
+public:
using NodeInput::NodeInput;
+ virtual SignalLevel level();
+
+private:
constexpr static const char * type = "input_high";
static NodeInputHigh instance;
-
- SignalLevel input = HIGH;
};
+
diff --git a/main.cpp b/main.cpp
index e2721b1..0e73d6f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,6 +4,8 @@
#include "Parser.h"
#include "Circuit.h"
+#include "prut.h"
+
using std::cout;
using std::endl;
using std::ifstream;
@@ -23,6 +25,7 @@ int main(int argc, char** argv) {
cout << "Parser error: " << e.what() << endl;
return EXIT_FAILURE;
}
+ prutprint("parsing done!");
try {
circuit.sim();