/************************************************************************** ** ** This file is part of Nut project. ** https://github.com/HamedMasafi/Nut ** ** Nut is free software: you can redistribute it and/or modify ** it under the terms of the GNU Lesser General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** Nut is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU Lesser General Public License for more details. ** ** You should have received a copy of the GNU Lesser General Public License ** along with Nut. If not, see . ** **************************************************************************/ #ifndef TABLESET_H #define TABLESET_H #include #include #include #include #include #include "tablesetbase_p.h" #include "table.h" #include "bulkinserter.h" NUT_BEGIN_NAMESPACE template class Query; class BulkInserter; template class NUT_EXPORT TableSet : public TableSetBase { public: explicit TableSet(Database *parent); explicit TableSet(Table *parent); void append(T *t); void append(QList t); void remove(T *t); void remove(QList t); inline T *type() const {} int length() const; T *at(int i) const; const T &operator[](int i) const; Query *query(bool autoDelete = true); BulkInserter *bulkInserter(); }; template Q_OUTOFLINE_TEMPLATE TableSet::TableSet(Database *parent) : TableSetBase(parent) { _childClassName = T::staticMetaObject.className(); } template Q_OUTOFLINE_TEMPLATE TableSet::TableSet(Table *parent) : TableSetBase(parent) { _childClassName = T::staticMetaObject.className(); } template Q_OUTOFLINE_TEMPLATE Query *TableSet::query(bool autoDelete) { Query *q = new Query(_database, this, autoDelete); return q; } template Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet::bulkInserter() { BulkInserter *bi = new BulkInserter(_childClassName); return bi; } template Q_OUTOFLINE_TEMPLATE int TableSet::length() const { return _tables.count(); } template Q_OUTOFLINE_TEMPLATE T *TableSet::at(int i) const { return reinterpret_cast(_tablesList.at(i)); } template Q_OUTOFLINE_TEMPLATE const T &TableSet::operator[](int i) const { return _tablesList[i]; } template Q_OUTOFLINE_TEMPLATE void TableSet::append(T *t) { _tables.insert(t); _tablesList.append(t); // rows.append(t); t->setParentTableSet(this); if(t->status() != Table::FeatchedFromDB) t->setStatus(Table::Added); } template Q_OUTOFLINE_TEMPLATE void TableSet::append(QList t) { foreach (T* i, t) append(i); } template Q_OUTOFLINE_TEMPLATE void TableSet::remove(T *t) { _tables.remove(t); t->setStatus(Table::Deleted); } template Q_OUTOFLINE_TEMPLATE void TableSet::remove(QList t) { foreach (T* i, t) remove(i); } NUT_END_NAMESPACE #endif // TABLESET_H