summaryrefslogtreecommitdiffstats
path: root/common/storage.h
blob: 0b548fb3935c56859418350e22c249e1e180e397 (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
#pragma once

#include <string>
#include <QString>

class Storage {
public:
    enum TransactionType { ReadOnly, ReadWrite };

    Storage(const QString &storageRoot, const QString &name);
    ~Storage();
    bool isInTransaction() const;
    bool startTransaction(TransactionType type = ReadWrite);
    bool commitTransaction();
    void abortTransaction();
    bool write(const char *key, size_t keySize, const char *value, size_t valueSize);
    bool write(const std::string &sKey, const std::string &sValue);
    //Perhaps prefer iterators (assuming we need to be able to match multiple values
    bool read(const std::string &sKey, const std::function<void(const std::string &value)> &);
    bool read(const std::string &sKey, const std::function<void(void *ptr, int size)> &);

    qint64 diskUsage() const;
    void removeFromDisk() const;
private:
    class Private;
    Private * const d;
};