File indexing completed on 2024-04-28 15:17:40

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 
0014 using namespace Baloo;
0015 
0016 class Baloo::ResultIteratorPrivate {
0017 public:
0018     ResultIteratorPrivate() = default;
0019 
0020     ~ResultIteratorPrivate() {
0021     }
0022 
0023     ResultList results;
0024     std::size_t pos = std::numeric_limits<size_t>::max();
0025 };
0026 
0027 ResultIterator::ResultIterator(ResultList&& res)
0028     : d(new ResultIteratorPrivate)
0029 {
0030     d->results = res;
0031 }
0032 
0033 #if BALOO_CORE_BUILD_DEPRECATED_SINCE(5, 55)
0034 ResultIterator::ResultIterator(const ResultIterator& rhs)
0035     : d(new ResultIteratorPrivate)
0036 {
0037     d->results = rhs.d->results;
0038 }
0039 #endif
0040 
0041 ResultIterator::ResultIterator(ResultIterator &&rhs)
0042     : d(rhs.d)
0043 {
0044     rhs.d = nullptr;
0045 }
0046 
0047 ResultIterator::~ResultIterator()
0048 {
0049     delete d;
0050 }
0051 
0052 bool ResultIterator::next()
0053 {
0054     d->pos++; // overflows to 0 on first use
0055     return d->pos < d->results.size();
0056 }
0057 
0058 QString ResultIterator::filePath() const
0059 {
0060     Q_ASSERT(d->pos < d->results.size());
0061     return QString::fromUtf8(d->results.at(d->pos).filePath);
0062 }
0063 
0064 QByteArray ResultIterator::documentId() const
0065 {
0066     Q_ASSERT(d->pos < d->results.size());
0067     return QByteArray::number(d->results.at(d->pos).documentId, 16);
0068 }