Baloo

resultiterator.cpp
1 /*
2  This file is part of the KDE Baloo Project
3  SPDX-FileCopyrightText: 2013 Vishesh Handa <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #include "resultiterator.h"
9 #include "result_p.h"
10 #include "searchstore.h"
11 #include <limits>
12 #include <vector>
13 
14 using namespace Baloo;
15 
16 class Baloo::ResultIteratorPrivate {
17 public:
18  ResultIteratorPrivate() = default;
19 
20  ~ResultIteratorPrivate() {
21  }
22 
23  ResultList results;
24  std::size_t pos = std::numeric_limits<size_t>::max();
25 };
26 
27 ResultIterator::ResultIterator(ResultList&& res)
28  : d(new ResultIteratorPrivate)
29 {
30  d->results = res;
31 }
32 
33 #if BALOO_CORE_BUILD_DEPRECATED_SINCE(5, 55)
34 ResultIterator::ResultIterator(const ResultIterator& rhs)
35  : d(new ResultIteratorPrivate)
36 {
37  d->results = rhs.d->results;
38 }
39 #endif
40 
41 ResultIterator::ResultIterator(ResultIterator &&rhs)
42  : d(rhs.d)
43 {
44  rhs.d = nullptr;
45 }
46 
47 ResultIterator::~ResultIterator()
48 {
49  delete d;
50 }
51 
52 bool ResultIterator::next()
53 {
54  d->pos++; // overflows to 0 on first use
55  return d->pos < d->results.size();
56 }
57 
58 QString ResultIterator::filePath() const
59 {
60  Q_ASSERT(d->pos < d->results.size());
61  return QString::fromUtf8(d->results.at(d->pos).filePath);
62 }
63 
64 QByteArray ResultIterator::documentId() const
65 {
66  Q_ASSERT(d->pos < d->results.size());
67  return QByteArray::number(d->results.at(d->pos).documentId, 16);
68 }
QString fromUtf8(const char *str, int size)
QByteArray number(int n, int base)
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.