1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/sg-first-SG-Database

В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
col.hpp 3.1 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
怎样 Отправлено 07.03.2021 16:51 b57503c
#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;
}
};

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/sg-first-SG-Database.git
git@api.gitlife.ru:oschina-mirror/sg-first-SG-Database.git
oschina-mirror
sg-first-SG-Database
sg-first-SG-Database
master