代码拉取完成,页面将自动刷新
#pragma once
#include <vector>
#include <list>
#include "basicType.h"
#include "record.h"
#include "config.h"
#ifdef JsInBasicClass
class jsCollection;
#endif
class col : public QObject, public manageable
{
private:
Q_OBJECT
const TYPE type;
vector<Basic*> allData;
public:
col(TYPE type,string ID) : type(type), ID(ID) {}
Q_INVOKABLE col(const col &c) : type(c.type), ID(c.ID)
{
for(Basic* v : this->allData)
{
auto copyObj=typeHelper::typehelper->copy(v);
copyObj->setSystemManage(); //转移所有权到col
this->allData.push_back(copyObj);
}
}
string ID;
//fix:还要有触发器和约束
const vector<Basic*> getAllData() { return this->allData; }
#ifdef JsInBasicClass
Q_INVOKABLE const jsCollection* getallData();
#endif
int getLen(){ return this->allData.size(); }
TYPE getType() { return this->type; }
vector<Basic*> getData(const vector<int>& filtered_index) //把指定下标的元素get出来
{
vector<Basic*> result;
for(int index:filtered_index) {
result.push_back(typeHelper::typehelper->copy(allData[index]));
}
return result;
}
#ifdef JsInBasicClass
Q_INVOKABLE jsCollection* getData(jsCollection* filtered_index);
#endif
string getLocStr(const int& index){
return allData[index]->toStr();
}
Q_INVOKABLE QString toStr()
{
string result="";
result+=(this->ID+":"+to_string(int(this->type)))+"\n";
for(int i=0;i<this->allData.size();++i){
result+=allData[i]->toStr()+"\n";
}
return QString::fromStdString(result);
}
col* genNewCol(const vector<int>& subList) //把指定下标的元素生成一张新表
{
col* result=new col(this->type,this->ID);
for(int i : subList)
{
Basic* copyObj;
if(i==-1){
copyObj=new Basic();
}
else{
copyObj=typeHelper::typehelper->copy(this->allData[i]); //会拷贝
}
result->add(copyObj);
}
return result;
}
#ifdef JsInBasicClass
Q_INVOKABLE col* genNewCol(jsCollection* subList);
#endif
Q_INVOKABLE void add(Basic* v) //必须使用这个函数添加数据
{
TYPE dataType=v->getType();
if(dataType!=this->getType()&&dataType!=_NULL)
throw string("type mismatch");
else
{
v->setSystemManage();
this->allData.push_back(v);
}
}
Q_INVOKABLE void mod(int opSub,Basic* v) //会拷贝,返回对这个值的修改是否实际进行
{
this->add(v);
this->del(opSub);
}
Q_INVOKABLE void del(int opSub)
{
delete this->allData[opSub];
this->allData.erase(this->allData.begin()+opSub);
}
~col()
{
for(Basic* v : allData)
delete v;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。