6 Star 4 Fork 2

GPLme / SG-Database

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
col.hpp 3.05 KB
一键复制 编辑 原始数据 按行查看 历史
#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;
}
};
C++
1
https://gitee.com/sg-first/SG-Database.git
git@gitee.com:sg-first/SG-Database.git
sg-first
SG-Database
SG-Database
master

搜索帮助