Browse Source

leveldb: Require C++11.

This CL switches the public headers to C++11 default and deleted constructors, and adds override to the relevant leveldb::EnvWrapper methods. This should be a good test for C++11 compiler support.

Once this CL settles, the rest of the codebase can be safely modernized to C++11.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=189873212
xry
costan 6 years ago
committed by Victor Costan
parent
commit
74f032ff6f
10 changed files with 101 additions and 89 deletions
  1. +8
    -3
      CMakeLists.txt
  2. +4
    -5
      include/leveldb/cache.h
  3. +5
    -6
      include/leveldb/db.h
  4. +63
    -58
      include/leveldb/env.h
  5. +2
    -1
      include/leveldb/filter_policy.h
  6. +4
    -4
      include/leveldb/iterator.h
  7. +4
    -2
      include/leveldb/slice.h
  8. +3
    -4
      include/leveldb/table.h
  9. +3
    -4
      include/leveldb/table_builder.h
  10. +5
    -2
      include/leveldb/write_batch.h

+ 8
- 3
CMakeLists.txt View File

@ -3,11 +3,16 @@
# found in the LICENSE file. See the AUTHORS file for names of contributors. # found in the LICENSE file. See the AUTHORS file for names of contributors.
cmake_minimum_required(VERSION 3.9) cmake_minimum_required(VERSION 3.9)
project(Leveldb VERSION 0.1.0 LANGUAGES C CXX)
project(Leveldb VERSION 1.21.0 LANGUAGES C CXX)
# This project can take advantage of C++11.
# This project can use C11, but will gracefully decay down to C89.
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS OFF)
# This project requires C++11.
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON) option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)

+ 4
- 5
include/leveldb/cache.h View File

@ -32,7 +32,10 @@ LEVELDB_EXPORT Cache* NewLRUCache(size_t capacity);
class LEVELDB_EXPORT Cache { class LEVELDB_EXPORT Cache {
public: public:
Cache() { }
Cache() = default;
Cache(const Cache&) = delete;
Cache& operator=(const Cache&) = delete;
// Destroys all existing entries by calling the "deleter" // Destroys all existing entries by calling the "deleter"
// function that was passed to the constructor. // function that was passed to the constructor.
@ -100,10 +103,6 @@ class LEVELDB_EXPORT Cache {
struct Rep; struct Rep;
Rep* rep_; Rep* rep_;
// No copying allowed
Cache(const Cache&);
void operator=(const Cache&);
}; };
} // namespace leveldb } // namespace leveldb

+ 5
- 6
include/leveldb/db.h View File

@ -53,7 +53,11 @@ class LEVELDB_EXPORT DB {
const std::string& name, const std::string& name,
DB** dbptr); DB** dbptr);
DB() { }
DB() = default;
DB(const DB&) = delete;
DB& operator=(const DB&) = delete;
virtual ~DB(); virtual ~DB();
// Set the database entry for "key" to "value". Returns OK on success, // Set the database entry for "key" to "value". Returns OK on success,
@ -142,11 +146,6 @@ class LEVELDB_EXPORT DB {
// Therefore the following call will compact the entire database: // Therefore the following call will compact the entire database:
// db->CompactRange(NULL, NULL); // db->CompactRange(NULL, NULL);
virtual void CompactRange(const Slice* begin, const Slice* end) = 0; virtual void CompactRange(const Slice* begin, const Slice* end) = 0;
private:
// No copying allowed
DB(const DB&);
void operator=(const DB&);
}; };
// Destroy the contents of the specified database. // Destroy the contents of the specified database.

+ 63
- 58
include/leveldb/env.h View File

