added task-class
This commit is contained in:
parent
469ad9bb65
commit
efd4e8fdf5
5 changed files with 113 additions and 17 deletions
30
.gitignore
vendored
Normal file
30
.gitignore
vendored
Normal file
|
|
@ -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
|
||||||
|
*~
|
||||||
25
CMakeLists.txt
Normal file
25
CMakeLists.txt
Normal file
|
|
@ -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)
|
||||||
32
einlesen.cpp
32
einlesen.cpp
|
|
@ -1,26 +1,24 @@
|
||||||
#include <iostream>
|
#include "task.h"
|
||||||
#include <fstream>
|
#include <deque>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <utility>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string> > readFile(const std::string &filename) {
|
using namespace std;
|
||||||
std::vector<std::pair<std::string, std::string> > instructions;
|
|
||||||
std::ifstream file(filename);
|
vector<pair<string, string> > readFile(const string &filename) {
|
||||||
|
vector<pair<string, string> > instructions;
|
||||||
|
ifstream file(filename);
|
||||||
if(!file.is_open()) {
|
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;
|
return instructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string line;
|
string line;
|
||||||
while (std::getline(file, line)) {
|
while (getline(file, line)) {
|
||||||
// Entferne führende oder trailing Whitespace
|
// Entferne führende oder trailing Whitespace
|
||||||
if (line.empty()) continue;
|
if (line.empty()) continue;
|
||||||
|
|
||||||
std::istringstream iss(line);
|
istringstream iss(line);
|
||||||
std::string command;
|
string command;
|
||||||
std::string param;
|
string param;
|
||||||
|
|
||||||
if (!(iss >> command)) {
|
if (!(iss >> command)) {
|
||||||
// Keine gültige Eingabe in dieser Zeile
|
// Keine gültige Eingabe in dieser Zeile
|
||||||
|
|
@ -33,7 +31,7 @@ std::vector<std::pair<std::string, std::string> > readFile(const std::string &fi
|
||||||
param = "";
|
param = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
instructions.push_back(std::make_pair(command, param));
|
instructions.push_back(make_pair(command, param));
|
||||||
}
|
}
|
||||||
|
|
||||||
return instructions;
|
return instructions;
|
||||||
|
|
@ -43,7 +41,7 @@ std::vector<std::pair<std::string, std::string> > readFile(const std::string &fi
|
||||||
int main() {
|
int main() {
|
||||||
auto result = readFile("init");
|
auto result = readFile("init");
|
||||||
for (const auto &inst : result) {
|
for (const auto &inst : result) {
|
||||||
std::cout << "Befehl: " << inst.first << " | Parameter: " << inst.second << "\n";
|
cout << "Befehl: " << inst.first << " | Parameter: " << inst.second << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
15
task.cpp
Normal file
15
task.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include <task.h>
|
||||||
|
|
||||||
|
Task::Task(int pid,
|
||||||
|
const std::string &name,
|
||||||
|
const std::vector<std::pair<std::string, std::string>> &program)
|
||||||
|
{
|
||||||
|
this->pid=pid;
|
||||||
|
this->name=name;
|
||||||
|
this->program=program;
|
||||||
|
this->pc=0;
|
||||||
|
this->acc=0;
|
||||||
|
this->blockTicks=0;
|
||||||
|
this->active=true;
|
||||||
|
}
|
||||||
|
|
||||||
28
task.h
Normal file
28
task.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef TASK_H
|
||||||
|
#define TASK_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
class Task
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Task()=delete;
|
||||||
|
Task(int pid, const std::string &name, const std::vector<std::pair<std::string, std::string>> &program);
|
||||||
|
private:
|
||||||
|
int pid,
|
||||||
|
pc,
|
||||||
|
acc,
|
||||||
|
blockTicks;
|
||||||
|
std::string name;
|
||||||
|
std::vector<std::pair<std::string, std::string>> program;
|
||||||
|
bool active;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //TASK_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue