This repository has been archived by the owner on Dec 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable.cpp
54 lines (48 loc) · 1.59 KB
/
table.cpp
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
#include "table.h"
Table::Table(str name, strp_vec& vec, uint_vec nums, char_name_vec& cvec){
this->name = name;
Data *temp = new Data(nums.at(0), nums.at(1), vec, cvec);
this->t_data = temp;
}
str Table::getName(){
return this->name;
}
void Table::desc(){
int camps;
camps = this->t_data->n + this->t_data->v;
std::cout << "Tabla: " << this->name << '\n';
std::cout << "Hay " << camps << " atributos.\n";
print_vec(this->t_data->names, this->t_data->vchars);
}
void writeTable(txt_file& file, Table* t){
int j = 0;
file << t->name << '\n';
for(int i = 0; i < t->t_data->names.size(); i++){
file << t->t_data->names.at(i).second << ' '; //STORED: DATA_NAME DATA_TYPE ENDL
if (t->t_data->names.at(i).first == "VARCHAR" ){
file << "VARCHAR(" << t->t_data->vchars.at(j).second << ")" << '\n';
j++;
} else file << t->t_data->names.at(i).first << '\n'; //TIPO DE DATO
}
file << "-----------------------------------------"; //SEPARATION BETWEEN TABLES
file << '\n' << std::endl; //so the next one starts at the next line
}
void writeHeaderTable(txt_file& file, Table* t){
int j = 0;
str alg;
alg.clear();
for(int i = 0; i < t->t_data->names.size(); i++){
//alg += (t->t_data->names.at(i).second + ',');
if (i != t->t_data->names.size()-1){
//file << t->t_data->names.at(i).second << ','; //STORED: DATA_NAME,DATA_NAME,... ENDL
alg += (t->t_data->names.at(i).second + ',');
}
else {
//file << t->t_data->names.at(i).second;
alg += t->t_data->names.at(i).second;
}
}
//while (alg.size() <= 59) alg += ' ';
alg += '\n'; //SEPARATION FOR THE DATA TO BE STORED
file << alg;
}