#ifndef LevelDBDatabase_h
#define LevelDBDatabase_h
#if USE(LEVELDB)
#include <memory>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace leveldb {
class Comparator;
class DB;
class Env;
class Snapshot;
}
namespace WebCore {
class LevelDBComparator;
class LevelDBDatabase;
class LevelDBIterator;
class LevelDBSlice;
class LevelDBWriteBatch;
class LevelDBSnapshot {
private:
friend class LevelDBDatabase;
friend class LevelDBTransaction;
explicit LevelDBSnapshot(LevelDBDatabase*);
~LevelDBSnapshot();
leveldb::DB* m_db;
const leveldb::Snapshot* m_snapshot;
};
class LevelDBDatabase {
public:
static std::unique_ptr<LevelDBDatabase> open(const String& fileName, const LevelDBComparator*);
static std::unique_ptr<LevelDBDatabase> openInMemory(const LevelDBComparator*);
LevelDBDatabase();
static bool destroy(const String& fileName);
virtual ~LevelDBDatabase();
bool put(const LevelDBSlice& key, const Vector<char>& value);
bool remove(const LevelDBSlice& key);
virtual bool safeGet(const LevelDBSlice& key, Vector<char>& value, bool& found, const LevelDBSnapshot* = 0);
bool write(LevelDBWriteBatch&);
std::unique_ptr<LevelDBIterator> createIterator(const LevelDBSnapshot* = 0);
const LevelDBComparator* comparator() const;
private:
friend class LevelDBSnapshot;
std::unique_ptr<leveldb::Env> m_env;
std::unique_ptr<leveldb::Comparator> m_comparatorAdapter;
std::unique_ptr<leveldb::DB> m_db;
const LevelDBComparator* m_comparator;
};
}
#endif
#endif