aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Circuit.cpp3
-rw-r--r--GateAnd.h2
-rw-r--r--Net.cpp1
-rw-r--r--Node.h2
-rw-r--r--NodeInput.cpp18
-rw-r--r--NodeInput.h49
6 files changed, 23 insertions, 52 deletions
diff --git a/Circuit.cpp b/Circuit.cpp
index d6a5375..62dfae4 100644
--- a/Circuit.cpp
+++ b/Circuit.cpp
@@ -43,9 +43,8 @@ void Circuit::new_net(string src, vector<string> dests) {
}
void Circuit::sim() {
- for (auto & node : nodes) {
+ for (auto & node : nodes)
node.second->sim();
- }
}
Node * Circuit::find_node(string label) {
diff --git a/GateAnd.h b/GateAnd.h
index 5de827c..2991c1d 100644
--- a/GateAnd.h
+++ b/GateAnd.h
@@ -5,7 +5,6 @@
class GateAnd : public Node {
public:
GateAnd() = default;
- GateAnd(const GateAnd * prototype);
~GateAnd() = default;
virtual GateAnd * clone() const;
@@ -17,6 +16,7 @@ protected:
using Node::Node;
private:
+ GateAnd(const GateAnd * prototype);
constexpr static const char * type = "and";
static GateAnd instance;
};
diff --git a/Net.cpp b/Net.cpp
index 9797796..e423c66 100644
--- a/Net.cpp
+++ b/Net.cpp
@@ -4,6 +4,7 @@
#include "prut.h"
void Net::setLevel(SignalLevel level){
+ // if (this->level == level) return;
this->level = level;
this->notify();
}
diff --git a/Node.h b/Node.h
index 59affcf..110928b 100644
--- a/Node.h
+++ b/Node.h
@@ -31,7 +31,7 @@ protected:
vector<Net *> inputs;
Net * output = nullptr;
-private:
+protected:
int min_inputs = -1;
int max_inputs = -1;
};
diff --git a/NodeInput.cpp b/NodeInput.cpp
index 2fae505..6ee0db4 100644
--- a/NodeInput.cpp
+++ b/NodeInput.cpp
@@ -1,25 +1,25 @@
#include "NodeInput.h"
#include "prut.h"
-
-NodeInput NodeInput::instance(NodeInput::type);
NodeInputLow NodeInputLow::instance(NodeInputLow::type);
NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type);
-NodeInput::NodeInput(const NodeInput * prototype) : Node() { }
-
-NodeInput * NodeInput::clone() const {
- return new NodeInput(this);
+NodeInput::NodeInput() {
+ this->max_inputs = -1;
+ this->max_inputs = 0;
}
-SignalLevel NodeInput::level() {
- prutprint("BaseInput");
- return UNDEFINED;
+NodeInputLow * NodeInputLow::clone() const {
+ return new NodeInputLow(this);
}
SignalLevel NodeInputLow::level() {
prutprint("LOW");
return LOW;
}
+
+NodeInputHigh * NodeInputHigh::clone() const {
+ return new NodeInputHigh(this);
+}
SignalLevel NodeInputHigh::level() {
prutprint("HIGH");
return HIGH;
diff --git a/NodeInput.h b/NodeInput.h
index 5c13133..f277130 100644
--- a/NodeInput.h
+++ b/NodeInput.h
@@ -6,66 +6,37 @@
class NodeInput : public Node {
public:
- NodeInput() = default;
- NodeInput(const NodeInput * prototype);
+ NodeInput();
~NodeInput() = default;
- virtual NodeInput * clone() const;
protected:
- SignalLevel level();
-
-private:
- using Node::Node;
- constexpr static const char * type = "input";
- static NodeInput instance;
-
-private:
- int min_inputs = -1;
- int max_inputs = 0;
+ NodeInput(const char * type) : Node(type) {}
};
-// 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 {
protected:
SignalLevel level();
+ NodeInputLow(const char * type) : NodeInput(type) {}
+ NodeInputLow * clone() const;
private:
+ NodeInputLow(const NodeInputLow *) : NodeInput() {}
using NodeInput::NodeInput;
constexpr static const char * type = "input_low";
static NodeInputLow instance;
};
class NodeInputHigh : public NodeInput {
+protected:
+ NodeInputHigh(const char * type) : NodeInput(type) {}
+
private:
SignalLevel level();
+ NodeInputHigh(const NodeInputHigh *) : NodeInput() {}
+ NodeInputHigh * clone() const;
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;
-// };
-