summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-03 09:01:05 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-03 09:01:05 +0100
commit4d9746c828558c9f872e0aed52442863affb25d5 (patch)
tree507d7c2ba67f47d3cbbcf01a722236ff1b48426b /common/index.cpp
parent9cea920b7dd51867a0be0fed2f461b6be73c103e (diff)
downloadsink-4d9746c828558c9f872e0aed52442863affb25d5.tar.gz
sink-4d9746c828558c9f872e0aed52442863affb25d5.zip
Fromatted the whole codebase with clang-format.
clang-format -i */**{.cpp,.h}
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/common/index.cpp b/common/index.cpp
index e35b838..b5e9980 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -7,17 +7,14 @@
7 7
8Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode) 8Index::Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode)
9 : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)), 9 : mTransaction(Sink::Storage(storageRoot, name, mode).createTransaction(mode)),
10 mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Sink::Storage::Error &)>(), true)), 10 mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Sink::Storage::Error &)>(), true)),
11 mName(name) 11 mName(name)
12{ 12{
13
14} 13}
15 14
16Index::Index(const QByteArray &name, Sink::Storage::Transaction &transaction) 15Index::Index(const QByteArray &name, Sink::Storage::Transaction &transaction)
17 : mDb(transaction.openDatabase(name, std::function<void(const Sink::Storage::Error &)>(), true)), 16 : mDb(transaction.openDatabase(name, std::function<void(const Sink::Storage::Error &)>(), true)), mName(name)
18 mName(name)
19{ 17{
20
21} 18}
22 19
23void Index::add(const QByteArray &key, const QByteArray &value) 20void Index::add(const QByteArray &key, const QByteArray &value)
@@ -30,30 +27,23 @@ void Index::remove(const QByteArray &key, const QByteArray &value)
30 mDb.remove(key, value); 27 mDb.remove(key, value);
31} 28}
32 29
33void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, 30void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, const std::function<void(const Error &error)> &errorHandler, bool matchSubStringKeys)
34 const std::function<void(const Error &error)> &errorHandler, bool matchSubStringKeys)
35{ 31{
36 mDb.scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool { 32 mDb.scan(key,
37 resultHandler(value); 33 [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool {
38 return true; 34 resultHandler(value);
39 }, 35 return true;
40 [errorHandler](const Sink::Storage::Error &error) { 36 },
41 Warning() << "Error while retrieving value" << error.message; 37 [errorHandler](const Sink::Storage::Error &error) {
42 errorHandler(Error(error.store, error.code, error.message)); 38 Warning() << "Error while retrieving value" << error.message;
43 }, 39 errorHandler(Error(error.store, error.code, error.message));
44 matchSubStringKeys); 40 },
41 matchSubStringKeys);
45} 42}
46 43
47QByteArray Index::lookup(const QByteArray &key) 44QByteArray Index::lookup(const QByteArray &key)
48{ 45{
49 QByteArray result; 46 QByteArray result;
50 lookup(key, 47 lookup(key, [&result](const QByteArray &value) { result = value; }, [this](const Index::Error &error) { Trace() << "Error while retrieving value" << error.message; });
51 [&result](const QByteArray &value) {
52 result = value;
53 },
54 [this](const Index::Error &error) {
55 Trace() << "Error while retrieving value" << error.message;
56 });
57 return result; 48 return result;
58} 49}
59