diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-05 09:46:53 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-05 09:46:53 +0100 |
commit | 351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad (patch) | |
tree | 3ba738fdc01f2b73bc3942ed530db34ef4cc1d6e /common/storage_kyoto.cpp | |
parent | 0c1400c7f0cf2f545a6cd7347314c1158fbfa36f (diff) | |
download | sink-351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad.tar.gz sink-351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad.zip |
make read return a bool on success
not happy with this API, but we need to discuss the whole read
thing anyways
Diffstat (limited to 'common/storage_kyoto.cpp')
-rw-r--r-- | common/storage_kyoto.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/common/storage_kyoto.cpp b/common/storage_kyoto.cpp index 05942c2..40bd3e6 100644 --- a/common/storage_kyoto.cpp +++ b/common/storage_kyoto.cpp | |||
@@ -118,28 +118,34 @@ bool Storage::write(const std::string &sKey, const std::string &sValue) | |||
118 | return success; | 118 | return success; |
119 | } | 119 | } |
120 | 120 | ||
121 | void Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) | 121 | bool Storage::read(const std::string &sKey, const std::function<void(const std::string &value)> &resultHandler) |
122 | { | 122 | { |
123 | if (!d->dbOpen) { | 123 | if (!d->dbOpen) { |
124 | return; | 124 | return false; |
125 | } | 125 | } |
126 | 126 | ||
127 | std::string value; | 127 | std::string value; |
128 | if (d->db.get(sKey, &value)) { | 128 | if (d->db.get(sKey, &value)) { |
129 | resultHandler(value); | 129 | resultHandler(value); |
130 | return true; | ||
130 | } | 131 | } |
132 | |||
133 | return false; | ||
131 | } | 134 | } |
132 | 135 | ||
133 | void Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) | 136 | bool Storage::read(const std::string &sKey, const std::function<void(void *ptr, int size)> &resultHandler) |
134 | { | 137 | { |
135 | if (!d->dbOpen) { | 138 | if (!d->dbOpen) { |
136 | return; | 139 | return false; |
137 | } | 140 | } |
138 | 141 | ||
139 | size_t valueSize; | 142 | size_t valueSize; |
140 | char *valueBuffer = d->db.get(sKey.data(), sKey.size(), &valueSize); | 143 | char *valueBuffer = d->db.get(sKey.data(), sKey.size(), &valueSize); |
141 | resultHandler(valueBuffer, valueSize); | 144 | if (valueBuffer) { |
145 | resultHandler(valueBuffer, valueSize); | ||
146 | } | ||
142 | delete[] valueBuffer; | 147 | delete[] valueBuffer; |
148 | return valueBuffer != nullptr; | ||
143 | } | 149 | } |
144 | 150 | ||
145 | qint64 Storage::diskUsage() const | 151 | qint64 Storage::diskUsage() const |