File indexing completed on 2024-04-21 03:51:48

0001 /*
0002     This file is part of the KDE Baloo Project
0003     SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "resultiterator.h"
0009 #include "result_p.h"
0010 #include "searchstore.h"
0011 #include <limits>
0012 #include <vector>
0013 #include <utility>
0014 
0015 using namespace Baloo;
0016 
0017 class Baloo::ResultIteratorPrivate {
0018 public:
0019     ResultIteratorPrivate() = default;
0020 
0021     ~ResultIteratorPrivate() {
0022     }
0023 
0024     ResultList results;
0025     std::size_t pos = std::numeric_limits<size_t>::max();
0026 };
0027 
0028 ResultIterator::ResultIterator(ResultList&& res)
0029     : d(new ResultIteratorPrivate)
0030 {
0031     d->results = res;
0032 }
0033 
0034 ResultIterator::ResultIterator(ResultIterator &&rhs)
0035     : d(std::move(rhs.d))
0036 {
0037 }
0038 
0039 ResultIterator::~ResultIterator() = default;
0040 
0041 bool ResultIterator::next()
0042 {
0043     d->pos++; // overflows to 0 on first use
0044     return d->pos < d->results.size();
0045 }
0046 
0047 QString ResultIterator::filePath() const
0048 {
0049     Q_ASSERT(d->pos < d->results.size());
0050     return QString::fromUtf8(d->results.at(d->pos).filePath);
0051 }
0052 
0053 QByteArray ResultIterator::documentId() const
0054 {
0055     Q_ASSERT(d->pos < d->results.size());
0056     return QByteArray::number(d->results.at(d->pos).documentId, 16);
0057 }