diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-04 14:02:13 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-04 14:02:13 +0200 |
commit | 6bf48a8fc00d76f712797a8f578445893de62791 (patch) | |
tree | 16852d930afa28fb7337f0db52abed063cf93b37 | |
parent | 6ceea7d142619020e6b18aad97e21572cb9dd314 (diff) |
add editorconfig + indent code
-rw-r--r-- | .editorconfig | 11 | ||||
-rw-r--r-- | Net.cpp | 10 | ||||
-rw-r--r-- | Net.h | 14 | ||||
-rw-r--r-- | Node.cpp | 56 | ||||
-rw-r--r-- | Node.h | 35 | ||||
-rw-r--r-- | Observer.cpp | 15 | ||||
-rw-r--r-- | Observer.h | 40 |
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 + @@ -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; } + @@ -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(); }; @@ -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); +// } } @@ -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(); } + @@ -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(); + // } }; - - - |