/
tokyo-base.hh
70 lines (54 loc) · 1.29 KB
/
tokyo-base.hh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef TOKYO_BASE_H
#define TOKYO_BASE_H 1
#include "base-test.hh"
#include <stdlib.h>
#include <stdint.h>
#include <tcutil.h>
#include <tchdb.h>
#define ERRSTR_SIZE 64
namespace kvtest {
/**
* A Tokyo Cabinet DB store.
*/
class TokyoStore : public KVStore {
public:
/**
* Get a TokyoStore.
*
* @param p the path to the file holding the db
* @param should_autocommit if true, sync after every set
*/
TokyoStore(char const *p, bool should_autocommit=true);
~TokyoStore() {
close();
}
/**
* Overrides reset().
*/
void reset();
/**
* Commit a transaction (unless not currently in one).
*/
void commit();
/**
* Overrides set().
*/
void set(std::string &key, std::string &val, Callback<bool> &cb);
/**
* Overrides get().
*/
void get(std::string &key, Callback<GetValue> &cb);
/**
* Overrides del().
*/
void del(std::string &key, Callback<bool> &cb);
private:
TCHDB *hdb;
int ecode;
const char *path;
bool autocommit;
void open();
void close();
};
}
#endif /* TOKYO_BASE_H */