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

added config.json for index-numbering

added includes.hpp for managing includes
restricted matrices to type binary (data mod2)
parent 0399854c
...@@ -12,4 +12,5 @@ add_executable(matrix ...@@ -12,4 +12,5 @@ add_executable(matrix
multi.cpp multi.cpp
generate.cpp generate.cpp
Matrix.cpp Matrix.cpp
includes.hpp
Matrix.hpp) Matrix.hpp)
\ No newline at end of file
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "Matrix.hpp" #include "Matrix.hpp"
std::mutex m;
bool existsm(string filename){ bool existsm(string filename){
ifstream f(filename); ifstream f(filename);
return f.good(); return f.good();
...@@ -33,25 +35,56 @@ void Matrix::print(){ ...@@ -33,25 +35,56 @@ void Matrix::print(){
} }
int Matrix::generateMatrix(int dimension){ int Matrix::generateMatrix(int dimension){
json j; dim = dimension;
data = new int[dim * dim];
this->dim = dimension;
this->data = new int[this->dim * this->dim];
srand(time(NULL)); srand(time(NULL));
for (int i = 0; i < this->dim * this->dim; i++) for (int i = 0; i < dim * dim; i++)
{ {
this->data[i] = rand() % 10; data[i] = rand() % 2;
} }
this->ID = rand() % 100; m.lock();
string folderpath = "Json/"; json jconfig;
string testpath = folderpath + to_string(this->ID); string configloc = "config.json";
while(existsm(testpath)){
cout << "<p>" << "File mit ID: " << this->ID << " existiert bereits!" << "</p>"; if(!existsm(configloc)) {
this->ID = rand() % 100; json jcreate;
testpath = folderpath + to_string(this->ID); jcreate["counter"] = 0;
ofstream ocreate;
ocreate.open(configloc);
ocreate << jcreate << endl;
ocreate.close();
cout << "<p> config.json did not exist. Created config.json with counter 0" << endl;
} }
ifstream in1(configloc);
in1 >> jconfig;
// in.close();
this->ID = jconfig["counter"]; //rand() % 100;
// cout << "<p> this->ID=" << this->ID << endl;
int temp_ID = jconfig["counter"];
temp_ID++;
// cout << "<p> temp_ID=" << temp_ID << endl;
jconfig["counter"] = temp_ID;
ofstream writecounter;
writecounter.open(configloc);
writecounter << jconfig << endl;
writecounter.close();
// cout << "<p> counter in json=" << jconfig["counter"] << endl;
// cout << "<p>" << "post ID setzen" << "</p>" << endl;
string folderpath = "Json/";
// string testpath = folderpath + to_string(this->ID);
// while(existsm(testpath)){
// cout << "<p>" << "File mit ID: " << this->ID << " existiert bereits!" << "</p>";
// this->ID = rand() % 100;
// testpath = folderpath + to_string(this->ID);
// }
folderpath += to_string(this->ID) + ".json"; folderpath += to_string(this->ID) + ".json";
json j;
j["id"] = this->ID; j["id"] = this->ID;
j["dimension"] = this->dim; j["dimension"] = this->dim;
int size = this->dim * this->dim; int size = this->dim * this->dim;
...@@ -62,6 +95,7 @@ int Matrix::generateMatrix(int dimension){ ...@@ -62,6 +95,7 @@ int Matrix::generateMatrix(int dimension){
o << j << endl; o << j << endl;
o.close(); o.close();
cout << "<p>" << "File wurde mit ID: " << this->ID << " in Ordner " << folderpath << " erstellt!" << "</p>"; cout << "<p>" << "File wurde mit ID: " << this->ID << " in Ordner " << folderpath << " erstellt!" << "</p>";
m.unlock();
return this->ID; return this->ID;
} }
...@@ -70,7 +104,7 @@ Matrix::Matrix(int dim) { ...@@ -70,7 +104,7 @@ Matrix::Matrix(int dim) {
while (dim2 < dim) while (dim2 < dim)
dim2 *= 2; dim2 *= 2;
this->dim = dim2; this->dim = dim2;
this->ID = 101; // this->ID = 101;
this->data = new int[dim * dim]; this->data = new int[dim * dim];
......
...@@ -7,20 +7,7 @@ ...@@ -7,20 +7,7 @@
#ifndef MATRIX_HPP #ifndef MATRIX_HPP
#define MATRIX_HPP #define MATRIX_HPP
#include <iostream> #include "includes.hpp"
#include <filesystem>
#include <fstream>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <nlohmann/json.hpp>
#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
using namespace std; using namespace std;
using namespace cgicc; using namespace cgicc;
......
#include <iostream>
#include <filesystem>
#include <fstream>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <mutex>
#include <nlohmann/json.hpp>
#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
\ No newline at end of file
...@@ -14,7 +14,7 @@ Matrix mult_std(Matrix a, Matrix b) { ...@@ -14,7 +14,7 @@ Matrix mult_std(Matrix a, Matrix b) {
for (int i = 0; i < a.dim; i++) for (int i = 0; i < a.dim; i++)
for (int k = 0; k < a.dim; k++) for (int k = 0; k < a.dim; k++)
for (int j = 0; j < a.dim; j++) for (int j = 0; j < a.dim; j++)
c(i,j) += a(i,k) * b(k,j); c(i,j) = (c(i,j) + a(i,k) * b(k,j)) % 2;
return c; return c;
} }
...@@ -93,9 +93,10 @@ int main(){ ...@@ -93,9 +93,10 @@ int main(){
string matrixs1 = ""; string matrixs1 = "";
string matrixs2 = ""; string matrixs2 = "";
string matrixs3 = ""; string matrixs3 = "";
int targetID = 0;
form_iterator fi1 = formData.getElement("multi1"); form_iterator fi1 = formData.getElement("multi1");
if( !fi1->isEmpty() && fi1 != (*formData).end()) { if( !fi1->isEmpty() && fi1 != (*formData).end()) {
matrixs1 = **fi1; matrixs1 = "Json/" + **fi1 + ".json";
cout << matrixs1 << endl; cout << matrixs1 << endl;
} }
else { else {
...@@ -104,7 +105,7 @@ int main(){ ...@@ -104,7 +105,7 @@ int main(){
form_iterator fi2 = formData.getElement("multi2"); form_iterator fi2 = formData.getElement("multi2");
if( !fi2->isEmpty() && fi2 != (*formData).end()) { if( !fi2->isEmpty() && fi2 != (*formData).end()) {
matrixs2 = **fi2; matrixs2 = "Json/" + **fi2 + ".json";
cout << matrixs2 << endl; cout << matrixs2 << endl;
} }
else { else {
...@@ -113,7 +114,8 @@ int main(){ ...@@ -113,7 +114,8 @@ int main(){
form_iterator fi3 = formData.getElement("multi3"); form_iterator fi3 = formData.getElement("multi3");
if( !fi3->isEmpty() && fi3 != (*formData).end()) { if( !fi3->isEmpty() && fi3 != (*formData).end()) {
matrixs3 = **fi3; targetID = stoi(**fi3);
matrixs3 = "Json/" + **fi3 + ".json";
cout << matrixs3 << endl; cout << matrixs3 << endl;
} }
else { else {
...@@ -161,13 +163,14 @@ int main(){ ...@@ -161,13 +163,14 @@ int main(){
// json3["dimension"] = result.dim; // json3["dimension"] = result.dim;
int size = result.dim * result.dim; int size = result.dim * result.dim;
vector<int> v(result.data, result.data + size); vector<int> v(result.data, result.data + size);
json3["id"] = targetID;
json3["dimension"] = result.dim;
json3["matrix"] = v; json3["matrix"] = v;
ofstream o;
o.open(matrixs3);
o << json3 << endl;
o.close();
// json json3;
// srand(time(NULL));
//
// result.ID = rand() % 100;
// string folderpath = "Json/"; // string folderpath = "Json/";
// string testpath = folderpath + to_string(result.ID); // string testpath = folderpath + to_string(result.ID);
// while(existsm(testpath)){ // while(existsm(testpath)){
......
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