diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2024-05-29 11:31:34 +0200 |
---|---|---|
committer | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2024-05-29 11:31:34 +0200 |
commit | 22b97d969cdff46a06a48a5bce7d183c4a877fb5 (patch) | |
tree | b6134d1afddbd20f7b4f4a731956271e5aa1e422 | |
parent | d062ae0e598ddc38b1e683a2f5169a0f48e5611e (diff) |
inital classes
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Net.cpp | 12 | ||||
-rw-r--r-- | Net.h | 17 | ||||
-rw-r--r-- | Node.cpp | 10 | ||||
-rw-r--r-- | Node.h | 23 | ||||
-rw-r--r-- | Observer.cpp | 19 | ||||
-rw-r--r-- | Observer.h | 31 | ||||
-rw-r--r-- | main.cpp | 9 | ||||
-rw-r--r-- | makefile | 25 |
9 files changed, 142 insertions, 5 deletions
@@ -1,2 +1,3 @@ main *.o +.vscode @@ -0,0 +1,12 @@ +#include "Net.h" + +Net::Net(){} + +Net::~Net(){} + +void Net::setLevel(SignalLevel level){ + this->level = level; +} +SignalLevel Net::getLevel(){ + return this->level; +} @@ -0,0 +1,17 @@ +#pragma once + +#include "Observer.h" + +enum SignalLevel {LOW, HIGH, UNDEFINED}; + +class Net: Subject { + private: + SignalLevel level = UNDEFINED; + public: + Net(/* args */); + ~Net(); + virtual void setLevel(SignalLevel); + virtual SignalLevel getLevel(); +}; + + diff --git a/Node.cpp b/Node.cpp new file mode 100644 index 0000000..7ed1f98 --- /dev/null +++ b/Node.cpp @@ -0,0 +1,10 @@ +#include "Node.h" + +Node::Node(/* args */){} +Node::~Node(){} +void Node::addInput(Net*){ + +} +void Node::addOutput(Net*){ + +} @@ -0,0 +1,23 @@ +#pragma once +#include <string> +#include <vector> + +#include "Observer.h" +#include "Net.h" + + + +class Node: Observer { + private: + std::string label; + std::string type; + + std::vector<Net*> inputs; + std::vector<Net*> outputs; + + public: + Node(/* args */); + ~Node(); + virtual void addInput(Net*); + virtual void addOutput(Net*); +}; diff --git a/Observer.cpp b/Observer.cpp new file mode 100644 index 0000000..adc2f8d --- /dev/null +++ b/Observer.cpp @@ -0,0 +1,19 @@ +#include "Observer.h" +#include <iostream> + +void Observer::update(){ + std::cout << 'a' << std::endl; +} + +void Subject::attach(Observer* obs){ + observers.push_back(obs); +} +void Subject::detach(Observer*){ + +} + +// TODO possibly add foo input as update value? +void Subject::notify() { + for (int i = 0; i < observers.size(); i++) + observers.at(i)->update(); +} diff --git a/Observer.h b/Observer.h new file mode 100644 index 0000000..e6d4f68 --- /dev/null +++ b/Observer.h @@ -0,0 +1,31 @@ +#pragma once +#include <vector> + + +class Observer { + private: + + 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*); + + // 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(); + // } +}; + + + + @@ -1,7 +1,14 @@ #include <cstdio> +// #include "Observer.h" +#include "Net.h" int main(int argc, char** argv) { - printf("hello world!\n"); + // Observer ob(); + Net n; + // n.setLevel(HIGH); + int level = 22; + level = n.getLevel(); + printf("hello world! %d\n", level); return 0; } @@ -1,8 +1,25 @@ -main: main.o +CC = g++ +LD = g++ +RM = rm -f +CFLAGS = -g -std=c++17 +LFLAGS = +TARGET = main \ + Observer \ + Node \ + Net +SRCS := $(wildcard *.cpp) +OBJS := $(patsubst %.cpp,%.o, $(SRCS)) + +all: $(TARGET) + +%.o: %.cpp + $(CC) -c $(CFLAGS) $< -o $@ + +$(TARGET): $(OBJS) + $(LD) $^ $(LFLAGS) -o $@ clean: - git clean -fxdi + $(RM) $(TARGET) $(OBJS) -compile_commands.json: +compile_commands: clean compiledb make -Bn - |