-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
117 lines (114 loc) · 5.48 KB
/
config.cpp
File metadata and controls
117 lines (114 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef CONFIG_CPP
#define CONFIG_CPP
#include <string>
#include <unordered_map>
#include <fstream>
#include <iostream>
#include "config.h"
enum pointer_type{
PT_STRING,
PT_INT,
PT_DOUBLE,
PT_DOUBLE_ARRAY,
PT_DOUBLE_ARRAY_ADD,
};
struct pointer_entitie
{
enum pointer_type type;
void* pointer;
void* pointer_2;
};
int config(std::string* file_path,int* debug_one,int* debug_two,int* debug_three,double* start_time,int* debug_one_step_one,int* debug_one_step_two,int* debug_one_step_three,double* increment,double* calculate_steps,int* number_calculate_steps){
try{
std::string line;
std::string line2;
std::string filename = "config";
std::ifstream config_file(filename);
std::unordered_map <std::string,pointer_entitie> map_pointers;
map_pointers["Name of Dataset:"] = pointer_entitie {.type=PT_STRING,.pointer = file_path};
map_pointers["Debug mode one:"] = pointer_entitie {.type=PT_INT,.pointer = debug_one};
map_pointers["Debug mode two:"] = pointer_entitie {.type=PT_INT,.pointer = debug_two};
map_pointers["Debug mode three:"] = pointer_entitie {.type=PT_INT,.pointer = debug_three};
map_pointers["Start time:"] = pointer_entitie {.type=PT_DOUBLE,.pointer = start_time};
map_pointers["Debug mode one stepping one:"] = pointer_entitie {.type=PT_INT,.pointer = debug_one_step_one};
map_pointers["Debug mode one stepping two:"] = pointer_entitie {.type=PT_INT,.pointer = debug_one_step_two};
map_pointers["Debug mode one stepping three:"] = pointer_entitie {.type=PT_INT,.pointer = debug_one_step_three};
map_pointers["Increment for threads(above 25000 cells):"] = pointer_entitie {.type=PT_DOUBLE,.pointer=increment};
map_pointers["Calculate these time steps base:"] = pointer_entitie {.type=PT_DOUBLE_ARRAY,.pointer=calculate_steps,.pointer_2=number_calculate_steps};//given in the following format--> start_value \n end_value \n increments
map_pointers["Calculate these time steps add:"] = pointer_entitie {.type=PT_DOUBLE_ARRAY_ADD,.pointer=calculate_steps,.pointer_2=number_calculate_steps};//given in the following format--> start_value \n end_value \n increments
std::string* temp_string_pointer;
int* temp_int8_t_pointer;
double* temp_double_pointer;
double start;
double end;
double increm;
if (config_file.is_open()){
while(std::getline(config_file,line)){
if(line == "<<END>>"){
//std::cout<<"END of config"<<std::endl;
return 0;
}
if(std::getline(config_file,line2)){
//std::cout<<"value read:"<<line2 <<" Asigning to" << line << "At memory location " << map_pointers[line].pointer <<std::endl;
switch (map_pointers[line].type)
{
case PT_STRING:
temp_string_pointer = (std::string*) map_pointers[line].pointer;
*temp_string_pointer = line2;
break;
case PT_INT: //converts a string to a int and saves it at the coresponding position
temp_int8_t_pointer = (int*) map_pointers[line].pointer;
*temp_int8_t_pointer = std::stoi(line2);
break;
case PT_DOUBLE:
temp_double_pointer = (double*) map_pointers[line].pointer;
*temp_double_pointer = std::stod(line2);
break;
case PT_DOUBLE_ARRAY:
temp_double_pointer = (double*) map_pointers[line].pointer;
temp_int8_t_pointer = (int*) map_pointers[line].pointer_2;
start = std::stod(line2);
std::getline(config_file,line);
end = std::stod(line);
std::getline(config_file,line);
increm = std::stod(line);
temp_double_pointer[0] = start;
temp_double_pointer[1] = end;
temp_double_pointer[2] = increm;
//std::cout<<temp_double_pointer[0]<<std::endl;
//std::cout<<temp_double_pointer[1]<<std::endl;
//std::cout<<temp_double_pointer[2]<<std::endl;
*temp_int8_t_pointer = 1;
break;
case PT_DOUBLE_ARRAY_ADD:
temp_double_pointer = (double*) map_pointers[line].pointer;
temp_int8_t_pointer = (int*) map_pointers[line].pointer_2;
start = std::stod(line2);
std::getline(config_file,line);
end = std::stod(line);
std::getline(config_file,line);
increm = std::stod(line);
double* temp_pointer;
temp_double_pointer[0+2*(*temp_int8_t_pointer)] = start;
temp_double_pointer[1+2*(*temp_int8_t_pointer)] = end;
temp_double_pointer[2+2*(*temp_int8_t_pointer)] = increm;
*temp_int8_t_pointer += 1;
break;
default:
break;
}
}
else{
throw 1;
}
}
config_file.close();
return 0;
}
}
catch(...){
return 1;
}
return 0;
};
#endif