Commit 9f002cd5 authored by Mario Bajer's avatar Mario Bajer
Browse files

code review + projektabgabe notes

parent 7feec40d
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
std::mutex m; std::mutex m;
void Matrix::print(std::ostream& a_r0s){ void Matrix::print(std::ostream& a_r0s){ // refactor auf z.B: "renderHTML"
for(int i = 0; i < this->dimx; i++){ for(int i = 0; i < this->dimx; i++){
a_r0s << "<p>"; a_r0s << "<p>";
for(int j = 0; j < this->dimy; j++){ for(int j = 0; j < this->dimy; j++){
...@@ -18,8 +18,8 @@ void Matrix::print(std::ostream& a_r0s){ ...@@ -18,8 +18,8 @@ void Matrix::print(std::ostream& a_r0s){
} }
void Matrix::fillRND() { void Matrix::fillRND() {
std::mt19937 engine(std::random_device{}()); static std::mt19937 engine(std::random_device{}()); //static damit nicht bei jedem call neues obj erstellt wird
std::uniform_int_distribution<uint64_t> distribution; static std::uniform_int_distribution<uint64_t> distribution;
for(int i = 0; i < datasize; i++){ for(int i = 0; i < datasize; i++){
data[i] = distribution(engine); data[i] = distribution(engine);
} }
...@@ -34,7 +34,7 @@ int Matrix::generateID() { ...@@ -34,7 +34,7 @@ int Matrix::generateID() {
json jcreate; json jcreate;
jcreate["counter"] = 0; jcreate["counter"] = 0;
ofstream ocreate; ofstream ocreate;
ocreate.open(configloc); ocreate.open(configloc); //abfangen obs auch wirklich aufgegangen is!
ocreate << jcreate << endl; ocreate << jcreate << endl;
ocreate.close(); ocreate.close();
cout << "<p> config.json did not exist. Created config.json with counter 0" << endl; cout << "<p> config.json did not exist. Created config.json with counter 0" << endl;
...@@ -54,7 +54,7 @@ int Matrix::generateID() { ...@@ -54,7 +54,7 @@ int Matrix::generateID() {
return ID; return ID;
} }
int Matrix::saveMatrix(){ int Matrix::saveMatrix(){ // sollte mit parameter "folderpath" aufgerufen werden oder geöffnetem stream von außen
ID = generateID(); ID = generateID();
string folderpath = "Json/"; string folderpath = "Json/";
...@@ -63,7 +63,7 @@ int Matrix::saveMatrix(){ ...@@ -63,7 +63,7 @@ int Matrix::saveMatrix(){
ofstream o; ofstream o;
o.open(folderpath); o.open(folderpath);
o << ID << "," << dimx << "," << dimy << "," << endl; o << ID << "," << dimx << "," << dimy << "," << endl;
o.seekp(50, std::ofstream::beg); o.seekp(50, std::ofstream::beg); // trennung durch newline
for(int i = 0; i < datasize; i++){ for(int i = 0; i < datasize; i++){
unsigned char val[sizeof(uint64_t)]; unsigned char val[sizeof(uint64_t)];
memcpy(val, &data[i], sizeof(uint64_t)); memcpy(val, &data[i], sizeof(uint64_t));
...@@ -93,7 +93,7 @@ void Matrix::getmatrixfromfile( const string& path) { ...@@ -93,7 +93,7 @@ void Matrix::getmatrixfromfile( const string& path) {
int i = 0; int i = 0;
string param; string param;
vector<string> input; vector<string> input;
while(getline(in, param, ',')){ while(getline(in, param, ',')){ //sollte static funktion sein die genau diese 7 zeilen ausführt
input.push_back(param); input.push_back(param);
i++; i++;
if (i == 3){ if (i == 3){
......
...@@ -51,7 +51,7 @@ int main(){ ...@@ -51,7 +51,7 @@ int main(){
string path = "Json"; string path = "Json";
for(const auto & entry : fs::directory_iterator(path)){ for(const auto & entry : fs::directory_iterator(path)){ // https://github.com/pantor/inja#loops
vector<string> rs = parseHeader(entry.path()); vector<string> rs = parseHeader(entry.path());
cout << "<tr>" << endl; cout << "<tr>" << endl;
cout << "<td>" << rs[0] << "</td>" << endl; cout << "<td>" << rs[0] << "</td>" << endl;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <thread> #include <thread>
#define MAX_THREADS 4 #define MAX_THREADS 4
void callMult(Matrix* a, Matrix* b, Matrix c, size_t from, size_t to){ void callMult(Matrix* a, Matrix* b, Matrix c, size_t from, size_t to){ // c auch als ref!
c.threadedmult(a,b,from,to); c.threadedmult(a,b,from,to);
} }
...@@ -55,7 +55,7 @@ int main(){ ...@@ -55,7 +55,7 @@ int main(){
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
if(stoi(matrixA[2]) >= (2 * MAX_THREADS)) { if(stoi(matrixA[2]) >= (2 * MAX_THREADS)) {
for (size_t i = 0; i < MAX_THREADS; i++) { for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i] = thread(callMult, &a, &b, c, (i * tsize), (i * tsize) + tsize - 1); matrixthread[i] = thread(callMult, &a, &b, c, (i * tsize), (i * tsize) + tsize - 1); // c als ref
} }
for (size_t i = 0; i < MAX_THREADS; i++) { for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i].join(); matrixthread[i].join();
......
#include "notmatrix.hpp" #include "notmatrix.hpp"
bool existsm(const string& filename){ bool existsm(const string& filename){ // https://en.cppreference.com/w/cpp/filesystem/exists
ifstream f(filename); ifstream f(filename);
return f.good(); return f.good();
} }
...@@ -16,7 +16,7 @@ void htmlHeader(const string& title){ ...@@ -16,7 +16,7 @@ void htmlHeader(const string& title){
cout << "</head>" << endl; cout << "</head>" << endl;
} }
string parseCgiElement(Cgicc formData, const string& elementName){ string parseCgiElement(Cgicc formData, const string& elementName){ // const Cgicc& für ref
auto fi = formData.getElement(elementName); auto fi = formData.getElement(elementName);
if( !fi->isEmpty() && fi != (*formData).end()) { if( !fi->isEmpty() && fi != (*formData).end()) {
return **fi; return **fi;
...@@ -28,7 +28,7 @@ string parseCgiElement(Cgicc formData, const string& elementName){ ...@@ -28,7 +28,7 @@ string parseCgiElement(Cgicc formData, const string& elementName){
} }
} }
vector<string> parseHeader(filesystem::path filepath){ vector<string> parseHeader(filesystem::path filepath){ // const path& // in matrix Klasse verschieben (ist keine util)
ifstream inFile(filepath); ifstream inFile(filepath);
int i = 0; int i = 0;
string param; string param;
......
...@@ -38,7 +38,7 @@ string parseCgiElement(Cgicc formData, const string& elementName); ...@@ -38,7 +38,7 @@ string parseCgiElement(Cgicc formData, const string& elementName);
/** @brief Trennt die Header Parameter von den Daten ab und gibt diese als string zurück. /** @brief Trennt die Header Parameter von den Daten ab und gibt diese als string zurück.
* *
* Die Daten werden in folgendem Format gespeichert. * Die Daten werden in folgendem Format gespeichert.
* id:{id},dimx:{dimx},dimy:{dimy}\n * {id},{dimx},{dimy}\n
* {data} * {data}
* Es wird die erste Zeile übergeben und alle per ',' werden nacheinander in den vector gepushed. * Es wird die erste Zeile übergeben und alle per ',' werden nacheinander in den vector gepushed.
* *
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "Matrix.hpp" #include "Matrix.hpp"
#include "notmatrix.hpp" #include "notmatrix.hpp"
int main(){ int main(){ // idee: schwarz/weiß pixel zur darstellung von matrixelementen mit https://www.w3schools.com/html/html5_canvas.asp
Cgicc formData; Cgicc formData;
htmlHeader("show.cgi"); htmlHeader("show.cgi");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment