/* * Copyright (C) 2014 Christian Mollekopf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once #include #include #include #include #include "metadata_generated.h" #include "entitybuffer.h" #include "applicationdomaintype.h" /* * An iterator to a result set. * * We'll eventually want to lazy load results in next(). */ class ResultSet { public: struct Result { Result(const Sink::ApplicationDomain::ApplicationDomainType &e, Sink::Operation op, const QMap &v = {}, const QVector &a = {}) : entity(e), operation(op), aggregateValues(v), aggregateIds(a) {} Sink::ApplicationDomain::ApplicationDomainType entity; Sink::Operation operation; QMap aggregateValues; QVector aggregateIds; }; typedef std::function Callback; typedef std::function ValueGenerator; typedef std::function IdGenerator; typedef std::function SkipValue; ResultSet(); ResultSet(const ValueGenerator &generator, const SkipValue &skip); ResultSet(const IdGenerator &generator); ResultSet(const QVector &resultSet); ResultSet(const ResultSet &other); bool next(); bool next(const Callback &callback); void skip(int number); struct ReplayResult { qint64 replayedEntities; bool replayedAll; }; ReplayResult replaySet(int offset, int batchSize, const Callback &callback); QByteArray id(); bool isEmpty(); private: QVector mResultSet; QVector::ConstIterator mIt; QByteArray mCurrentValue; IdGenerator mGenerator; ValueGenerator mValueGenerator; SkipValue mSkip; bool mFirst; };