From efd4e8fdf579ff6ba2e84cb623adc1a1accbb293 Mon Sep 17 00:00:00 2001 From: portnoytmy Date: Mon, 16 Jun 2025 23:47:53 +0200 Subject: [PATCH] added task-class --- .gitignore | 30 ++++++++++++++++++++++++++++++ CMakeLists.txt | 25 +++++++++++++++++++++++++ einlesen.cpp | 32 +++++++++++++++----------------- task.cpp | 15 +++++++++++++++ task.h | 28 ++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 task.cpp create mode 100644 task.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80ccb77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Build-Verzeichnisse +build/ +bin/ +lib/ + +# CMake-Dateien +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +Makefile + +# Compiled Object files +*.o +*.obj + +# Shared objects +*.so +*.dylib +*.dll + +# Executables +*.exe +*.out +*.app + +# IDE-spezifische Dateien +.vscode/ +.idea/ +*.swp +*~ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0233e40 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) +project(BS_Praktikum5 VERSION 0.1.0 LANGUAGES CXX) + +# Compiler-Optionen +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Warnungen und Debug-Informationen bei Entwicklung aktivieren +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -g") +endif() + +# Aktuelles Verzeichnis als Include-Pfad hinzufügen +include_directories(.) + +# Quellen sammeln +file(GLOB SOURCES *.cpp) +file(GLOB HEADERS *.h *.hpp) + +# Ausführbare Datei erstellen +add_executable(${PROJECT_NAME} ${SOURCES}) + +# Installation konfigurieren +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/einlesen.cpp b/einlesen.cpp index c219a30..9487db0 100644 --- a/einlesen.cpp +++ b/einlesen.cpp @@ -1,26 +1,24 @@ -#include -#include -#include -#include -#include -#include +#include "task.h" +#include -std::vector > readFile(const std::string &filename) { - std::vector > instructions; - std::ifstream file(filename); +using namespace std; + +vector > readFile(const string &filename) { + vector > instructions; + ifstream file(filename); if(!file.is_open()) { - std::cerr << "Fehler: Datei " << filename << " konnte nicht geöffnet werden.\n"; + cerr << "Fehler: Datei " << filename << " konnte nicht geöffnet werden.\n"; return instructions; } - std::string line; - while (std::getline(file, line)) { + string line; + while (getline(file, line)) { // Entferne führende oder trailing Whitespace if (line.empty()) continue; - std::istringstream iss(line); - std::string command; - std::string param; + istringstream iss(line); + string command; + string param; if (!(iss >> command)) { // Keine gültige Eingabe in dieser Zeile @@ -33,7 +31,7 @@ std::vector > readFile(const std::string &fi param = ""; } - instructions.push_back(std::make_pair(command, param)); + instructions.push_back(make_pair(command, param)); } return instructions; @@ -43,7 +41,7 @@ std::vector > readFile(const std::string &fi int main() { auto result = readFile("init"); for (const auto &inst : result) { - std::cout << "Befehl: " << inst.first << " | Parameter: " << inst.second << "\n"; + cout << "Befehl: " << inst.first << " | Parameter: " << inst.second << "\n"; } return 0; diff --git a/task.cpp b/task.cpp new file mode 100644 index 0000000..222621f --- /dev/null +++ b/task.cpp @@ -0,0 +1,15 @@ +#include + +Task::Task(int pid, + const std::string &name, + const std::vector> &program) +{ + this->pid=pid; + this->name=name; + this->program=program; + this->pc=0; + this->acc=0; + this->blockTicks=0; + this->active=true; +} + diff --git a/task.h b/task.h new file mode 100644 index 0000000..b0f775e --- /dev/null +++ b/task.h @@ -0,0 +1,28 @@ +#ifndef TASK_H +#define TASK_H + +#include +#include +#include +#include +#include +#include +#include + +class Task +{ +public: + Task()=delete; + Task(int pid, const std::string &name, const std::vector> &program); +private: + int pid, + pc, + acc, + blockTicks; + std::string name; + std::vector> program; + bool active; +}; + + +#endif //TASK_H