summaryrefslogtreecommitdiffstats
path: root/common/index.h
blob: 3cd7cc821a5e3762347d36bf35fbd67a78577dd6 (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
#pragma once

#include <string>
#include <functional>
#include <QString>
#include "storage.h"

/**
 * An index for value pairs.
 */
class Index
{
public:
    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, Akonadi2::Storage::AccessMode mode = Akonadi2::Storage::ReadOnly);

    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);

private:
    Q_DISABLE_COPY(Index);
    Akonadi2::Storage mStorage;
};