mirror of
https://github.com/google/leveldb.git
synced 2025-01-27 06:30:07 +08:00
Put any object conveniently as below:
// ... User user; db_->Put("Tom", user); // or db_->Put("Tom", user, WriteOptions());
This commit is contained in:
parent
068d5ee1a3
commit
08e7397975
@ -66,6 +66,12 @@ class LEVELDB_EXPORT DB {
|
||||
virtual Status Put(const WriteOptions& options, const Slice& key,
|
||||
const Slice& value) = 0;
|
||||
|
||||
// Convenience wrapper
|
||||
Status Put(const Slice& key, const Slice& value,
|
||||
const WriteOptions& options = WriteOptions()) {
|
||||
return Put(options, key, value);
|
||||
};
|
||||
|
||||
// Remove the database entry (if any) for "key". Returns OK on
|
||||
// success, and a non-OK status on error. It is not an error if "key"
|
||||
// did not exist in the database.
|
||||
|
@ -35,6 +35,10 @@ class LEVELDB_EXPORT Slice {
|
||||
// Create a slice that refers to the contents of "s"
|
||||
Slice(const std::string& s) : data_(s.data()), size_(s.size()) {}
|
||||
|
||||
// For any object
|
||||
template<typename T>
|
||||
Slice(const T& s) : data_(reinterpret_cast<const char*>(&s)), size_(sizeof(T)) {}
|
||||
|
||||
// Create a slice that refers to s[0,strlen(s)-1]
|
||||
Slice(const char* s) : data_(s), size_(strlen(s)) {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user