diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-20 20:49:17 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-20 20:49:17 +0100 |
commit | ed42bdd74d70c7bcb9e1fb8f071ccb92b1515406 (patch) | |
tree | fc068b2f678d3d38d5ad398e6c85474306a0aa02 /common/resultset.h | |
parent | bc06643cd0c16140f6013be35b64732c1676e794 (diff) | |
download | sink-ed42bdd74d70c7bcb9e1fb8f071ccb92b1515406.tar.gz sink-ed42bdd74d70c7bcb9e1fb8f071ccb92b1515406.zip |
Fetch more data on demand
We skip values we've already seen and only retrieve the new ones.
This currently only properly works in a non-live query and we don't
give the model any feedback when we can't fetch more data anymore.
However, it generally works and we get the desired effect.
Diffstat (limited to 'common/resultset.h')
-rw-r--r-- | common/resultset.h | 101 |
1 files changed, 11 insertions, 90 deletions
diff --git a/common/resultset.h b/common/resultset.h index 8a0720d..e513460 100644 --- a/common/resultset.h +++ b/common/resultset.h | |||
@@ -34,100 +34,20 @@ class ResultSet { | |||
34 | typedef std::function<QByteArray()> IdGenerator; | 34 | typedef std::function<QByteArray()> IdGenerator; |
35 | typedef std::function<void()> SkipValue; | 35 | typedef std::function<void()> SkipValue; |
36 | 36 | ||
37 | ResultSet() | 37 | ResultSet(); |
38 | : mIt(nullptr) | 38 | ResultSet(const ValueGenerator &generator, const SkipValue &skip); |
39 | { | 39 | ResultSet(const IdGenerator &generator); |
40 | ResultSet(const QVector<QByteArray> &resultSet); | ||
41 | ResultSet(const ResultSet &other); | ||
40 | 42 | ||
41 | } | 43 | bool next(); |
44 | bool next(std::function<bool(const Sink::ApplicationDomain::ApplicationDomainType::Ptr &value, Sink::Operation)> callback); | ||
42 | 45 | ||
43 | ResultSet(const ValueGenerator &generator, const SkipValue &skip) | 46 | void skip(int number); |
44 | : mIt(nullptr), | ||
45 | mValueGenerator(generator), | ||
46 | mSkip(skip) | ||
47 | { | ||
48 | 47 | ||
49 | } | 48 | QByteArray id(); |
50 | 49 | ||
51 | ResultSet(const IdGenerator &generator) | 50 | bool isEmpty(); |
52 | : mIt(nullptr), | ||
53 | mGenerator(generator), | ||
54 | mSkip([this]() { | ||
55 | mGenerator(); | ||
56 | }) | ||
57 | { | ||
58 | |||
59 | } | ||
60 | |||
61 | ResultSet(const QVector<QByteArray> &resultSet) | ||
62 | : mResultSet(resultSet), | ||
63 | mIt(nullptr), | ||
64 | mSkip([this]() { | ||
65 | mGenerator(); | ||
66 | }) | ||
67 | { | ||
68 | |||
69 | } | ||
70 | |||
71 | bool next() | ||
72 | { | ||
73 | if (mGenerator) { | ||
74 | mCurrentValue = mGenerator(); | ||
75 | } else { | ||
76 | if (!mIt) { | ||
77 | mIt = mResultSet.constBegin(); | ||
78 | } else { | ||
79 | mIt++; | ||
80 | } | ||
81 | return mIt != mResultSet.constEnd(); | ||
82 | } | ||
83 | if (!mCurrentValue.isNull()) { | ||
84 | return true; | ||
85 | } | ||
86 | return false; | ||
87 | } | ||
88 | |||
89 | bool next(std::function<bool(const Sink::ApplicationDomain::ApplicationDomainType::Ptr &value, Sink::Operation)> callback) | ||
90 | { | ||
91 | Q_ASSERT(mValueGenerator); | ||
92 | return mValueGenerator(callback); | ||
93 | } | ||
94 | |||
95 | bool next(std::function<void(const QByteArray &key)> callback) | ||
96 | { | ||
97 | if (mGenerator) { | ||
98 | mCurrentValue = mGenerator(); | ||
99 | } else { | ||
100 | if (!mIt) { | ||
101 | mIt = mResultSet.constBegin(); | ||
102 | } else { | ||
103 | mIt++; | ||
104 | } | ||
105 | return mIt != mResultSet.constEnd(); | ||
106 | } | ||
107 | return false; | ||
108 | } | ||
109 | |||
110 | void skip(int number) | ||
111 | { | ||
112 | Q_ASSERT(mSkip); | ||
113 | for (int i = 0; i < number; i++) { | ||
114 | mSkip(); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | QByteArray id() | ||
119 | { | ||
120 | if (mIt) { | ||
121 | return *mIt; | ||
122 | } else { | ||
123 | return mCurrentValue; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | bool isEmpty() | ||
128 | { | ||
129 | return mResultSet.isEmpty(); | ||
130 | } | ||
131 | 51 | ||
132 | private: | 52 | private: |
133 | QVector<QByteArray> mResultSet; | 53 | QVector<QByteArray> mResultSet; |
@@ -136,5 +56,6 @@ class ResultSet { | |||
136 | IdGenerator mGenerator; | 56 | IdGenerator mGenerator; |
137 | ValueGenerator mValueGenerator; | 57 | ValueGenerator mValueGenerator; |
138 | SkipValue mSkip; | 58 | SkipValue mSkip; |
59 | bool mFirst; | ||
139 | }; | 60 | }; |
140 | 61 | ||