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

cleanup

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