aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.editorconfig11
-rw-r--r--Net.cpp10
-rw-r--r--Net.h14
-rw-r--r--Node.cpp56
-rw-r--r--Node.h35
-rw-r--r--Observer.cpp15
-rw-r--r--Observer.h40
7 files changed, 93 insertions, 88 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..a3793d2
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+insert_final_newline = true
+
+[*.md]
+indent_style = space
+indent_size = 2
+
diff --git a/Net.cpp b/Net.cpp
index be01152..5b3f5e3 100644
--- a/Net.cpp
+++ b/Net.cpp
@@ -6,10 +6,12 @@ Net::Net(){}
Net::~Net(){}
void Net::setLevel(SignalLevel level){
- this->level = level;
- std::cout << this->size() << std::endl;
- this->notify();
+ this->level = level;
+ std::cout << this->size() << std::endl;
+ this->notify();
}
+
SignalLevel Net::getLevel(){
- return this->level;
+ return this->level;
}
+
diff --git a/Net.h b/Net.h
index 81c8034..150c9b6 100644
--- a/Net.h
+++ b/Net.h
@@ -5,13 +5,13 @@
enum SignalLevel {LOW, HIGH, UNDEFINED};
class Net: public Subject {
- private:
- SignalLevel level = UNDEFINED;
- public:
- Net(/* args */);
- ~Net();
- virtual void setLevel(SignalLevel);
- virtual SignalLevel getLevel();
+private:
+ SignalLevel level = UNDEFINED;
+public:
+ Net(/* args */);
+ ~Net();
+ virtual void setLevel(SignalLevel);
+ virtual SignalLevel getLevel();
};
diff --git a/Node.cpp b/Node.cpp
index d351af1..05ac5d6 100644
--- a/Node.cpp
+++ b/Node.cpp
@@ -5,43 +5,41 @@
Node::Node(){}
Node::~Node(){}
void Node::addInput(Net* net){
- net->attach(this);
+ net->attach(this);
}
void Node::setOutput(Net* net){
- this->output = net;
+ this->output = net;
}
void Node::update(){
- std::cout << "updated" << std::endl;
- this->compare();
+ std::cout << "updated" << std::endl;
+ this->compare();
}
/*/ Concrete Nodes: /*/
void GateAnd::compare(){
- SignalLevel new_out = HIGH;
-
- // TODO fix segfault somewhere below
- // for (int i = 0; i < this->inputs.size(); i++){
- // switch (this->inputs[i]->getLevel()){
- // case LOW:
- // new_out = LOW;
- // break;
- // case HIGH:
- // continue;
- // break;
- // case UNDEFINED:
- // default:
- // new_out = UNDEFINED;
- // exit;
- // break;
- // }
- // }
-
- // if (this->output->getLevel() == new_out){
- // /* do nothing */
- // } else {
- // this->output->setLevel(new_out);
- // }
-
+ SignalLevel new_out = HIGH;
+// TODO fix segfault somewhere below
+// for (int i = 0; i < this->inputs.size(); i++){
+// switch (this->inputs[i]->getLevel()){
+// case LOW:
+// new_out = LOW;
+// break;
+// case HIGH:
+// continue;
+// break;
+// case UNDEFINED:
+// default:
+// new_out = UNDEFINED;
+// exit;
+// break;
+// }
+// }
+
+// if (this->output->getLevel() == new_out){
+// /* do nothing */
+// } else {
+// this->output->setLevel(new_out);
+// }
}
diff --git a/Node.h b/Node.h
index f1845a9..8db9fe9 100644
--- a/Node.h
+++ b/Node.h
@@ -1,32 +1,31 @@
#pragma once
+
#include <string>
#include <vector>
#include "Observer.h"
#include "Net.h"
-
-
class Node: Observer {
- protected:
- std::string label;
- std::string type;
+protected:
+ std::string label;
+ std::string type;
- std::vector<Net*> inputs;
- Net* output;
+ std::vector<Net*> inputs;
+ Net* output;
- public:
- Node(/* args */);
- virtual ~Node();
- void update();
- virtual void addInput(Net*);
- virtual void setOutput(Net*);
- virtual void compare() = 0;
+public:
+ Node(/* args */);
+ virtual ~Node();
+ void update();
+ virtual void addInput(Net*);
+ virtual void setOutput(Net*);
+ virtual void compare() = 0;
};
class GateAnd: public Node {
- public:
- GateAnd(){};
- ~GateAnd(){};
- void compare();
+public:
+ GateAnd(){};
+ ~GateAnd(){};
+ void compare();
};
diff --git a/Observer.cpp b/Observer.cpp
index 1e9c9bb..1d96ed4 100644
--- a/Observer.cpp
+++ b/Observer.cpp
@@ -2,22 +2,21 @@
#include <iostream>
void Observer::update(){
- std::cout << 'a' << std::endl;
+ std::cout << 'a' << std::endl;
}
-
-
void Subject::attach(Observer* obs){
- std::cout << "added" << std::endl;
- this->observers.push_back(obs);
+ std::cout << "added" << std::endl;
+ this->observers.push_back(obs);
}
void Subject::detach(Observer*){
}
-
+
// 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 (int i = 0; i < this->observers.size(); i++)
+ this->observers[i]->update();
}
+
diff --git a/Observer.h b/Observer.h
index 6ff8f3b..7b2db7e 100644
--- a/Observer.h
+++ b/Observer.h
@@ -1,32 +1,28 @@
#pragma once
#include <vector>
-
class Observer {
- private:
+private:
+
+public:
+ virtual void update();
- public:
- virtual void update();
-
};
class Subject {
- private:
- std::vector<Observer*> observers;
- public:
- // virtual void attach(Observer* obs) { observers.push_back(obs);}
- virtual void attach(Observer* obs);
- virtual void detach(Observer*);
- virtual int size() { return this->observers.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();
- // }
+private:
+ std::vector<Observer*> observers;
+public:
+ // virtual void attach(Observer* obs) { observers.push_back(obs);}
+ virtual void attach(Observer* obs);
+ virtual void detach(Observer*);
+ virtual int size() { return this->observers.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();
+ // }
};
-
-
-