/usr/include/caffe/util/db_leveldb.hpp is in libcaffe-cpu-dev 1.0.0~rc4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 71 72 73 74 75 76 77 78 | #ifdef USE_LEVELDB
#ifndef CAFFE_UTIL_DB_LEVELDB_HPP
#define CAFFE_UTIL_DB_LEVELDB_HPP
#include <string>
#include "leveldb/db.h"
#include "leveldb/write_batch.h"
#include "caffe/util/db.hpp"
namespace caffe { namespace db {
class LevelDBCursor : public Cursor {
public:
explicit LevelDBCursor(leveldb::Iterator* iter)
: iter_(iter) {
SeekToFirst();
CHECK(iter_->status().ok()) << iter_->status().ToString();
}
~LevelDBCursor() { delete iter_; }
virtual void SeekToFirst() { iter_->SeekToFirst(); }
virtual void Next() { iter_->Next(); }
virtual string key() { return iter_->key().ToString(); }
virtual string value() { return iter_->value().ToString(); }
virtual bool valid() { return iter_->Valid(); }
private:
leveldb::Iterator* iter_;
};
class LevelDBTransaction : public Transaction {
public:
explicit LevelDBTransaction(leveldb::DB* db) : db_(db) { CHECK_NOTNULL(db_); }
virtual void Put(const string& key, const string& value) {
batch_.Put(key, value);
}
virtual void Commit() {
leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);
CHECK(status.ok()) << "Failed to write batch to leveldb "
<< std::endl << status.ToString();
}
private:
leveldb::DB* db_;
leveldb::WriteBatch batch_;
DISABLE_COPY_AND_ASSIGN(LevelDBTransaction);
};
class LevelDB : public DB {
public:
LevelDB() : db_(NULL) { }
virtual ~LevelDB() { Close(); }
virtual void Open(const string& source, Mode mode);
virtual void Close() {
if (db_ != NULL) {
delete db_;
db_ = NULL;
}
}
virtual LevelDBCursor* NewCursor() {
return new LevelDBCursor(db_->NewIterator(leveldb::ReadOptions()));
}
virtual LevelDBTransaction* NewTransaction() {
return new LevelDBTransaction(db_);
}
private:
leveldb::DB* db_;
};
} // namespace db
} // namespace caffe
#endif // CAFFE_UTIL_DB_LEVELDB_HPP
#endif // USE_LEVELDB
|