aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GateAnd.cpp2
-rw-r--r--GateAnd.h2
-rw-r--r--Net.cpp7
-rw-r--r--Node.cpp3
-rw-r--r--NodeInput.cpp17
-rw-r--r--NodeInput.h18
-rw-r--r--NodeOutput.cpp4
-rw-r--r--Observer.cpp7
-rw-r--r--Observer.h8
-rw-r--r--docs/class-diag.puml4
-rw-r--r--main.cpp26
-rw-r--r--makefile2
-rw-r--r--prut.h6
13 files changed, 46 insertions, 60 deletions
diff --git a/GateAnd.cpp b/GateAnd.cpp
index c48d19c..e51df30 100644
--- a/GateAnd.cpp
+++ b/GateAnd.cpp
@@ -2,8 +2,6 @@
GateAnd GateAnd::instance(GateAnd::type);
-GateAnd::GateAnd(const char * type) : Node(type) { }
-
SignalLevel GateAnd::level() {
for (int i = 0; i < this->inputs.size(); i++){
SignalLevel l = this->inputs[i]->getLevel();
diff --git a/GateAnd.h b/GateAnd.h
index a8cc3d0..f3ba3a7 100644
--- a/GateAnd.h
+++ b/GateAnd.h
@@ -12,7 +12,7 @@ public:
private:
SignalLevel level();
- GateAnd(const char * type);
+ using Node::Node;
constexpr static const char * type = "and";
static GateAnd instance;
};
diff --git a/Net.cpp b/Net.cpp
index 249b6bb..801210b 100644
--- a/Net.cpp
+++ b/Net.cpp
@@ -1,9 +1,14 @@
#include "Net.h"
#include <iostream>
+#include "prut.h"
+
void Net::setLevel(SignalLevel level){
this->level = level;
- std::cout << this->size() << std::endl;
+ // std::cout << this->size() << std::endl;
+ prutprintf("%u", this->size());
+
+
this->notify();
}
diff --git a/Node.cpp b/Node.cpp
index 4ba3961..3a9f6f3 100644
--- a/Node.cpp
+++ b/Node.cpp
@@ -4,6 +4,8 @@
#include "NodeFactory.h"
#include "Net.h"
+#include "prut.h"
+
Node::Node(const char * type) {
NodeFactory::assign(type, this);
}
@@ -33,6 +35,7 @@ void Node::sim() {
}
void Node::update(){
+ prutprint("updated");
this->sim();
}
diff --git a/NodeInput.cpp b/NodeInput.cpp
index 0fc8110..fafbd3b 100644
--- a/NodeInput.cpp
+++ b/NodeInput.cpp
@@ -2,12 +2,15 @@
#include <iostream>
-NodeInput::NodeInput(const char * type) : Node(type) { }
+NodeInputLow NodeInputLow::instance(NodeInputLow::type);
+NodeInputHigh NodeInputHigh::instance(NodeInputHigh::type);
-void NodeInput::sim() {
- if (this->output == nullptr) return;
+NodeInput::NodeInput(const char * type) : Node(type) { };
- this->output->setLevel(this->input);
+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() { }
@@ -16,9 +19,9 @@ NodeInput * NodeInput::clone() const {
return new NodeInput(this);
}
-// INPUT_LOW
-NodeInputLow NodeInputLow::instance(NodeInputLow::type);
-NodeInputLow::NodeInputLow(const char * type) : NodeInput() { }
+SignalLevel NodeInput::level() {
+ return UNDEFINED;
+};
// NodeInputLow::NodeInputLow(const NodeInputLow * prototype) : NodeInput() { }
diff --git a/NodeInput.h b/NodeInput.h
index 71cf36c..23a5e14 100644
--- a/NodeInput.h
+++ b/NodeInput.h
@@ -4,22 +4,25 @@
class NodeInput : public Node {
public:
- NodeInput() = default;
+ NodeInput() = default;
NodeInput(const NodeInput * prototype);
~NodeInput() = default;
virtual void sim();
- SignalLevel level() { return UNDEFINED; };
+ SignalLevel level();
virtual NodeInput * clone() const;
-private:
+protected:
NodeInput(const char * type);
-SignalLevel input = UNDEFINED;
+private:
+ SignalLevel input = UNDEFINED;
};
// Input LOW and HIGH unicorns:
class NodeInputLow : public NodeInput {
+ using NodeInput::NodeInput;
+
public:
// NodeInputLow(const NodeInputLow * prototype);
// ~NodeInputLow() = default;
@@ -27,18 +30,17 @@ public:
// virtual NodeInputLow * clone() const;
private:
- NodeInputLow(const char * type);
constexpr static const char * type = "input_low";
static NodeInputLow instance;
- SignalLevel input = LOW;
+ SignalLevel input = LOW;
};
class NodeInputHigh : public NodeInput {
private:
- NodeInputHigh(const char * type);
+ using NodeInput::NodeInput;
constexpr static const char * type = "input_high";
static NodeInputHigh instance;
- SignalLevel input = HIGH;
+ SignalLevel input = HIGH;
};
diff --git a/NodeOutput.cpp b/NodeOutput.cpp
index 5138805..a02ba1f 100644
--- a/NodeOutput.cpp
+++ b/NodeOutput.cpp
@@ -1,7 +1,7 @@
#include "NodeOutput.h"
#include "Exception.h"
-#include <iostream>
+#include "prut.h"
NodeOutput NodeOutput::instance(NodeOutput::type);
@@ -11,7 +11,7 @@ void NodeOutput::sim() {
if (this->inputs.size() == 0)
throw CircuitException("No inputs on probe");
- std::cout << "Probe signal level: " << this->inputs[0]->getLevel() << std::endl;
+ prutprintf("level: %u", this->inputs[0]->getLevel());
}
NodeOutput::NodeOutput(const NodeOutput * prototype) : Node() { }
diff --git a/Observer.cpp b/Observer.cpp
index 7d5dc22..39a8245 100644
--- a/Observer.cpp
+++ b/Observer.cpp
@@ -3,6 +3,7 @@
#include "Observer.h"
void Subject::attach(Observer * obs){
+ // std::cout << "added" << std::endl;
this->observers.push_back(obs);
}
@@ -11,12 +12,12 @@ void Subject::detach(Observer *){
}
int Subject::size() {
+ // std::cout << "subject list size " << this->observers.size() << std::endl;
return this->observers.size();
}
-// TODO possibly add foo input as update value?
void Subject::notify() {
- for (int i = 0; i < this->observers.size(); i++)
- this->observers[i]->update();
+ for (auto observer : this->observers)
+ observer->update();
}
diff --git a/Observer.h b/Observer.h
index 0661bf0..20ca887 100644
--- a/Observer.h
+++ b/Observer.h
@@ -2,11 +2,8 @@
#include <vector>
class Observer {
-private:
-
public:
virtual void update() = 0;
-
};
class Subject {
@@ -18,11 +15,6 @@ public:
virtual void detach(Observer*);
virtual int size();
- // TODO possibly add foo input as update value?
virtual void notify();
- // virtual void notify() {
- // for (int i = 0; i < observers.size(); i++)
- // observers.at(i)->update();
- // }
};
diff --git a/docs/class-diag.puml b/docs/class-diag.puml
index 4d9f489..971de54 100644
--- a/docs/class-diag.puml
+++ b/docs/class-diag.puml
@@ -61,8 +61,8 @@ Net -- SignalLevel
Node -- SignalLevel
Node <|-[dashed]-- GateAnd
-Node <|-[dashed]-- GateNand
-Node <|-[dashed]-- GateNor
+GateAnd <|-- GateNand
+GateOr <|-- GateNor
Node <|-[dashed]-- GateNot
Node <|-[dashed]-- GateOr
Node <|-[dashed]-- GateXor
diff --git a/main.cpp b/main.cpp
index 032a812..e2721b1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,31 +8,6 @@ using std::cout;
using std::endl;
using std::ifstream;
-#include "Node.h"
-#include "GateAnd.h"
-
-int main() {
- // Observer ob();
- Net n, n1, o;
- Node *g = new GateAnd;
- try {
- g->addInput(&n);
- g->addInput(&n1);
- g->setOutput(&o);
-
- // o.setLevel(UNDEFINED);
- n.setLevel(HIGH);
- n1.setLevel(HIGH);
- int level = 22;
- level = o.getLevel();
- printf("hello world! %d\n", level);
- } catch(Exception& e) {
- std::cerr << e.what() << '\n';
- }
- return 0;
-}
-
-/*
int main(int argc, char** argv) {
Parser main_parser;
Circuit circuit;
@@ -61,4 +36,3 @@ int main(int argc, char** argv) {
return EXIT_SUCCESS;
}
-*/ \ No newline at end of file
diff --git a/makefile b/makefile
index 509e1e8..cbdba7f 100644
--- a/makefile
+++ b/makefile
@@ -20,3 +20,5 @@ clean:
compile_commands.json:
compiledb make -Bn
+
+_Bj: ; $(MAKE) -C . -Bj
diff --git a/prut.h b/prut.h
new file mode 100644
index 0000000..a41c01c
--- /dev/null
+++ b/prut.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#define prutprintf(fmt, ...) printf("\x1b[37m%s (%s:%d):\x1b[0m " fmt "\n", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__, __VA_ARGS__)
+
+#define prutprint(s) prutprintf("%s", s)
+