/************************************************************************** ** ** 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 #include #include #include #include #include NUT_BEGIN_NAMESPACE template class Query; class BulkInserter; class Database; template class TableSet : public AbstractTableSet { public: typedef T value_type; typedef T *pointer; typedef T &reference; explicit TableSet(Database *parent); explicit TableSet(Table *parent); void append(Row t); void append(RowList t); void remove(Row t); void remove(RowList t); int length() const; Row at(int i) const; Row operator[](int i) const; Query *query(bool autoDelete = true); BulkInserter *bulkInserter(); }; template Q_OUTOFLINE_TEMPLATE TableSet::TableSet(Database *parent) : AbstractTableSet(parent) { data->childClassName = QString::fromUtf8(T::staticMetaObject.className()); } template Q_OUTOFLINE_TEMPLATE TableSet::TableSet(Table *parent) : AbstractTableSet(parent) { data->childClassName = QString::fromUtf8(T::staticMetaObject.className()); } template Q_OUTOFLINE_TEMPLATE Query *TableSet::query(bool autoDelete) { Query *q = new Query(data->database, this, autoDelete); return q; } template Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet::bulkInserter() { BulkInserter *bi = new BulkInserter(data->database, data->childClassName); return bi; } template Q_OUTOFLINE_TEMPLATE int TableSet::length() const { return data->childs.count(); } template Q_OUTOFLINE_TEMPLATE Row TableSet::at(int i) const { #ifdef NUT_SHARED_POINTER return data->childs.at(i).template objectCast(); #else return reinterpret_cast(data->childs.at(i)); #endif } template Q_OUTOFLINE_TEMPLATE Row TableSet::operator[](int i) const { return at(i); } template Q_OUTOFLINE_TEMPLATE void TableSet::append(Row t) { data.detach(); data->childs.append(t); // data->tables.insert(t.data()); // data->childRows.append(t.data()); // if (_database) // t->setModel(_database->model().tableByClassName(t->metaObject()->className())); t->setParentTableSet(this); if(t->status() != Table::FetchedFromDB) t->setStatus(Table::Added); } template Q_OUTOFLINE_TEMPLATE void TableSet::append(RowList t) { foreach (Row i, t) append(i); } template Q_OUTOFLINE_TEMPLATE void TableSet::remove(Row t) { data.detach(); // data->childs.removeOne(t.data()); // data->tables.remove(t.data()); data->childs.removeOne(t); t->setStatus(Table::Deleted); } template Q_OUTOFLINE_TEMPLATE void TableSet::remove(RowList t) { foreach (Row i, t) remove(i); } NUT_END_NAMESPACE #endif // TABLESET_H