-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsCall.cpp
178 lines (143 loc) · 5.07 KB
/
jsCall.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "tableManager.h"
#include "typeHelper.hpp"
#include "aggHelper.h"
#include <QtScript/QScriptEngine>
Q_DECLARE_METATYPE(QVector<QString>)
using namespace std;
TYPE strToType(const string& str){
if(str=="FLOAT"){
return FLOAT;
}
else if(str=="INT"){
return INT;
}
else if(str=="STR"){
return STR;
}
else if(str=="BOOL"){
return BOOL;
}
else if(str=="NULL"){
return _NULL;
}
return PLACEHOLDER;
}
vector<string> jsvalueTostrVec(const QScriptValue& jsvalue){
vector<string> StrVec;
const QVector<QString>& strVec=qscriptvalue_cast<QVector<QString>>(jsvalue);
for(const QString& str:strVec){
StrVec.push_back(str.toStdString());
}
return StrVec;
}
vector<col*> strVecToColVec(const vector<string>& colStrVec){
vector<col*> colVec;
for(const string& str:colStrVec){
for(int i=0;i<str.length();++i){
if(str[i]==':'){
colVec.push_back(new col (str.substr(i+1),str.substr(0,i)));
break;
}
}
}
return colVec;
}
vector<Basic*> jsvalueToBasicVec(const QScriptValue& str){
const vector<string>& tmp=jsvalueTostrVec(str);
vector<Basic*> basicVec;
for(int i=0;i<tmp.size();++i){
basicVec.push_back(typeHelper::typehelper->strToBasic(QString::fromStdString(tmp[i])));
}
return basicVec;
}
table* tableManager::tableJoin(const QString &newTableID, const QString &lTableName, const QScriptValue &lColName, const QString &rTableName, const QScriptValue &rColName, const QString &lKey, const QString &rKey, const QString &joinWay){
return tableJoin(newTableID,lTableName,jsvalueTostrVec(lColName),rTableName,jsvalueTostrVec(rColName),lKey,rKey,joinWay);
}
table* table::genNewTable(const QScriptValue& colNames, jsCollection *tupSubList){
return this->genNewTable(jsvalueTostrVec(colNames),tupSubList->getintVec());
}
void table::add(const QScriptValue& tuple){
vector<Basic*> basicVec=jsvalueToBasicVec(tuple);
this->add(basicVec);
}
void table::mod(int opSub, const QScriptValue& tuple){
vector<Basic*> basicVec=jsvalueToBasicVec(tuple);
this->mod(opSub,basicVec);
}
void table::del(jsCollection *allOpSub){
this->del(allOpSub->getintVec());
}
jsCollection* table::find_in(const QString& colName, jsCollection *target_vec){
const vector<int>& tmp=this->find_in(colName.toStdString(),target_vec->getbasicVec());
return new jsCollection (tmp);
}
jsCollection* table::find_not_in(const QString& colName, jsCollection *target_vec){
const vector<int>& tmp=this->find_not_in(colName.toStdString(),target_vec->getbasicVec());
return new jsCollection (tmp);
}
jsCollection* table::find(const QScriptValue& allExp){
const vector<string>& StrVec=jsvalueTostrVec(allExp);
return new jsCollection(find(StrVec));
}
col* table::getCol(const QString &colName){
return getCol(this->findCol({colName.toStdString()})[0]);
}
int table::getColIndex(const QString &colName){
return this->getColIndex(colName.toStdString());
}
table* tableManager::createTable(const QString& ID,const QScriptValue& strVec){
const vector<string>& colStrVec=jsvalueTostrVec(strVec);
vector<col*> allCols=strVecToColVec(colStrVec);
return new table(ID.toStdString(),allCols);
}
void tableManager::removeTable(const QString& ID){
const string& tableName=ID.toStdString();
auto iter=managedTable.find(tableName);
if(iter!=managedTable.end()){
delete managedTable[tableName];
managedTable.erase(tableName);
auto it=find(managedTableName.begin(),managedTableName.end(),tableName);
managedTableName.erase(it);
}
const string& path=table::default_path+"\\"+tableName+".csv";
IO::del_table_blocks(path);
}
col::col(const string& type,const string& ID):type(strToType(type)),ID(ID){}
jsCollection* col::getData(jsCollection *filtered_index){
return new jsCollection(this->getData(filtered_index->getintVec()));
}
col* col::genNewCol(jsCollection *subList){
return this->genNewCol(subList->getintVec());
}
const jsCollection* col::getallData(){
return new jsCollection (this->allData);
}
Basic* typeHelper::strToBasic(const QString &val){
string tmp=val.toStdString();
TYPE tp=judgeType(tmp);
return strToBasic(tmp,tp);
}
jsCollection* aggHelper::distinct(jsCollection *data_vec){
return new jsCollection (this->distinct(data_vec->getbasicVec()));
}
Basic* aggHelper::avg(jsCollection* data_vec){
return this->avg(data_vec->getbasicVec());
}
Basic* aggHelper::count(jsCollection *data_vec){
return this->count(data_vec->getbasicVec());
}
Basic* aggHelper::first(jsCollection *data_vec){
return this->first(data_vec->getbasicVec());
}
Basic* aggHelper::last(jsCollection *data_vec){
return this->last(data_vec->getbasicVec());
}
Basic* aggHelper::max(jsCollection* data_vec){
return this->max(data_vec->getbasicVec());
}
Basic* aggHelper::min(jsCollection* data_vec){
return this->min(data_vec->getbasicVec());
}
Basic* aggHelper::sum(jsCollection *data_vec){
return this->sum(data_vec->getbasicVec());
}