Commit 8e26685c authored by Mario Bajer's avatar Mario Bajer
Browse files

cleanup

parent db8a6887
......@@ -4,3 +4,8 @@ project(ese_zeitlhofer_bajer)
set(CMAKE_CXX_STANDARD 20)
include_directories(E:/IT/Tools/)
add_executable(matrix
show.cpp
Matrix.cpp
Matrix.hpp)
\ No newline at end of file
//
// Created by Mario on 05/05/2020.
//
#include "Matrix.hpp"
bool exists_m (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
void Matrix::printtocnsl(Matrix matrix){
// cout << "<p>";
for (int i = 0; i < dim; i++) {
cout << "<p>";
for (int j = 0; j < dim; j++)
cout << matrix(i,j) << " ";
cout << "</p>";
}
// cout << "</p>";
}
void Matrix::generate(int dimg) {
srand(time(NULL));
Matrix matrix;
matrix.data = new int[dimg * dimg];
matrix.dim = dimg;
for (int i = 0; i < dimg * dimg; i++)
matrix.data[i] = rand() % 10;
matrix.ID = rand() % 100;
while(exists_m(to_string(matrix.ID)+".json")){
matrix.ID = rand() % 100;
}
json j;
j["id"] = matrix.ID;
j["dim"] = matrix.dim;
vector<int> vector1(matrix.data, matrix.data + (matrix.dim * matrix.dim));
j["data"] = vector1;
ofstream outFileGen;
outFileGen.open(to_string(matrix.ID)+".json");
outFileGen << j << endl;
outFileGen.close();
cout << "File generiert\n";
}
//
// Created by Mario on 05/05/2020.
//
#ifndef ESE_ZEITLHOFER_BAJER_MATRIX_H
#define ESE_ZEITLHOFER_BAJER_MATRIX_H
#include <iostream>
#include <filesystem>
#include <fstream>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
#include <json.hpp>
using namespace std;
using namespace cgicc;
using json = nlohmann::json;
class Matrix {
public:
int ID;
int dim;
int *data;
void generate(int dim);
void printtocnsl(Matrix matrix);
inline int &operator()(unsigned row, unsigned col) {
return data[dim * row + col];
}
inline int operator()(unsigned row, unsigned col) const {
return data[dim * row + col];
}
private:
};
#endif //ESE_ZEITLHOFER_BAJER_MATRIX_H
CC=g++
CFLAGS=-Wall -std=c++17
LDLIBS=-lcgicc
all: show
show:
$(CC) $(CFLAGS) show.cpp Matrix.cpp $(LDLIBS) -o /mnt/e/IT/Tools/xampp/cgi-bin/show.cgi
clean:
rm -f /mnt/e/IT/Tools/xampp/cgi-bin/*.cgi
\ No newline at end of file
#include "Matrix.hpp"
int main(){
Matrix matrix;
Cgicc formContent;
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>show.cgi</title>\n";
cout << "</head>\n";
cout << "<body>\n";
matrix.generate(10);
cout << "after generate\n";
string folderpath = "";
form_iterator fi = formContent.getElement("ID");
if( !fi->isEmpty() && fi != (*formContent).end()) {
folderpath = **fi;
}
else {
cout << "Error!" << endl;
}
json j;
ifstream inFile("48.json");
inFile >> j;
matrix.ID = j["id"];
matrix.dim = j["dim"];
vector<int> vector2 = j["data"];
matrix.data = &vector2[0];
matrix.printtocnsl(matrix);
cout << "<a href=\"http://localhost:80/index.html\">Back to Start</a>";
cout << "</body>\n";
cout << "</html>\n";
return 0;
}
\ No newline at end of file
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