Commit a791ab2e authored by Mario Bajer's avatar Mario Bajer
Browse files

cleanup

parent 8e26685c
......@@ -7,5 +7,6 @@ include_directories(E:/IT/Tools/)
add_executable(matrix
show.cpp
generate.cpp
Matrix.cpp
Matrix.hpp)
\ No newline at end of file
......@@ -4,43 +4,43 @@
#include "Matrix.hpp"
bool exists_m (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
bool exists(string filename){
ifstream f(filename);
return f.good();
}
void Matrix::printtocnsl(Matrix matrix){
void Matrix::printtocnsl(){
// cout << "<p>";
for (int i = 0; i < dim; i++) {
for (int i = 0; i < this->dim; i++) {
cout << "<p>";
for (int j = 0; j < dim; j++)
cout << matrix(i,j) << " ";
for (int j = 0; j < this->dim; j++)
cout << (*this)(i,j) << " ";
cout << "</p>";
}
// cout << "</p>";
}
void Matrix::generate(int dimg) {
void Matrix::generate(int dims) {
srand(time(NULL));
Matrix matrix;
matrix.data = new int[dimg * dimg];
matrix.dim = dimg;
// Matrix matrix;
this->dim = dims;
this->data = new int[dims * dims];
for (int i = 0; i < dimg * dimg; i++)
matrix.data[i] = rand() % 10;
for (int i = 0; i < (dims * dims); i++)
this->data[i] = rand() % 10;
matrix.ID = rand() % 100;
while(exists_m(to_string(matrix.ID)+".json")){
matrix.ID = rand() % 100;
this->ID = rand() % 100;
while(exists("Json/" + to_string(this->ID)+".json")){
this->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["id"] = this->ID;
j["dim"] = this->dim;
vector<int> vector1(this->data, this->data + (this->dim * this->dim));
j["data"] = vector1;
ofstream outFileGen;
outFileGen.open(to_string(matrix.ID)+".json");
outFileGen.open(to_string(this->ID)+".json");
outFileGen << j << endl;
outFileGen.close();
cout << "File generiert\n";
......
......@@ -29,10 +29,10 @@ public:
int ID;
int dim;
int *data;
void generate(int dim);
void printtocnsl(Matrix matrix);
void generate(int dims);
void printtocnsl();
inline int &operator()(unsigned row, unsigned col) {
inline int& operator()(unsigned row, unsigned col) {
return data[dim * row + col];
}
......
//
// Created by Mario on 08/05/2020.
//
#include "Matrix.hpp"
int main() {
Matrix matrix;
Cgicc formData;
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>" << endl;
cout << "<head>" << endl;
cout << "<meta charset=\"utf-8\">" << endl;
cout << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">" << endl;
cout << "<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\" integrity=\"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh\" crossorigin=\"anonymous\">";
cout << "<title>generate.cgi</title>" << endl;
cout << "</head>" << endl;
matrix.generate(10);
form_iterator fi = formData.getElement("dimension");
if( !fi->isEmpty() && fi != (*formData).end()) {
matrix.generate(stoi(**fi));
}else {
cout << "Wrong input" << endl;
}
cout << "<a href=\"http://localhost:80/index.html\">Back to Start</a>";
cout << "</div>" << endl;
cout << "</body>\n";
cout << "</html>\n";
}
\ No newline at end of file
......@@ -2,10 +2,12 @@ CC=g++
CFLAGS=-Wall -std=c++17
LDLIBS=-lcgicc
all: show
all: show generate
show:
$(CC) $(CFLAGS) show.cpp Matrix.cpp $(LDLIBS) -o /mnt/e/IT/Tools/xampp/cgi-bin/show.cgi
generate:
$(CC) $(CFLAGS) generate.cpp Matrix.cpp $(LDLIBS) -o /mnt/e/IT/Tools/xampp/cgi-bin/generate.cgi
clean:
rm -f /mnt/e/IT/Tools/xampp/cgi-bin/*.cgi
......@@ -4,12 +4,21 @@ 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";
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";
cout << "<html>" << endl;
cout << "<head>" << endl;
cout << "<meta charset=\"utf-8\">" << endl;
cout << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">" << endl;
cout << "<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\" integrity=\"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh\" crossorigin=\"anonymous\">";
cout << "<title>show.cgi</title>" << endl;
cout << "</head>" << endl;
matrix.generate(10);
cout << "after generate\n";
......@@ -31,9 +40,10 @@ int main(){
vector<int> vector2 = j["data"];
matrix.data = &vector2[0];
matrix.printtocnsl(matrix);
matrix.printtocnsl();
cout << "<a href=\"http://localhost:80/index.html\">Back to Start</a>";
cout << "</div>" << endl;
cout << "</body>\n";
cout << "</html>\n";
return 0;
......
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