@ -31,7 +31,11 @@ class WritableFile;
class LEVELDB_EXPORT Env { class LEVELDB_EXPORT Env {
public: public:
Env() { }
Env() = default;
Env(const Env&) = delete;
Env& operator=(const Env&) = delete;
virtual ~Env(); virtual ~Env();
// Return a default environment suitable for the current operating // Return a default environment suitable for the current operating
@ -162,17 +166,16 @@ class LEVELDB_EXPORT Env {
// Sleep/delay the thread for the prescribed number of micro-seconds. // Sleep/delay the thread for the prescribed number of micro-seconds.
virtual void SleepForMicroseconds(int micros) = 0; virtual void SleepForMicroseconds(int micros) = 0;
private:
// No copying allowed
Env(const Env&);
void operator=(const Env&);
}; };
// A file abstraction for reading sequentially through a file // A file abstraction for reading sequentially through a file
class LEVELDB_EXPORT SequentialFile { class LEVELDB_EXPORT SequentialFile {
public: public:
SequentialFile() { }
SequentialFile() = default;
SequentialFile(const SequentialFile&) = delete;
SequentialFile& operator=(const SequentialFile&) = delete;
virtual ~SequentialFile(); virtual ~SequentialFile();
// Read up to "n" bytes from the file. "scratch[0..n-1]" may be // Read up to "n" bytes from the file. "scratch[0..n-1]" may be
@ -193,17 +196,16 @@ class LEVELDB_EXPORT SequentialFile {
// //
// REQUIRES: External synchronization // REQUIRES: External synchronization
virtual Status Skip(uint64_t n) = 0; virtual Status Skip(uint64_t n) = 0;
private:
// No copying allowed
SequentialFile(const SequentialFile&);
void operator=(const SequentialFile&);
}; };
// A file abstraction for randomly reading the contents of a file. // A file abstraction for randomly reading the contents of a file.
class LEVELDB_EXPORT RandomAccessFile { class LEVELDB_EXPORT RandomAccessFile {
public: public:
RandomAccessFile() { }
RandomAccessFile() = default;
RandomAccessFile(const RandomAccessFile&) = delete;
RandomAccessFile& operator=(const RandomAccessFile&) = delete;
virtual ~RandomAccessFile(); virtual ~RandomAccessFile();
// Read up to "n" bytes from the file starting at "offset". // Read up to "n" bytes from the file starting at "offset".
@ -217,11 +219,6 @@ class LEVELDB_EXPORT RandomAccessFile {
// Safe for concurrent use by multiple threads. // Safe for concurrent use by multiple threads.
virtual Status Read(uint64_t offset, size_t n, Slice* result, virtual Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const = 0; char* scratch) const = 0;
private:
// No copying allowed
RandomAccessFile(const RandomAccessFile&);
void operator=(const RandomAccessFile&);
}; };
// A file abstraction for sequential writing. The implementation // A file abstraction for sequential writing. The implementation
@ -229,45 +226,42 @@ class LEVELDB_EXPORT RandomAccessFile {
// at a time to the file. // at a time to the file.
class LEVELDB_EXPORT WritableFile { class LEVELDB_EXPORT WritableFile {
public: public:
WritableFile() { }
WritableFile() = default;
WritableFile(const WritableFile&) = delete;
WritableFile& operator=(const WritableFile&) = delete;
virtual ~WritableFile(); virtual ~WritableFile();
virtual Status Append(const Slice& data) = 0; virtual Status Append(const Slice& data) = 0;
virtual Status Close() = 0; virtual Status Close() = 0;
virtual Status Flush() = 0; virtual Status Flush() = 0;
virtual Status Sync() = 0; virtual Status Sync() = 0;
private:
// No copying allowed
WritableFile(const WritableFile&);
void operator=(const WritableFile&);
}; };
// An interface for writing log messages. // An interface for writing log messages.
class LEVELDB_EXPORT Logger { class LEVELDB_EXPORT Logger {
public: public:
Logger() { }
Logger() = default;
Logger(const Logger&) = delete;
Logger& operator=(const Logger&) = delete;
virtual ~Logger(); virtual ~Logger();
// Write an entry to the log file with the specified format. // Write an entry to the log file with the specified format.
virtual void Logv(const char* format, va_list ap) = 0; virtual void Logv(const char* format, va_list ap) = 0;
private:
// No copying allowed
Logger(const Logger&);
void operator=(const Logger&);
}; };
// Identifies a locked file. // Identifies a locked file.
class LEVELDB_EXPORT FileLock { class LEVELDB_EXPORT FileLock {
public: public:
FileLock() { }
FileLock() = default;
FileLock(const FileLock&) = delete;
FileLock& operator=(const FileLock&) = delete;
virtual ~FileLock(); virtual ~FileLock();
private:
// No copying allowed
FileLock(const FileLock&);
void operator=(const FileLock&);
}; };
// Log the specified data to *info_log if info_log is non-NULL. // Log the specified data to *info_log if info_log is non-NULL.
@ -290,61 +284,72 @@ LEVELDB_EXPORT Status ReadFileToString(Env* env, const std::string& fname,
// functionality of another Env. // functionality of another Env.
class LEVELDB_EXPORT EnvWrapper : public Env { class LEVELDB_EXPORT EnvWrapper : public Env {
public: public:
// Initialize an EnvWrapper that delegates all calls to *t
// Initialize an EnvWrapper that delegates all calls to *t.
explicit EnvWrapper(Env* t) : target_(t) { } explicit EnvWrapper(Env* t) : target_(t) { }
virtual ~EnvWrapper(); virtual ~EnvWrapper();
// Return the target to which this Env forwards all calls
// Return the target to which this Env forwards all calls.
Env* target() const { return target_; } Env* target() const { return target_; }
// The following text is boilerplate that forwards all methods to target()
Status NewSequentialFile(const std::string& f, SequentialFile** r) {
// The following text is boilerplate that forwards all methods to target().
Status NewSequentialFile(const std::string& f, SequentialFile** r) override {
return target_->NewSequentialFile(f, r); return target_->NewSequentialFile(f, r);
} }
Status NewRandomAccessFile(const std::string& f, RandomAccessFile** r) {
Status NewRandomAccessFile(const std::string& f,
RandomAccessFile** r) override {
return target_->NewRandomAccessFile(f, r); return target_->NewRandomAccessFile(f, r);
} }
Status NewWritableFile(const std::string& f, WritableFile** r) {
Status NewWritableFile(const std::string& f, WritableFile** r) override {
return target_->NewWritableFile(f, r); return target_->NewWritableFile(f, r);
} }
Status NewAppendableFile(const std::string& f, WritableFile** r) {
Status NewAppendableFile(const std::string& f, WritableFile** r) override {
return target_->NewAppendableFile(f, r); return target_->NewAppendableFile(f, r);
} }
bool FileExists(const std::string& f) { return target_->FileExists(f); }
Status GetChildren(const std::string& dir, std::vector<std::string>* r) {
bool FileExists(const std::string& f) override {
return target_->FileExists(f);
}
Status GetChildren(const std::string& dir,
std::vector<std::string>* r) override {
return target_->GetChildren(dir, r); return target_->GetChildren(dir, r);
} }
Status DeleteFile(const std::string& f) { return target_->DeleteFile(f); }
Status CreateDir(const std::string& d) { return target_->CreateDir(d); }
Status DeleteDir(const std::string& d) { return target_->DeleteDir(d); }
Status GetFileSize(const std::string& f, uint64_t* s) {
Status DeleteFile(const std::string& f) override {
return target_->DeleteFile(f);
}
Status CreateDir(const std::string& d) override {
return target_->CreateDir(d);
}
Status DeleteDir(const std::string& d) override {
return target_->DeleteDir(d);
}
Status GetFileSize(const std::string& f, uint64_t* s) override {
return target_->GetFileSize(f, s); return target_->GetFileSize(f, s);
} }
Status RenameFile(const std::string& s, const std::string& t) {
Status RenameFile(const std::string& s, const std::string& t) override {
return target_->RenameFile(s, t); return target_->RenameFile(s, t);
} }
Status LockFile(const std::string& f, FileLock** l) {
Status LockFile(const std::string& f, FileLock** l) override {
return target_->LockFile(f, l); return target_->LockFile(f, l);
} }
Status UnlockFile(FileLock* l) { return target_->UnlockFile(l); }
void Schedule(void (*f)(void*), void* a) {
Status UnlockFile(FileLock* l) override { return target_->UnlockFile(l); }
void Schedule(void (*f)(void*), void* a) override {
return target_->Schedule(f, a); return target_->Schedule(f, a);
} }
void StartThread(void (*f)(void*), void* a) {
void StartThread(void (*f)(void*), void* a) override {
return target_->StartThread(f, a); return target_->StartThread(f, a);
} }
virtual Status GetTestDirectory(std::string* path) {
Status GetTestDirectory(std::string* path) override {
return target_->GetTestDirectory(path); return target_->GetTestDirectory(path);
} }
virtual Status NewLogger(const std::string& fname, Logger** result) {
Status NewLogger(const std::string& fname, Logger** result) override {
return target_->NewLogger(fname, result); return target_->NewLogger(fname, result);
} }
uint64_t NowMicros() {
uint64_t NowMicros() override {
return target_->NowMicros(); return target_->NowMicros();
} }
void SleepForMicroseconds(int micros) {
void SleepForMicroseconds(int micros) override {
target_->SleepForMicroseconds(micros); target_->SleepForMicroseconds(micros);
} }
private: private:
Env* target_; Env* target_;
}; };

+ 2
- 1
include/leveldb/filter_policy.h View File

@ -65,6 +65,7 @@ class LEVELDB_EXPORT FilterPolicy {
// FilterPolicy (like NewBloomFilterPolicy) that does not ignore // FilterPolicy (like NewBloomFilterPolicy) that does not ignore
// trailing spaces in keys. // trailing spaces in keys.
LEVELDB_EXPORT const FilterPolicy* NewBloomFilterPolicy(int bits_per_key); LEVELDB_EXPORT const FilterPolicy* NewBloomFilterPolicy(int bits_per_key);
}
} // namespace leveldb
#endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ #endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_

+ 4
- 4
include/leveldb/iterator.h View File

@ -24,6 +24,10 @@ namespace leveldb {
class LEVELDB_EXPORT Iterator { class LEVELDB_EXPORT Iterator {
public: public:
Iterator(); Iterator();
Iterator(const Iterator&) = delete;
Iterator& operator=(const Iterator&) = delete;
virtual ~Iterator(); virtual ~Iterator();
// An iterator is either positioned at a key/value pair, or // An iterator is either positioned at a key/value pair, or
@ -84,10 +88,6 @@ class LEVELDB_EXPORT Iterator {
Cleanup* next; Cleanup* next;
}; };
Cleanup cleanup_; Cleanup cleanup_;
// No copying allowed
Iterator(const Iterator&);
void operator=(const Iterator&);
}; };
// Return an empty iterator (yields nothing). // Return an empty iterator (yields nothing).

+ 4
- 2
include/leveldb/slice.h View File

@ -37,6 +37,10 @@ class LEVELDB_EXPORT Slice {
// Create a slice that refers to s[0,strlen(s)-1] // Create a slice that refers to s[0,strlen(s)-1]
Slice(const char* s) : data_(s), size_(strlen(s)) { } Slice(const char* s) : data_(s), size_(strlen(s)) { }
// Intentionally copyable.
Slice(const Slice&) = default;
Slice& operator=(const Slice&) = default;
// Return a pointer to the beginning of the referenced data // Return a pointer to the beginning of the referenced data
const char* data() const { return data_; } const char* data() const { return data_; }
@ -81,8 +85,6 @@ class LEVELDB_EXPORT Slice {
private: private:
const char* data_; const char* data_;
size_t size_; size_t size_;
// Intentionally copyable
}; };
inline bool operator==(const Slice& x, const Slice& y) { inline bool operator==(const Slice& x, const Slice& y) {

+ 3
- 4
include/leveldb/table.h View File

@ -41,6 +41,9 @@ class LEVELDB_EXPORT Table {
uint64_t file_size, uint64_t file_size,
Table** table); Table** table);
Table(const Table&) = delete;
void operator=(const Table&) = delete;
~Table(); ~Table();
// Returns a new iterator over the table contents. // Returns a new iterator over the table contents.
@ -75,10 +78,6 @@ class LEVELDB_EXPORT Table {
void ReadMeta(const Footer& footer); void ReadMeta(const Footer& footer);
void ReadFilter(const Slice& filter_handle_value); void ReadFilter(const Slice& filter_handle_value);
// No copying allowed
Table(const Table&);
void operator=(const Table&);
}; };
} // namespace leveldb } // namespace leveldb

+ 3
- 4
include/leveldb/table_builder.h View File

@ -31,6 +31,9 @@ class LEVELDB_EXPORT TableBuilder {
// caller to close the file after calling Finish(). // caller to close the file after calling Finish().
TableBuilder(const Options& options, WritableFile* file); TableBuilder(const Options& options, WritableFile* file);
TableBuilder(const TableBuilder&) = delete;
void operator=(const TableBuilder&) = delete;
// REQUIRES: Either Finish() or Abandon() has been called. // REQUIRES: Either Finish() or Abandon() has been called.
~TableBuilder(); ~TableBuilder();
@ -82,10 +85,6 @@ class LEVELDB_EXPORT TableBuilder {
struct Rep; struct Rep;
Rep* rep_; Rep* rep_;
// No copying allowed
TableBuilder(const TableBuilder&);
void operator=(const TableBuilder&);
}; };
} // namespace leveldb } // namespace leveldb

+ 5
- 2
include/leveldb/write_batch.h View File

@ -32,6 +32,11 @@ class Slice;
class LEVELDB_EXPORT WriteBatch { class LEVELDB_EXPORT WriteBatch {
public: public:
WriteBatch(); WriteBatch();
// Intentionally copyable.
WriteBatch(const WriteBatch&) = default;
WriteBatch& operator =(const WriteBatch&) = default;
~WriteBatch(); ~WriteBatch();
// Store the mapping "key->value" in the database. // Store the mapping "key->value" in the database.
@ -62,8 +67,6 @@ class LEVELDB_EXPORT WriteBatch {
friend class WriteBatchInternal; friend class WriteBatchInternal;
std::string rep_; // See comment in write_batch.cc for the format of rep_ std::string rep_; // See comment in write_batch.cc for the format of rep_
// Intentionally copyable
}; };
} // namespace leveldb } // namespace leveldb

Loading…
Cancel
Save