File indexing completed on 2024-05-12 05:26:04
0001 /* 0002 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0018 */ 0019 #pragma once 0020 0021 #include "sink_export.h" 0022 0023 #include <QVector> 0024 #include <QMap> 0025 #include <QVariant> 0026 #include <functional> 0027 #include "metadata_generated.h" 0028 #include "entitybuffer.h" 0029 #include "applicationdomaintype.h" 0030 #include "storage/key.h" 0031 0032 /* 0033 * An iterator to a result set. 0034 * 0035 * We'll eventually want to lazy load results in next(). 0036 */ 0037 class SINK_EXPORT ResultSet 0038 { 0039 public: 0040 struct Result { 0041 Result(const Sink::ApplicationDomain::ApplicationDomainType &e, Sink::Operation op, 0042 const QMap<QByteArray, QVariant> &v = {}, const QVector<Sink::Storage::Identifier> &a = {}) 0043 : entity(e), operation(op), aggregateValues(v), aggregateIds(a) 0044 { 0045 } 0046 Sink::ApplicationDomain::ApplicationDomainType entity; 0047 Sink::Operation operation; 0048 QMap<QByteArray, QVariant> aggregateValues; 0049 QVector<Sink::Storage::Identifier> aggregateIds; 0050 }; 0051 typedef std::function<void(const Result &)> Callback; 0052 typedef std::function<bool(Callback)> ValueGenerator; 0053 typedef std::function<Sink::Storage::Identifier()> IdGenerator; 0054 typedef std::function<void()> SkipValue; 0055 0056 ResultSet(); 0057 ResultSet(const ValueGenerator &generator, const SkipValue &skip); 0058 ResultSet(const QVector<Sink::Storage::Identifier> &resultSet); 0059 ResultSet(const ResultSet &other); 0060 0061 bool next(); 0062 bool next(const Callback &callback); 0063 0064 void skip(int number); 0065 0066 struct ReplayResult { 0067 qint64 replayedEntities; 0068 bool replayedAll; 0069 }; 0070 ReplayResult replaySet(int offset, int batchSize, const Callback &callback); 0071 0072 Sink::Storage::Identifier id(); 0073 0074 bool isEmpty(); 0075 0076 private: 0077 QVector<Sink::Storage::Identifier> mResultSet; 0078 QVector<Sink::Storage::Identifier>::ConstIterator mIt; 0079 Sink::Storage::Identifier mCurrentValue; 0080 ValueGenerator mValueGenerator; 0081 SkipValue mSkip; 0082 bool mFirst; 0083 };