aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2024-06-12 20:07:31 +0200
committerUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2024-06-12 20:07:31 +0200
commit7b101df2d5742773058ae0a2fbc2d172beae7291 (patch)
treee942d09c5b0a39ce8e454ce40506e54b2fd137d7
parentf1de485461b4cbb5dda4705323b416abec39b574 (diff)
WIP
-rw-r--r--Node.cpp6
-rw-r--r--Node.h2
-rw-r--r--NodeInput.cpp10
-rw-r--r--NodeInput.h54
-rw-r--r--readme.md22
5 files changed, 65 insertions, 29 deletions
diff --git a/Node.cpp b/Node.cpp
index 092d05d..a65a636 100644
--- a/Node.cpp
+++ b/Node.cpp
@@ -16,7 +16,11 @@ void Node::addInput(Net * net) {
}
void Node::setOutput(Net * net){
- this->output = net;
+ if (this->output == nullptr) {
+ this->output = net;
+ } else {
+ throw CircuitException("Net already assigned");
+ }
}
void Node::sim() {
diff --git a/Node.h b/Node.h
index 3496851..59affcf 100644
--- a/Node.h
+++ b/Node.h
@@ -29,7 +29,7 @@ protected:
string label;
vector<Net *> inputs;
- Net * output;
+ Net * output = nullptr;
private:
int min_inputs = -1;
diff --git a/NodeInput.cpp b/NodeInput.cpp
index 2d1d517..ea328e3 100644
--- a/NodeInput.cpp
+++ b/NodeInput.cpp
@@ -1,8 +1,8 @@
#include "NodeInput.h"
#include "prut.h"
-#include <iostream>
+NodeInput NodeInput::instance(NodeInput::type);
NodeInputLow NodeInputLow::instance(NodeInputLow::type);
NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type);
@@ -13,15 +13,15 @@ NodeInput * NodeInput::clone() const {
}
SignalLevel NodeInput::level() {
- prutprint("");
- return UNDEFINED;
+ prutprint("BaseInput");
+ return HIGH;
}
SignalLevel NodeInputLow::level() {
- prutprint("");
+ prutprint("LOW");
return LOW;
}
SignalLevel NodeInputHigh::level() {
- prutprint("");
+ prutprint("HIGH");
return HIGH;
}
diff --git a/NodeInput.h b/NodeInput.h
index e176fa7..5c13133 100644
--- a/NodeInput.h
+++ b/NodeInput.h
@@ -6,34 +6,66 @@
class NodeInput : public Node {
public:
- using Node::Node;
+ NodeInput() = default;
NodeInput(const NodeInput * prototype);
-
+ ~NodeInput() = default;
virtual NodeInput * clone() const;
+protected:
+ SignalLevel level();
+
private:
- NodeInput(const char * type);
+ using Node::Node;
+ constexpr static const char * type = "input";
+ static NodeInput instance;
- SignalLevel input = UNDEFINED;
+private:
+ int min_inputs = -1;
+ int max_inputs = 0;
};
+// class NodeInput : public Node {
+// public:
+// using Node::Node;
+// NodeInput(const NodeInput * prototype);
+
+// virtual NodeInput * clone() const;
+
+// protected:
+// SignalLevel level() = 0;
+
+// private:
+// NodeInput(const char * type);
+
+// SignalLevel input = UNDEFINED;
+// };
+
class NodeInputLow : public NodeInput {
-public:
- using NodeInput::NodeInput;
- virtual SignalLevel level();
+protected:
+ SignalLevel level();
private:
+ using NodeInput::NodeInput;
constexpr static const char * type = "input_low";
static NodeInputLow instance;
};
class NodeInputHigh : public NodeInput {
-public:
- using NodeInput::NodeInput;
- virtual SignalLevel level();
-
private:
+ SignalLevel level();
+
+ using NodeInput::NodeInput;
constexpr static const char * type = "input_high";
static NodeInputHigh instance;
};
+// class NodeInputHigh : public NodeInput {
+// public:
+// using NodeInput::NodeInput;
+// virtual SignalLevel level();
+
+// private:
+// constexpr static const char * type = "input_high";
+// static NodeInputHigh instance;
+// };
+
diff --git a/readme.md b/readme.md
index 3ae509d..4bf2686 100644
--- a/readme.md
+++ b/readme.md
@@ -17,19 +17,19 @@ make
## TODO
-- [ ] abstract class Node
-- [ ] class CircuitFactory
-- [ ] class GateAnd
-- [ ] class GateNand
-- [ ] class GateNor
+- [x] class Node
+- [x] class CircuitFactory
+- [x] class GateAnd
+- [x] class GateNand
+- [X] class GateNor
- [ ] class GateNot
-- [ ] class GateOr
+- [x] class GateOr
- [ ] class GateXor
-- [ ] class Net
+- [x] class Net
- [ ] class NodeInput
- [ ] class NodeOutput
-- [ ] class Parser
-- [ ] class Subject
-- [ ] enum SignalLevel
-- [ ] interface Observer
+- [x] class Parser
+- [x] class Subject
+- [x] enum SignalLevel
+- [x] interface Observer