blob: 20213b268df48cea9f325641243b488bddf9e6dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#pragma once
#include <string>
#include <functional>
#include <QString>
#include "storage.h"
/**
* An index for value pairs.
*/
class Index
{
public:
enum ErrorCodes {
IndexNotAvailable = -1
};
class Error
{
public:
Error(const QByteArray &s, int c, const QByteArray &m)
: store(s), message(m), code(c) {}
QByteArray store;
QByteArray message;
int code;
};
Index(const QString &storageRoot, const QString &name, Sink::Storage::AccessMode mode = Sink::Storage::ReadOnly);
Index(const QByteArray &name, Sink::Storage::Transaction &);
void add(const QByteArray &key, const QByteArray &value);
void remove(const QByteArray &key, const QByteArray &value);
void lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
const std::function<void(const Error &error)> &errorHandler);
QByteArray lookup(const QByteArray &key);
private:
Q_DISABLE_COPY(Index);
Sink::Storage::Transaction mTransaction;
Sink::Storage::NamedDatabase mDb;
};
|