-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyntable.h
67 lines (60 loc) · 1.8 KB
/
dyntable.h
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
#include <iostream>
#include "dyncmatx.h"
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Table{
ifstream lectura;
vector<vector<string>> the_table;
void build_table(){
for (string linea; getline(lectura, linea); )
{
stringstream registro(linea);
string dato; vector<string> temp_table;
for (int columna = 0; getline(registro, dato, ','); ++columna)
{
temp_table.emplace_back(dato);
}
the_table.emplace_back(temp_table);
}
}
public:
Table(const string& __path){
lectura.open(__path,ios::in);
build_table();
lectura.close();
}
string get_data_table(const uint& row,const uint& col){
return the_table.at(row).at(col);
}
void print_table(){
for(uint i = 0; i != the_table.size();i++){
for(string & e: the_table.at(i)){
cout << e << " ";
}
cout << endl;
}
}
void refresh(const string& new_path){
lectura.open(new_path,ios::in);
build_table();
lectura.close();
}
dyncmatx<string> get_dyn_table(){
dyncmatx<string> res = the_table;
return res;
}
DMAT get_matrix_table(){
vector<vector<double>> nums;
for(uint i = 0; i != the_table.size();i++){
vector<double> temp_nums;
string::size_type sz;
for(uint j = 0; j != the_table.at(i).size();j++){
temp_nums.emplace_back(stod( the_table[i][j], &sz ));
}
nums.emplace_back(temp_nums);
}
return nums;
}
};