aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2024-05-29 11:31:34 +0200
committerUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2024-05-29 11:31:34 +0200
commit22b97d969cdff46a06a48a5bce7d183c4a877fb5 (patch)
treeb6134d1afddbd20f7b4f4a731956271e5aa1e422
parentd062ae0e598ddc38b1e683a2f5169a0f48e5611e (diff)
inital classes
-rw-r--r--.gitignore1
-rw-r--r--Net.cpp12
-rw-r--r--Net.h17
-rw-r--r--Node.cpp10
-rw-r--r--Node.h23
-rw-r--r--Observer.cpp19
-rw-r--r--Observer.h31
-rw-r--r--main.cpp9
-rw-r--r--makefile25
9 files changed, 142 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 87e54c2..4ce588c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
main
*.o
+.vscode
diff --git a/Net.cpp b/Net.cpp
new file mode 100644
index 0000000..9ee86e7
--- /dev/null
+++ b/Net.cpp
@@ -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;
+}
diff --git a/Net.h b/Net.h
new file mode 100644
index 0000000..bf93377
--- /dev/null
+++ b/Net.h
@@ -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*){
+
+}
diff --git a/Node.h b/Node.h
new file mode 100644
index 0000000..70a580c
--- /dev/null
+++ b/Node.h
@@ -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();
+ // }
+};
+
+
+
+
diff --git a/main.cpp b/main.cpp
index e548bf8..d7709e2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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;
}
diff --git a/makefile b/makefile
index 14da6dc..3b8b5d6 100644
--- a/makefile
+++ b/makefile
@@ -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
-