diff --git a/db/auto_roll_logger.cc b/db/auto_roll_logger.cc index 8118b23777..0fb2a1d2a4 100644 --- a/db/auto_roll_logger.cc +++ b/db/auto_roll_logger.cc @@ -6,8 +6,6 @@ #include "db/auto_roll_logger.h" #include "util/mutexlock.h" -using namespace std; - namespace rocksdb { // -- AutoRollLogger @@ -47,7 +45,8 @@ void AutoRollLogger::RollLogFile() { env_->RenameFile(log_fname_, old_fname); } -string AutoRollLogger::ValistToString(const char* format, va_list args) const { +std::string AutoRollLogger::ValistToString(const char* format, + va_list args) const { // Any log messages longer than 1024 will get truncated. // The user is responsible for chopping longer messages into multi line log static const int MAXBUFFERSIZE = 1024; @@ -112,7 +111,7 @@ void AutoRollLogger::LogHeader(const char* format, va_list args) { // strings va_list tmp; va_copy(tmp, args); - string data = ValistToString(format, tmp); + std::string data = ValistToString(format, tmp); va_end(tmp); MutexLock l(&mutex_); diff --git a/db/auto_roll_logger_test.cc b/db/auto_roll_logger_test.cc index ecb6051028..6c72930296 100644 --- a/db/auto_roll_logger_test.cc +++ b/db/auto_roll_logger_test.cc @@ -19,8 +19,6 @@ #include #include -using namespace std; - namespace rocksdb { class AutoRollLoggerTest : public testing::Test { @@ -40,23 +38,22 @@ class AutoRollLoggerTest : public testing::Test { Env::Default()->CreateDir(kTestDir); } - void RollLogFileBySizeTest(AutoRollLogger* logger, - size_t log_max_size, - const string& log_message); - uint64_t RollLogFileByTimeTest(AutoRollLogger* logger, - size_t time, - const string& log_message); + void RollLogFileBySizeTest(AutoRollLogger* logger, size_t log_max_size, + const std::string& log_message); + uint64_t RollLogFileByTimeTest(AutoRollLogger* logger, size_t time, + const std::string& log_message); - static const string kSampleMessage; - static const string kTestDir; - static const string kLogFile; + static const std::string kSampleMessage; + static const std::string kTestDir; + static const std::string kLogFile; static Env* env; }; -const string AutoRollLoggerTest::kSampleMessage( +const std::string AutoRollLoggerTest::kSampleMessage( "this is the message to be written to the log file!!"); -const string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test"); -const string AutoRollLoggerTest::kLogFile(test::TmpDir() + "/db_log_test/LOG"); +const std::string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test"); +const std::string AutoRollLoggerTest::kLogFile(test::TmpDir() + + "/db_log_test/LOG"); Env* AutoRollLoggerTest::env = Env::Default(); // In this test we only want to Log some simple log message with @@ -86,7 +83,7 @@ void GetFileCreateTime(const std::string& fname, uint64_t* file_ctime) { void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger, size_t log_max_size, - const string& log_message) { + const std::string& log_message) { logger->SetInfoLogLevel(InfoLogLevel::INFO_LEVEL); // measure the size of each message, which is supposed // to be equal or greater than log_message.size() @@ -111,7 +108,7 @@ void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger, } uint64_t AutoRollLoggerTest::RollLogFileByTimeTest( - AutoRollLogger* logger, size_t time, const string& log_message) { + AutoRollLogger* logger, size_t time, const std::string& log_message) { uint64_t expected_create_time; uint64_t actual_create_time; uint64_t total_log_size; @@ -361,13 +358,13 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) { // Test the logger Header function for roll over logs // We expect the new logs creates as roll over to carry the headers specified -static std::vector GetOldFileNames(const string& path) { - std::vector ret; +static std::vector GetOldFileNames(const std::string& path) { + std::vector ret; - const string dirname = path.substr(/*start=*/ 0, path.find_last_of("/")); - const string fname = path.substr(path.find_last_of("/") + 1); + const std::string dirname = path.substr(/*start=*/0, path.find_last_of("/")); + const std::string fname = path.substr(path.find_last_of("/") + 1); - std::vector children; + std::vector children; Env::Default()->GetChildren(dirname, &children); // We know that the old log files are named [path] @@ -382,12 +379,13 @@ static std::vector GetOldFileNames(const string& path) { } // Return the number of lines where a given pattern was found in the file -static size_t GetLinesCount(const string& fname, const string& pattern) { - stringstream ssbuf; - string line; +static size_t GetLinesCount(const std::string& fname, + const std::string& pattern) { + std::stringstream ssbuf; + std::string line; size_t count = 0; - ifstream inFile(fname.c_str()); + std::ifstream inFile(fname.c_str()); ssbuf << inFile.rdbuf(); while (getline(ssbuf, line)) { @@ -426,7 +424,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) { } } - const string newfname = logger.TEST_log_fname(); + const std::string newfname = logger.TEST_log_fname(); // Log enough data to cause a roll over int i = 0; @@ -466,7 +464,7 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) { [](char ch) { return ch == '/'; }, '\\'); std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; #else - string deleteCmd = "rm -rf " + kTestDir; + std::string deleteCmd = "rm -rf " + kTestDir; #endif ASSERT_EQ(system(deleteCmd.c_str()), 0); options.max_log_file_size = 100 * 1024 * 1024; diff --git a/db/column_family_test.cc b/db/column_family_test.cc index f8ebec57fb..c795cf213a 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -447,7 +447,7 @@ TEST_F(ColumnFamilyTest, AddDrop) { std::vector families; ASSERT_OK(DB::ListColumnFamilies(db_options_, dbname_, &families)); - sort(families.begin(), families.end()); + std::sort(families.begin(), families.end()); ASSERT_TRUE(families == std::vector({"default", "four", "three"})); } diff --git a/db/db_impl.cc b/db/db_impl.cc index d86f32bb66..8191d291cb 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -909,9 +909,11 @@ void DBImpl::PurgeObsoleteFiles(const JobContext& state) { // dedup state.candidate_files so we don't try to delete the same // file twice - sort(candidate_files.begin(), candidate_files.end(), CompareCandidateFile); - candidate_files.erase(unique(candidate_files.begin(), candidate_files.end()), - candidate_files.end()); + std::sort(candidate_files.begin(), candidate_files.end(), + CompareCandidateFile); + candidate_files.erase( + std::unique(candidate_files.begin(), candidate_files.end()), + candidate_files.end()); std::vector old_info_log_files; InfoLogPrefix info_log_prefix(!db_options_.db_log_dir.empty(), dbname_); diff --git a/db/db_test.cc b/db/db_test.cc index f49337a54b..4160cfe3e9 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2681,7 +2681,7 @@ TEST_F(DBTest, GroupCommitTest) { for (int i = 0; i < kGCNumThreads * kGCNumKeys; ++i) { expected_db.push_back(ToString(i)); } - sort(expected_db.begin(), expected_db.end()); + std::sort(expected_db.begin(), expected_db.end()); Iterator* itr = db_->NewIterator(ReadOptions()); itr->SeekToFirst(); diff --git a/db/transaction_log_impl.cc b/db/transaction_log_impl.cc index 8002d935fe..91ed054127 100644 --- a/db/transaction_log_impl.cc +++ b/db/transaction_log_impl.cc @@ -8,8 +8,8 @@ #define __STDC_FORMAT_MACROS #endif -#include #include "db/transaction_log_impl.h" +#include #include "db/write_batch_internal.h" #include "util/file_reader_writer.h" @@ -250,7 +250,7 @@ void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) { // currentBatchSeq_ can only change here assert(currentLastSeq_ <= versions_->LastSequence()); - currentBatch_ = move(batch); + currentBatch_ = std::move(batch); isValid_ = true; currentStatus_ = Status::OK(); } @@ -262,10 +262,9 @@ Status TransactionLogIteratorImpl::OpenLogReader(const LogFile* logFile) { return s; } assert(file); - currentLogReader_.reset(new log::Reader(options_->info_log, - std::move(file), &reporter_, - read_options_.verify_checksums_, 0, - logFile->LogNumber())); + currentLogReader_.reset(new log::Reader( + options_->info_log, std::move(file), &reporter_, + read_options_.verify_checksums_, 0, logFile->LogNumber())); return Status::OK(); } } // namespace rocksdb diff --git a/db/version_set.cc b/db/version_set.cc index 2ace7a5be0..0381f736f7 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1552,11 +1552,11 @@ void VersionStorageInfo::GenerateLevel0NonOverlapping() { std::vector level0_sorted_file( level_files_brief_[0].files, level_files_brief_[0].files + level_files_brief_[0].num_files); - sort(level0_sorted_file.begin(), level0_sorted_file.end(), - [this](const FdWithKeyRange & f1, const FdWithKeyRange & f2)->bool { - return (internal_comparator_->Compare(f1.smallest_key, f2.smallest_key) < - 0); - }); + std::sort(level0_sorted_file.begin(), level0_sorted_file.end(), + [this](const FdWithKeyRange& f1, const FdWithKeyRange& f2) -> bool { + return (internal_comparator_->Compare(f1.smallest_key, + f2.smallest_key) < 0); + }); for (size_t i = 1; i < level0_sorted_file.size(); ++i) { FdWithKeyRange& f = level0_sorted_file[i]; diff --git a/port/win/xpress_win.cc b/port/win/xpress_win.cc index e183078eab..a0206b5780 100644 --- a/port/win/xpress_win.cc +++ b/port/win/xpress_win.cc @@ -189,9 +189,8 @@ char* Decompress(const char* input_data, size_t input_length, if (!success) { #ifdef _DEBUG - std::cerr << - "XPRESS: Failed to create Decompressor LastError " << - GetLastError() << std::endl; + std::cerr << "XPRESS: Failed to create Decompressor LastError " + << GetLastError() << std::endl; #endif return nullptr; } @@ -215,9 +214,9 @@ char* Decompress(const char* input_data, size_t input_length, if (lastError != ERROR_INSUFFICIENT_BUFFER) { #ifdef _DEBUG - std::cerr << - "XPRESS: Failed to estimate decompressed buffer size LastError " << - lastError << std::endl; + std::cerr + << "XPRESS: Failed to estimate decompressed buffer size LastError " + << lastError << std::endl; #endif return nullptr; } @@ -266,5 +265,3 @@ char* Decompress(const char* input_data, size_t input_length, } #endif - - diff --git a/tools/db_stress.cc b/tools/db_stress.cc index b01437d1b7..c78205dd11 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -2152,8 +2152,9 @@ class StressTest { // this is a reopen. just assert that existing column_family_names are // equivalent to what we remember auto sorted_cfn = column_family_names_; - sort(sorted_cfn.begin(), sorted_cfn.end()); - sort(existing_column_families.begin(), existing_column_families.end()); + std::sort(sorted_cfn.begin(), sorted_cfn.end()); + std::sort(existing_column_families.begin(), + existing_column_families.end()); if (sorted_cfn != existing_column_families) { fprintf(stderr, "Expected column families differ from the existing:\n"); diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index 3ab1371336..b226614e01 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -40,33 +40,31 @@ namespace rocksdb { -using namespace std; - -const string LDBCommand::ARG_DB = "db"; -const string LDBCommand::ARG_PATH = "path"; -const string LDBCommand::ARG_HEX = "hex"; -const string LDBCommand::ARG_KEY_HEX = "key_hex"; -const string LDBCommand::ARG_VALUE_HEX = "value_hex"; -const string LDBCommand::ARG_CF_NAME = "column_family"; -const string LDBCommand::ARG_TTL = "ttl"; -const string LDBCommand::ARG_TTL_START = "start_time"; -const string LDBCommand::ARG_TTL_END = "end_time"; -const string LDBCommand::ARG_TIMESTAMP = "timestamp"; -const string LDBCommand::ARG_FROM = "from"; -const string LDBCommand::ARG_TO = "to"; -const string LDBCommand::ARG_MAX_KEYS = "max_keys"; -const string LDBCommand::ARG_BLOOM_BITS = "bloom_bits"; -const string LDBCommand::ARG_FIX_PREFIX_LEN = "fix_prefix_len"; -const string LDBCommand::ARG_COMPRESSION_TYPE = "compression_type"; -const string LDBCommand::ARG_COMPRESSION_MAX_DICT_BYTES = +const std::string LDBCommand::ARG_DB = "db"; +const std::string LDBCommand::ARG_PATH = "path"; +const std::string LDBCommand::ARG_HEX = "hex"; +const std::string LDBCommand::ARG_KEY_HEX = "key_hex"; +const std::string LDBCommand::ARG_VALUE_HEX = "value_hex"; +const std::string LDBCommand::ARG_CF_NAME = "column_family"; +const std::string LDBCommand::ARG_TTL = "ttl"; +const std::string LDBCommand::ARG_TTL_START = "start_time"; +const std::string LDBCommand::ARG_TTL_END = "end_time"; +const std::string LDBCommand::ARG_TIMESTAMP = "timestamp"; +const std::string LDBCommand::ARG_FROM = "from"; +const std::string LDBCommand::ARG_TO = "to"; +const std::string LDBCommand::ARG_MAX_KEYS = "max_keys"; +const std::string LDBCommand::ARG_BLOOM_BITS = "bloom_bits"; +const std::string LDBCommand::ARG_FIX_PREFIX_LEN = "fix_prefix_len"; +const std::string LDBCommand::ARG_COMPRESSION_TYPE = "compression_type"; +const std::string LDBCommand::ARG_COMPRESSION_MAX_DICT_BYTES = "compression_max_dict_bytes"; -const string LDBCommand::ARG_BLOCK_SIZE = "block_size"; -const string LDBCommand::ARG_AUTO_COMPACTION = "auto_compaction"; -const string LDBCommand::ARG_DB_WRITE_BUFFER_SIZE = "db_write_buffer_size"; -const string LDBCommand::ARG_WRITE_BUFFER_SIZE = "write_buffer_size"; -const string LDBCommand::ARG_FILE_SIZE = "file_size"; -const string LDBCommand::ARG_CREATE_IF_MISSING = "create_if_missing"; -const string LDBCommand::ARG_NO_VALUE = "no_value"; +const std::string LDBCommand::ARG_BLOCK_SIZE = "block_size"; +const std::string LDBCommand::ARG_AUTO_COMPACTION = "auto_compaction"; +const std::string LDBCommand::ARG_DB_WRITE_BUFFER_SIZE = "db_write_buffer_size"; +const std::string LDBCommand::ARG_WRITE_BUFFER_SIZE = "write_buffer_size"; +const std::string LDBCommand::ARG_FILE_SIZE = "file_size"; +const std::string LDBCommand::ARG_CREATE_IF_MISSING = "create_if_missing"; +const std::string LDBCommand::ARG_NO_VALUE = "no_value"; const char* LDBCommand::DELIM = " ==> "; @@ -82,7 +80,7 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( int argc, char** argv, const Options& options, const LDBOptions& ldb_options, const std::vector* column_families) { - vector args; + std::vector args; for (int i = 1; i < argc; i++) { args.push_back(argv[i]); } @@ -102,30 +100,30 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( */ template LDBCommand* LDBCommand::InitFromCmdLineArgs( - const vector& args, const Options& options, + const std::vector& args, const Options& options, const LDBOptions& ldb_options, const std::vector* column_families, Selector selector) { // --x=y command line arguments are added as x->y map entries. - map option_map; + std::map option_map; // Command-line arguments of the form --hex end up in this array as hex - vector flags; + std::vector flags; // Everything other than option_map and flags. Represents commands // and their parameters. For eg: put key1 value1 go into this vector. - vector cmdTokens; + std::vector cmdTokens; - const string OPTION_PREFIX = "--"; + const std::string OPTION_PREFIX = "--"; for (const auto& arg : args) { if (arg[0] == '-' && arg[1] == '-'){ - vector splits = StringSplit(arg, '='); + std::vector splits = StringSplit(arg, '='); if (splits.size() == 2) { - string optionKey = splits[0].substr(OPTION_PREFIX.size()); + std::string optionKey = splits[0].substr(OPTION_PREFIX.size()); option_map[optionKey] = splits[1]; } else { - string optionKey = splits[0].substr(OPTION_PREFIX.size()); + std::string optionKey = splits[0].substr(OPTION_PREFIX.size()); flags.push_back(optionKey); } } else { @@ -138,8 +136,8 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( return nullptr; } - string cmd = cmdTokens[0]; - vector cmdParams(cmdTokens.begin()+1, cmdTokens.end()); + std::string cmd = cmdTokens[0]; + std::vector cmdParams(cmdTokens.begin() + 1, cmdTokens.end()); LDBCommand* command = selector(cmd, cmdParams, option_map, flags); if (command) { @@ -150,12 +148,9 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs( } LDBCommand* LDBCommand::SelectCommand( - const std::string& cmd, - const vector& cmdParams, - const map& option_map, - const vector& flags - ) { - + const std::string& cmd, const std::vector& cmdParams, + const std::map& option_map, + const std::vector& flags) { if (cmd == GetCommand::Name()) { return new GetCommand(cmdParams, option_map, flags); } else if (cmd == PutCommand::Name()) { @@ -223,9 +218,9 @@ void LDBCommand::Run() { } } -LDBCommand::LDBCommand(const map& options, - const vector& flags, bool is_read_only, - const vector& valid_cmd_line_options) +LDBCommand::LDBCommand(const std::map& options, + const std::vector& flags, bool is_read_only, + const std::vector& valid_cmd_line_options) : db_(nullptr), is_read_only_(is_read_only), is_key_hex_(false), @@ -235,7 +230,7 @@ LDBCommand::LDBCommand(const map& options, option_map_(options), flags_(flags), valid_cmd_line_options_(valid_cmd_line_options) { - map::const_iterator itr = options.find(ARG_DB); + std::map::const_iterator itr = options.find(ARG_DB); if (itr != options.end()) { db_path_ = itr->second; } @@ -305,7 +300,7 @@ void LDBCommand::OpenDB() { } } if (!st.ok()) { - string msg = st.ToString(); + std::string msg = st.ToString(); exec_state_ = LDBCommandExecuteResult::Failed(msg); } else if (!handles_opened.empty()) { assert(handles_opened.size() == column_families_.size()); @@ -357,17 +352,18 @@ ColumnFamilyHandle* LDBCommand::GetCfHandle() { return db_->DefaultColumnFamily(); } -vector LDBCommand::BuildCmdLineOptions(vector options) { - vector ret = {ARG_DB, - ARG_BLOOM_BITS, - ARG_BLOCK_SIZE, - ARG_AUTO_COMPACTION, - ARG_COMPRESSION_TYPE, - ARG_COMPRESSION_MAX_DICT_BYTES, - ARG_WRITE_BUFFER_SIZE, - ARG_FILE_SIZE, - ARG_FIX_PREFIX_LEN, - ARG_CF_NAME}; +std::vector LDBCommand::BuildCmdLineOptions( + std::vector options) { + std::vector ret = {ARG_DB, + ARG_BLOOM_BITS, + ARG_BLOCK_SIZE, + ARG_AUTO_COMPACTION, + ARG_COMPRESSION_TYPE, + ARG_COMPRESSION_MAX_DICT_BYTES, + ARG_WRITE_BUFFER_SIZE, + ARG_FILE_SIZE, + ARG_FIX_PREFIX_LEN, + ARG_CF_NAME}; ret.insert(ret.end(), options.begin(), options.end()); return ret; } @@ -379,23 +375,24 @@ vector LDBCommand::BuildCmdLineOptions(vector options) { * value. If there is an error, the specified exec_state is also * updated. */ -bool LDBCommand::ParseIntOption(const map& options, - const string& option, int& value, - LDBCommandExecuteResult& exec_state) { - - map::const_iterator itr = option_map_.find(option); +bool LDBCommand::ParseIntOption( + const std::map& options, + const std::string& option, int& value, + LDBCommandExecuteResult& exec_state) { + std::map::const_iterator itr = + option_map_.find(option); if (itr != option_map_.end()) { try { #if defined(CYGWIN) value = strtol(itr->second.c_str(), 0, 10); #else - value = stoi(itr->second); + value = std::stoi(itr->second); #endif return true; - } catch(const invalid_argument&) { + } catch (const std::invalid_argument&) { exec_state = LDBCommandExecuteResult::Failed(option + " has an invalid value."); - } catch(const out_of_range&) { + } catch (const std::out_of_range&) { exec_state = LDBCommandExecuteResult::Failed( option + " has a value out-of-range."); } @@ -408,8 +405,9 @@ bool LDBCommand::ParseIntOption(const map& options, * Returns true if the option is found. * Returns false otherwise. */ -bool LDBCommand::ParseStringOption(const map& options, - const string& option, string* value) { +bool LDBCommand::ParseStringOption( + const std::map& options, + const std::string& option, std::string* value) { auto itr = option_map_.find(option); if (itr != option_map_.end()) { *value = itr->second; @@ -423,7 +421,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() { Options opt = options_; opt.create_if_missing = false; - map::const_iterator itr; + std::map::const_iterator itr; BlockBasedTableOptions table_options; bool use_table_options = false; @@ -460,7 +458,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() { itr = option_map_.find(ARG_COMPRESSION_TYPE); if (itr != option_map_.end()) { - string comp = itr->second; + std::string comp = itr->second; if (comp == "no") { opt.compression = kNoCompression; } else if (comp == "snappy") { @@ -546,10 +544,11 @@ Options LDBCommand::PrepareOptionsForOpenDB() { return opt; } -bool LDBCommand::ParseKeyValue(const string& line, string* key, string* value, - bool is_key_hex, bool is_value_hex) { +bool LDBCommand::ParseKeyValue(const std::string& line, std::string* key, + std::string* value, bool is_key_hex, + bool is_value_hex) { size_t pos = line.find(DELIM); - if (pos != string::npos) { + if (pos != std::string::npos) { *key = line.substr(0, pos); *value = line.substr(pos + strlen(DELIM)); if (is_key_hex) { @@ -572,22 +571,22 @@ bool LDBCommand::ParseKeyValue(const string& line, string* key, string* value, * appropriate error msg to stderr. */ bool LDBCommand::ValidateCmdLineOptions() { - - for (map::const_iterator itr = option_map_.begin(); - itr != option_map_.end(); ++itr) { - if (find(valid_cmd_line_options_.begin(), - valid_cmd_line_options_.end(), itr->first) == - valid_cmd_line_options_.end()) { + for (std::map::const_iterator itr = + option_map_.begin(); + itr != option_map_.end(); ++itr) { + if (std::find(valid_cmd_line_options_.begin(), + valid_cmd_line_options_.end(), + itr->first) == valid_cmd_line_options_.end()) { fprintf(stderr, "Invalid command-line option %s\n", itr->first.c_str()); return false; } } - for (vector::const_iterator itr = flags_.begin(); - itr != flags_.end(); ++itr) { - if (find(valid_cmd_line_options_.begin(), - valid_cmd_line_options_.end(), *itr) == - valid_cmd_line_options_.end()) { + for (std::vector::const_iterator itr = flags_.begin(); + itr != flags_.end(); ++itr) { + if (std::find(valid_cmd_line_options_.begin(), + valid_cmd_line_options_.end(), + *itr) == valid_cmd_line_options_.end()) { fprintf(stderr, "Invalid command-line flag %s\n", itr->c_str()); return false; } @@ -603,8 +602,8 @@ bool LDBCommand::ValidateCmdLineOptions() { return true; } -string LDBCommand::HexToString(const string& str) { - string result; +std::string LDBCommand::HexToString(const std::string& str) { + std::string result; std::string::size_type len = str.length(); if (len < 2 || str[0] != '0' || str[1] != 'x') { fprintf(stderr, "Invalid hex input %s. Must start with 0x\n", str.c_str()); @@ -616,27 +615,28 @@ string LDBCommand::HexToString(const string& str) { return result; } -string LDBCommand::StringToHex(const string& str) { - string result("0x"); +std::string LDBCommand::StringToHex(const std::string& str) { + std::string result("0x"); result.append(Slice(str).ToString(true)); return result; } -string LDBCommand::PrintKeyValue(const string& key, const string& value, - bool is_key_hex, bool is_value_hex) { - string result; +std::string LDBCommand::PrintKeyValue(const std::string& key, + const std::string& value, bool is_key_hex, + bool is_value_hex) { + std::string result; result.append(is_key_hex ? StringToHex(key) : key); result.append(DELIM); result.append(is_value_hex ? StringToHex(value) : value); return result; } -string LDBCommand::PrintKeyValue(const string& key, const string& value, - bool is_hex) { +std::string LDBCommand::PrintKeyValue(const std::string& key, + const std::string& value, bool is_hex) { return PrintKeyValue(key, value, is_hex, is_hex); } -string LDBCommand::HelpRangeCmdArgs() { +std::string LDBCommand::HelpRangeCmdArgs() { std::ostringstream str_stream; str_stream << " "; str_stream << "[--" << ARG_FROM << "] "; @@ -644,32 +644,33 @@ string LDBCommand::HelpRangeCmdArgs() { return str_stream.str(); } -bool LDBCommand::IsKeyHex(const map& options, - const vector& flags) { +bool LDBCommand::IsKeyHex(const std::map& options, + const std::vector& flags) { return (IsFlagPresent(flags, ARG_HEX) || IsFlagPresent(flags, ARG_KEY_HEX) || ParseBooleanOption(options, ARG_HEX, false) || ParseBooleanOption(options, ARG_KEY_HEX, false)); } -bool LDBCommand::IsValueHex(const map& options, - const vector& flags) { +bool LDBCommand::IsValueHex(const std::map& options, + const std::vector& flags) { return (IsFlagPresent(flags, ARG_HEX) || IsFlagPresent(flags, ARG_VALUE_HEX) || ParseBooleanOption(options, ARG_HEX, false) || ParseBooleanOption(options, ARG_VALUE_HEX, false)); } -bool LDBCommand::ParseBooleanOption(const map& options, - const string& option, bool default_val) { - map::const_iterator itr = options.find(option); +bool LDBCommand::ParseBooleanOption( + const std::map& options, + const std::string& option, bool default_val) { + std::map::const_iterator itr = options.find(option); if (itr != options.end()) { - string option_val = itr->second; + std::string option_val = itr->second; return StringToBool(itr->second); } return default_val; } -bool LDBCommand::StringToBool(string val) { +bool LDBCommand::StringToBool(std::string val) { std::transform(val.begin(), val.end(), val.begin(), [](char ch) -> char { return (char)::tolower(ch); }); @@ -682,14 +683,17 @@ bool LDBCommand::StringToBool(string val) { } } -CompactorCommand::CompactorCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_FROM, ARG_TO, ARG_HEX, ARG_KEY_HEX, - ARG_VALUE_HEX, ARG_TTL})), - null_from_(true), null_to_(true) { - - map::const_iterator itr = options.find(ARG_FROM); +CompactorCommand::CompactorCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, + BuildCmdLineOptions({ARG_FROM, ARG_TO, ARG_HEX, ARG_KEY_HEX, + ARG_VALUE_HEX, ARG_TTL})), + null_from_(true), + null_to_(true) { + std::map::const_iterator itr = + options.find(ARG_FROM); if (itr != options.end()) { null_from_ = false; from_ = itr->second; @@ -711,7 +715,7 @@ CompactorCommand::CompactorCommand(const vector& params, } } -void CompactorCommand::Help(string& ret) { +void CompactorCommand::Help(std::string& ret) { ret.append(" "); ret.append(CompactorCommand::Name()); ret.append(HelpRangeCmdArgs()); @@ -745,27 +749,30 @@ void CompactorCommand::DoCommand() { // ---------------------------------------------------------------------------- -const string DBLoaderCommand::ARG_DISABLE_WAL = "disable_wal"; -const string DBLoaderCommand::ARG_BULK_LOAD = "bulk_load"; -const string DBLoaderCommand::ARG_COMPACT = "compact"; - -DBLoaderCommand::DBLoaderCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, - ARG_FROM, ARG_TO, ARG_CREATE_IF_MISSING, - ARG_DISABLE_WAL, ARG_BULK_LOAD, - ARG_COMPACT})), - create_if_missing_(false), disable_wal_(false), bulk_load_(false), - compact_(false) { +const std::string DBLoaderCommand::ARG_DISABLE_WAL = "disable_wal"; +const std::string DBLoaderCommand::ARG_BULK_LOAD = "bulk_load"; +const std::string DBLoaderCommand::ARG_COMPACT = "compact"; +DBLoaderCommand::DBLoaderCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand( + options, flags, false, + BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, ARG_FROM, + ARG_TO, ARG_CREATE_IF_MISSING, ARG_DISABLE_WAL, + ARG_BULK_LOAD, ARG_COMPACT})), + create_if_missing_(false), + disable_wal_(false), + bulk_load_(false), + compact_(false) { create_if_missing_ = IsFlagPresent(flags, ARG_CREATE_IF_MISSING); disable_wal_ = IsFlagPresent(flags, ARG_DISABLE_WAL); bulk_load_ = IsFlagPresent(flags, ARG_BULK_LOAD); compact_ = IsFlagPresent(flags, ARG_COMPACT); } -void DBLoaderCommand::Help(string& ret) { +void DBLoaderCommand::Help(std::string& ret) { ret.append(" "); ret.append(DBLoaderCommand::Name()); ret.append(" [--" + ARG_CREATE_IF_MISSING + "]"); @@ -796,10 +803,10 @@ void DBLoaderCommand::DoCommand() { } int bad_lines = 0; - string line; - while (getline(cin, line, '\n')) { - string key; - string value; + std::string line; + while (getline(std::cin, line, '\n')) { + std::string key; + std::string value; if (ParseKeyValue(line, &key, &value, is_key_hex_, is_value_hex_)) { db_->Put(write_options, GetCfHandle(), Slice(key), Slice(value)); } else if (0 == line.find("Keys in range:")) { @@ -812,7 +819,7 @@ void DBLoaderCommand::DoCommand() { } if (bad_lines > 0) { - cout << "Warning: " << bad_lines << " bad lines ignored." << endl; + std::cout << "Warning: " << bad_lines << " bad lines ignored." << std::endl; } if (compact_) { db_->CompactRange(CompactRangeOptions(), GetCfHandle(), nullptr, nullptr); @@ -846,11 +853,11 @@ void DumpManifestFile(std::string file, bool verbose, bool hex, bool json) { } // namespace -const string ManifestDumpCommand::ARG_VERBOSE = "verbose"; -const string ManifestDumpCommand::ARG_JSON = "json"; -const string ManifestDumpCommand::ARG_PATH = "path"; +const std::string ManifestDumpCommand::ARG_VERBOSE = "verbose"; +const std::string ManifestDumpCommand::ARG_JSON = "json"; +const std::string ManifestDumpCommand::ARG_PATH = "path"; -void ManifestDumpCommand::Help(string& ret) { +void ManifestDumpCommand::Help(std::string& ret) { ret.append(" "); ret.append(ManifestDumpCommand::Name()); ret.append(" [--" + ARG_VERBOSE + "]"); @@ -859,18 +866,21 @@ void ManifestDumpCommand::Help(string& ret) { ret.append("\n"); } -ManifestDumpCommand::ManifestDumpCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_VERBOSE, ARG_PATH, ARG_HEX, ARG_JSON})), - verbose_(false), - json_(false), - path_("") -{ +ManifestDumpCommand::ManifestDumpCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand( + options, flags, false, + BuildCmdLineOptions({ARG_VERBOSE, ARG_PATH, ARG_HEX, ARG_JSON})), + verbose_(false), + json_(false), + path_("") { verbose_ = IsFlagPresent(flags, ARG_VERBOSE); json_ = IsFlagPresent(flags, ARG_JSON); - map::const_iterator itr = options.find(ARG_PATH); + std::map::const_iterator itr = + options.find(ARG_PATH); if (itr != options.end()) { path_ = itr->second; if (path_.empty()) { @@ -930,7 +940,7 @@ void ManifestDumpCommand::DoCommand() { // ---------------------------------------------------------------------------- -void ListColumnFamiliesCommand::Help(string& ret) { +void ListColumnFamiliesCommand::Help(std::string& ret) { ret.append(" "); ret.append(ListColumnFamiliesCommand::Name()); ret.append(" full_path_to_db_directory "); @@ -938,10 +948,10 @@ void ListColumnFamiliesCommand::Help(string& ret) { } ListColumnFamiliesCommand::ListColumnFamiliesCommand( - const vector& params, const map& options, - const vector& flags) + const std::vector& params, + const std::map& options, + const std::vector& flags) : LDBCommand(options, flags, false, {}) { - if (params.size() != 1) { exec_state_ = LDBCommandExecuteResult::Failed( "dbname must be specified for the list_column_families command"); @@ -951,7 +961,7 @@ ListColumnFamiliesCommand::ListColumnFamiliesCommand( } void ListColumnFamiliesCommand::DoCommand() { - vector column_families; + std::vector column_families; Status s = DB::ListColumnFamilies(DBOptions(), dbname_, &column_families); if (!s.ok()) { printf("Error in processing db %s %s\n", dbname_.c_str(), @@ -970,7 +980,7 @@ void ListColumnFamiliesCommand::DoCommand() { } } -void CreateColumnFamilyCommand::Help(string& ret) { +void CreateColumnFamilyCommand::Help(std::string& ret) { ret.append(" "); ret.append(CreateColumnFamilyCommand::Name()); ret.append(" --db= "); @@ -978,8 +988,9 @@ void CreateColumnFamilyCommand::Help(string& ret) { } CreateColumnFamilyCommand::CreateColumnFamilyCommand( - const vector& params, const map& options, - const vector& flags) + const std::vector& params, + const std::map& options, + const std::vector& flags) : LDBCommand(options, flags, true, {ARG_DB}) { if (params.size() != 1) { exec_state_ = LDBCommandExecuteResult::Failed( @@ -1006,28 +1017,30 @@ void CreateColumnFamilyCommand::DoCommand() { namespace { -string ReadableTime(int unixtime) { +std::string ReadableTime(int unixtime) { char time_buffer [80]; time_t rawtime = unixtime; struct tm tInfo; struct tm* timeinfo = localtime_r(&rawtime, &tInfo); assert(timeinfo == &tInfo); strftime(time_buffer, 80, "%c", timeinfo); - return string(time_buffer); + return std::string(time_buffer); } // This function only called when it's the sane case of >1 buckets in time-range // Also called only when timekv falls between ttl_start and ttl_end provided -void IncBucketCounts(vector& bucket_counts, int ttl_start, - int time_range, int bucket_size, int timekv, int num_buckets) { +void IncBucketCounts(std::vector& bucket_counts, int ttl_start, + int time_range, int bucket_size, int timekv, + int num_buckets) { assert(time_range > 0 && timekv >= ttl_start && bucket_size > 0 && timekv < (ttl_start + time_range) && num_buckets > 1); int bucket = (timekv - ttl_start) / bucket_size; bucket_counts[bucket]++; } -void PrintBucketCounts(const vector& bucket_counts, int ttl_start, - int ttl_end, int bucket_size, int num_buckets) { +void PrintBucketCounts(const std::vector& bucket_counts, + int ttl_start, int ttl_end, int bucket_size, + int num_buckets) { int time_point = ttl_start; for(int i = 0; i < num_buckets - 1; i++, time_point += bucket_size) { fprintf(stdout, "Keys in range %s to %s : %lu\n", @@ -1043,14 +1056,15 @@ void PrintBucketCounts(const vector& bucket_counts, int ttl_start, } // namespace -const string InternalDumpCommand::ARG_COUNT_ONLY = "count_only"; -const string InternalDumpCommand::ARG_COUNT_DELIM = "count_delim"; -const string InternalDumpCommand::ARG_STATS = "stats"; -const string InternalDumpCommand::ARG_INPUT_KEY_HEX = "input_key_hex"; +const std::string InternalDumpCommand::ARG_COUNT_ONLY = "count_only"; +const std::string InternalDumpCommand::ARG_COUNT_DELIM = "count_delim"; +const std::string InternalDumpCommand::ARG_STATS = "stats"; +const std::string InternalDumpCommand::ARG_INPUT_KEY_HEX = "input_key_hex"; -InternalDumpCommand::InternalDumpCommand(const vector& params, - const map& options, - const vector& flags) +InternalDumpCommand::InternalDumpCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) : LDBCommand( options, flags, true, BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, ARG_FROM, @@ -1068,7 +1082,8 @@ InternalDumpCommand::InternalDumpCommand(const vector& params, has_to_ = ParseStringOption(options, ARG_TO, &to_); ParseIntOption(options, ARG_MAX_KEYS, max_keys_, exec_state_); - map::const_iterator itr = options.find(ARG_COUNT_DELIM); + std::map::const_iterator itr = + options.find(ARG_COUNT_DELIM); if (itr != options.end()) { delim_ = itr->second; count_delim_ = true; @@ -1092,7 +1107,7 @@ InternalDumpCommand::InternalDumpCommand(const vector& params, } } -void InternalDumpCommand::Help(string& ret) { +void InternalDumpCommand::Help(std::string& ret) { ret.append(" "); ret.append(InternalDumpCommand::Name()); ret.append(HelpRangeCmdArgs()); @@ -1111,7 +1126,7 @@ void InternalDumpCommand::DoCommand() { } if (print_stats_) { - string stats; + std::string stats; if (db_->GetProperty(GetCfHandle(), "rocksdb.stats", &stats)) { fprintf(stdout, "%s\n", stats.c_str()); } @@ -1123,7 +1138,7 @@ void InternalDumpCommand::DoCommand() { exec_state_ = LDBCommandExecuteResult::Failed("DB is not DBImpl"); return; } - string rtype1,rtype2,row,val; + std::string rtype1, rtype2, row, val; rtype2 = ""; uint64_t c=0; uint64_t s1=0,s2=0; @@ -1186,8 +1201,8 @@ void InternalDumpCommand::DoCommand() { } if (!count_only_ && !count_delim_) { - string key = ikey.DebugString(is_key_hex_); - string value = iter->value().ToString(is_value_hex_); + std::string key = ikey.DebugString(is_key_hex_); + std::string value = iter->value().ToString(is_value_hex_); std::cout << key << " => " << value << "\n"; } @@ -1201,15 +1216,15 @@ void InternalDumpCommand::DoCommand() { fprintf(stdout, "Internal keys in range: %lld\n", (long long) count); } +const std::string DBDumperCommand::ARG_COUNT_ONLY = "count_only"; +const std::string DBDumperCommand::ARG_COUNT_DELIM = "count_delim"; +const std::string DBDumperCommand::ARG_STATS = "stats"; +const std::string DBDumperCommand::ARG_TTL_BUCKET = "bucket"; -const string DBDumperCommand::ARG_COUNT_ONLY = "count_only"; -const string DBDumperCommand::ARG_COUNT_DELIM = "count_delim"; -const string DBDumperCommand::ARG_STATS = "stats"; -const string DBDumperCommand::ARG_TTL_BUCKET = "bucket"; - -DBDumperCommand::DBDumperCommand(const vector& params, - const map& options, - const vector& flags) +DBDumperCommand::DBDumperCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) : LDBCommand(options, flags, true, BuildCmdLineOptions( {ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, ARG_FROM, @@ -1222,7 +1237,8 @@ DBDumperCommand::DBDumperCommand(const vector& params, count_only_(false), count_delim_(false), print_stats_(false) { - map::const_iterator itr = options.find(ARG_FROM); + std::map::const_iterator itr = + options.find(ARG_FROM); if (itr != options.end()) { null_from_ = false; from_ = itr->second; @@ -1240,12 +1256,12 @@ DBDumperCommand::DBDumperCommand(const vector& params, #if defined(CYGWIN) max_keys_ = strtol(itr->second.c_str(), 0, 10); #else - max_keys_ = stoi(itr->second); + max_keys_ = std::stoi(itr->second); #endif - } catch(const invalid_argument&) { + } catch (const std::invalid_argument&) { exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS + " has an invalid value"); - } catch(const out_of_range&) { + } catch (const std::out_of_range&) { exec_state_ = LDBCommandExecuteResult::Failed( ARG_MAX_KEYS + " has a value out-of-range"); } @@ -1277,7 +1293,7 @@ DBDumperCommand::DBDumperCommand(const vector& params, } } -void DBDumperCommand::Help(string& ret) { +void DBDumperCommand::Help(std::string& ret) { ret.append(" "); ret.append(DBDumperCommand::Name()); ret.append(HelpRangeCmdArgs()); @@ -1308,7 +1324,7 @@ void DBDumperCommand::Help(string& ret) { void DBDumperCommand::DoCommand() { if (!db_) { assert(!path_.empty()); - string fileName = GetFileNameFromPath(path_); + std::string fileName = GetFileNameFromPath(path_); uint64_t number; FileType type; @@ -1350,7 +1366,7 @@ void DBDumperCommand::DoDumpCommand() { // Parse command line args uint64_t count = 0; if (print_stats_) { - string stats; + std::string stats; if (db_->GetProperty("rocksdb.stats", &stats)) { fprintf(stdout, "%s\n", stats.c_str()); } @@ -1391,7 +1407,7 @@ void DBDumperCommand::DoDumpCommand() { bucket_size = time_range; // Will have just 1 bucket by default } //cretaing variables for row count of each type - string rtype1,rtype2,row,val; + std::string rtype1, rtype2, row, val; rtype2 = ""; uint64_t c=0; uint64_t s1=0,s2=0; @@ -1400,7 +1416,7 @@ void DBDumperCommand::DoDumpCommand() { int num_buckets = (bucket_size >= time_range) ? 1 : ((time_range + bucket_size - 1) / bucket_size); - vector bucket_counts(num_buckets, 0); + std::vector bucket_counts(num_buckets, 0); if (is_db_ttl_ && !count_only_ && timestamp_ && !count_delim_) { fprintf(stdout, "Dumping key-values from %s to %s\n", ReadableTime(ttl_start).c_str(), ReadableTime(ttl_end).c_str()); @@ -1457,9 +1473,9 @@ void DBDumperCommand::DoDumpCommand() { if (is_db_ttl_ && timestamp_) { fprintf(stdout, "%s ", ReadableTime(rawtime).c_str()); } - string str = PrintKeyValue(iter->key().ToString(), - iter->value().ToString(), is_key_hex_, - is_value_hex_); + std::string str = + PrintKeyValue(iter->key().ToString(), iter->value().ToString(), + is_key_hex_, is_value_hex_); fprintf(stdout, "%s\n", str.c_str()); } } @@ -1477,18 +1493,19 @@ void DBDumperCommand::DoDumpCommand() { delete iter; } -const string ReduceDBLevelsCommand::ARG_NEW_LEVELS = "new_levels"; -const string ReduceDBLevelsCommand::ARG_PRINT_OLD_LEVELS = "print_old_levels"; - -ReduceDBLevelsCommand::ReduceDBLevelsCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_NEW_LEVELS, ARG_PRINT_OLD_LEVELS})), - old_levels_(1 << 7), - new_levels_(-1), - print_old_levels_(false) { - +const std::string ReduceDBLevelsCommand::ARG_NEW_LEVELS = "new_levels"; +const std::string ReduceDBLevelsCommand::ARG_PRINT_OLD_LEVELS = + "print_old_levels"; +ReduceDBLevelsCommand::ReduceDBLevelsCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, + BuildCmdLineOptions({ARG_NEW_LEVELS, ARG_PRINT_OLD_LEVELS})), + old_levels_(1 << 7), + new_levels_(-1), + print_old_levels_(false) { ParseIntOption(option_map_, ARG_NEW_LEVELS, new_levels_, exec_state_); print_old_levels_ = IsFlagPresent(flags, ARG_PRINT_OLD_LEVELS); @@ -1498,9 +1515,9 @@ ReduceDBLevelsCommand::ReduceDBLevelsCommand(const vector& params, } } -vector ReduceDBLevelsCommand::PrepareArgs(const string& db_path, - int new_levels, bool print_old_level) { - vector ret; +std::vector ReduceDBLevelsCommand::PrepareArgs( + const std::string& db_path, int new_levels, bool print_old_level) { + std::vector ret; ret.push_back("reduce_levels"); ret.push_back("--" + ARG_DB + "=" + db_path); ret.push_back("--" + ARG_NEW_LEVELS + "=" + rocksdb::ToString(new_levels)); @@ -1510,7 +1527,7 @@ vector ReduceDBLevelsCommand::PrepareArgs(const string& db_path, return ret; } -void ReduceDBLevelsCommand::Help(string& ret) { +void ReduceDBLevelsCommand::Help(std::string& ret) { ret.append(" "); ret.append(ReduceDBLevelsCommand::Name()); ret.append(" --" + ARG_NEW_LEVELS + "="); @@ -1603,20 +1620,20 @@ void ReduceDBLevelsCommand::DoCommand() { } } -const string ChangeCompactionStyleCommand::ARG_OLD_COMPACTION_STYLE = - "old_compaction_style"; -const string ChangeCompactionStyleCommand::ARG_NEW_COMPACTION_STYLE = - "new_compaction_style"; +const std::string ChangeCompactionStyleCommand::ARG_OLD_COMPACTION_STYLE = + "old_compaction_style"; +const std::string ChangeCompactionStyleCommand::ARG_NEW_COMPACTION_STYLE = + "new_compaction_style"; ChangeCompactionStyleCommand::ChangeCompactionStyleCommand( - const vector& params, const map& options, - const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_OLD_COMPACTION_STYLE, - ARG_NEW_COMPACTION_STYLE})), - old_compaction_style_(-1), - new_compaction_style_(-1) { - + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, + BuildCmdLineOptions( + {ARG_OLD_COMPACTION_STYLE, ARG_NEW_COMPACTION_STYLE})), + old_compaction_style_(-1), + new_compaction_style_(-1) { ParseIntOption(option_map_, ARG_OLD_COMPACTION_STYLE, old_compaction_style_, exec_state_); if (old_compaction_style_ != kCompactionStyleLevel && @@ -1653,7 +1670,7 @@ ChangeCompactionStyleCommand::ChangeCompactionStyleCommand( } } -void ChangeCompactionStyleCommand::Help(string& ret) { +void ChangeCompactionStyleCommand::Help(std::string& ret) { ret.append(" "); ret.append(ChangeCompactionStyleCommand::Name()); ret.append(" --" + ARG_OLD_COMPACTION_STYLE + "=& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, true, - BuildCmdLineOptions( - {ARG_WAL_FILE, ARG_PRINT_HEADER, ARG_PRINT_VALUE})), - print_header_(false), print_values_(false) { +const std::string WALDumperCommand::ARG_WAL_FILE = "walfile"; +const std::string WALDumperCommand::ARG_PRINT_VALUE = "print_value"; +const std::string WALDumperCommand::ARG_PRINT_HEADER = "header"; +WALDumperCommand::WALDumperCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, true, + BuildCmdLineOptions( + {ARG_WAL_FILE, ARG_PRINT_HEADER, ARG_PRINT_VALUE})), + print_header_(false), + print_values_(false) { wal_file_.clear(); - map::const_iterator itr = options.find(ARG_WAL_FILE); + std::map::const_iterator itr = + options.find(ARG_WAL_FILE); if (itr != options.end()) { wal_file_ = itr->second; } @@ -1923,7 +1944,7 @@ WALDumperCommand::WALDumperCommand(const vector& params, } } -void WALDumperCommand::Help(string& ret) { +void WALDumperCommand::Help(std::string& ret) { ret.append(" "); ret.append(WALDumperCommand::Name()); ret.append(" --" + ARG_WAL_FILE + "="); @@ -1938,12 +1959,12 @@ void WALDumperCommand::DoCommand() { // ---------------------------------------------------------------------------- -GetCommand::GetCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, true, BuildCmdLineOptions({ARG_TTL, ARG_HEX, - ARG_KEY_HEX, - ARG_VALUE_HEX})) { - +GetCommand::GetCommand(const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand( + options, flags, true, + BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) { if (params.size() != 1) { exec_state_ = LDBCommandExecuteResult::Failed( " must be specified for the get command"); @@ -1956,7 +1977,7 @@ GetCommand::GetCommand(const vector& params, } } -void GetCommand::Help(string& ret) { +void GetCommand::Help(std::string& ret) { ret.append(" "); ret.append(GetCommand::Name()); ret.append(" "); @@ -1969,7 +1990,7 @@ void GetCommand::DoCommand() { assert(GetExecuteState().IsFailed()); return; } - string value; + std::string value; Status st = db_->Get(ReadOptions(), GetCfHandle(), key_, &value); if (st.ok()) { fprintf(stdout, "%s\n", @@ -1981,12 +2002,13 @@ void GetCommand::DoCommand() { // ---------------------------------------------------------------------------- -ApproxSizeCommand::ApproxSizeCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, true, - BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, - ARG_FROM, ARG_TO})) { - +ApproxSizeCommand::ApproxSizeCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, true, + BuildCmdLineOptions( + {ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, ARG_FROM, ARG_TO})) { if (options.find(ARG_FROM) != options.end()) { start_key_ = options.find(ARG_FROM)->second; } else { @@ -2009,7 +2031,7 @@ ApproxSizeCommand::ApproxSizeCommand(const vector& params, } } -void ApproxSizeCommand::Help(string& ret) { +void ApproxSizeCommand::Help(std::string& ret) { ret.append(" "); ret.append(ApproxSizeCommand::Name()); ret.append(HelpRangeCmdArgs()); @@ -2036,12 +2058,13 @@ void ApproxSizeCommand::DoCommand() { // ---------------------------------------------------------------------------- -BatchPutCommand::BatchPutCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, - ARG_CREATE_IF_MISSING})) { - +BatchPutCommand::BatchPutCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, + BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, + ARG_VALUE_HEX, ARG_CREATE_IF_MISSING})) { if (params.size() < 2) { exec_state_ = LDBCommandExecuteResult::Failed( "At least one pair must be specified batchput."); @@ -2050,16 +2073,16 @@ BatchPutCommand::BatchPutCommand(const vector& params, "Equal number of s and s must be specified for batchput."); } else { for (size_t i = 0; i < params.size(); i += 2) { - string key = params.at(i); - string value = params.at(i+1); - key_values_.push_back(pair( - is_key_hex_ ? HexToString(key) : key, - is_value_hex_ ? HexToString(value) : value)); + std::string key = params.at(i); + std::string value = params.at(i + 1); + key_values_.push_back(std::pair( + is_key_hex_ ? HexToString(key) : key, + is_value_hex_ ? HexToString(value) : value)); } } } -void BatchPutCommand::Help(string& ret) { +void BatchPutCommand::Help(std::string& ret) { ret.append(" "); ret.append(BatchPutCommand::Name()); ret.append(" [ ] [..]"); @@ -2074,8 +2097,9 @@ void BatchPutCommand::DoCommand() { } WriteBatch batch; - for (vector>::const_iterator itr - = key_values_.begin(); itr != key_values_.end(); ++itr) { + for (std::vector>::const_iterator itr = + key_values_.begin(); + itr != key_values_.end(); ++itr) { batch.Put(GetCfHandle(), itr->first, itr->second); } Status st = db_->Write(WriteOptions(), &batch); @@ -2094,20 +2118,20 @@ Options BatchPutCommand::PrepareOptionsForOpenDB() { // ---------------------------------------------------------------------------- -ScanCommand::ScanCommand(const vector& params, - const map& options, - const vector& flags) - : LDBCommand(options, flags, true, - BuildCmdLineOptions( - {ARG_TTL, ARG_NO_VALUE, ARG_HEX, ARG_KEY_HEX, - ARG_TO, ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP, - ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})), +ScanCommand::ScanCommand(const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand( + options, flags, true, + BuildCmdLineOptions({ARG_TTL, ARG_NO_VALUE, ARG_HEX, ARG_KEY_HEX, + ARG_TO, ARG_VALUE_HEX, ARG_FROM, ARG_TIMESTAMP, + ARG_MAX_KEYS, ARG_TTL_START, ARG_TTL_END})), start_key_specified_(false), end_key_specified_(false), max_keys_scanned_(-1), no_value_(false) { - - map::const_iterator itr = options.find(ARG_FROM); + std::map::const_iterator itr = + options.find(ARG_FROM); if (itr != options.end()) { start_key_ = itr->second; if (is_key_hex_) { @@ -2124,7 +2148,7 @@ ScanCommand::ScanCommand(const vector& params, end_key_specified_ = true; } - vector::const_iterator vitr = + std::vector::const_iterator vitr = std::find(flags.begin(), flags.end(), ARG_NO_VALUE); if (vitr != flags.end()) { no_value_ = true; @@ -2136,19 +2160,19 @@ ScanCommand::ScanCommand(const vector& params, #if defined(CYGWIN) max_keys_scanned_ = strtol(itr->second.c_str(), 0, 10); #else - max_keys_scanned_ = stoi(itr->second); + max_keys_scanned_ = std::stoi(itr->second); #endif - } catch(const invalid_argument&) { + } catch (const std::invalid_argument&) { exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS + " has an invalid value"); - } catch(const out_of_range&) { + } catch (const std::out_of_range&) { exec_state_ = LDBCommandExecuteResult::Failed( ARG_MAX_KEYS + " has a value out-of-range"); } } } -void ScanCommand::Help(string& ret) { +void ScanCommand::Help(std::string& ret) { ret.append(" "); ret.append(ScanCommand::Name()); ret.append(HelpRangeCmdArgs()); @@ -2245,11 +2269,11 @@ void ScanCommand::DoCommand() { // ---------------------------------------------------------------------------- -DeleteCommand::DeleteCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) { - +DeleteCommand::DeleteCommand(const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, + BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) { if (params.size() != 1) { exec_state_ = LDBCommandExecuteResult::Failed( "KEY must be specified for the delete command"); @@ -2261,7 +2285,7 @@ DeleteCommand::DeleteCommand(const vector& params, } } -void DeleteCommand::Help(string& ret) { +void DeleteCommand::Help(std::string& ret) { ret.append(" "); ret.append(DeleteCommand::Name() + " "); ret.append("\n"); @@ -2280,13 +2304,12 @@ void DeleteCommand::DoCommand() { } } - -PutCommand::PutCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX, - ARG_CREATE_IF_MISSING})) { - +PutCommand::PutCommand(const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, + BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, + ARG_VALUE_HEX, ARG_CREATE_IF_MISSING})) { if (params.size() != 2) { exec_state_ = LDBCommandExecuteResult::Failed( " and must be specified for the put command"); @@ -2304,7 +2327,7 @@ PutCommand::PutCommand(const vector& params, } } -void PutCommand::Help(string& ret) { +void PutCommand::Help(std::string& ret) { ret.append(" "); ret.append(PutCommand::Name()); ret.append(" "); @@ -2338,15 +2361,17 @@ const char* DBQuerierCommand::GET_CMD = "get"; const char* DBQuerierCommand::PUT_CMD = "put"; const char* DBQuerierCommand::DELETE_CMD = "delete"; -DBQuerierCommand::DBQuerierCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, - ARG_VALUE_HEX})) { +DBQuerierCommand::DBQuerierCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand( + options, flags, false, + BuildCmdLineOptions({ARG_TTL, ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) { } -void DBQuerierCommand::Help(string& ret) { +void DBQuerierCommand::Help(std::string& ret) { ret.append(" "); ret.append(DBQuerierCommand::Name()); ret.append(" [--" + ARG_TTL + "]"); @@ -2365,17 +2390,16 @@ void DBQuerierCommand::DoCommand() { ReadOptions read_options; WriteOptions write_options; - string line; - string key; - string value; - while (getline(cin, line, '\n')) { - - // Parse line into vector - vector tokens; + std::string line; + std::string key; + std::string value; + while (getline(std::cin, line, '\n')) { + // Parse line into std::vector + std::vector tokens; size_t pos = 0; while (true) { size_t pos2 = line.find(' ', pos); - if (pos2 == string::npos) { + if (pos2 == std::string::npos) { break; } tokens.push_back(line.substr(pos, pos2-pos)); @@ -2383,7 +2407,7 @@ void DBQuerierCommand::DoCommand() { } tokens.push_back(line.substr(pos)); - const string& cmd = tokens[0]; + const std::string& cmd = tokens[0]; if (cmd == HELP_CMD) { fprintf(stdout, @@ -2416,13 +2440,13 @@ void DBQuerierCommand::DoCommand() { // ---------------------------------------------------------------------------- -CheckConsistencyCommand::CheckConsistencyCommand(const vector& params, - const map& options, const vector& flags) : - LDBCommand(options, flags, false, - BuildCmdLineOptions({})) { -} +CheckConsistencyCommand::CheckConsistencyCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) + : LDBCommand(options, flags, false, BuildCmdLineOptions({})) {} -void CheckConsistencyCommand::Help(string& ret) { +void CheckConsistencyCommand::Help(std::string& ret) { ret.append(" "); ret.append(CheckConsistencyCommand::Name()); ret.append("\n"); @@ -2446,12 +2470,12 @@ void CheckConsistencyCommand::DoCommand() { // ---------------------------------------------------------------------------- -RepairCommand::RepairCommand(const vector& params, - const map& options, - const vector& flags) +RepairCommand::RepairCommand(const std::vector& params, + const std::map& options, + const std::vector& flags) : LDBCommand(options, flags, false, BuildCmdLineOptions({})) {} -void RepairCommand::Help(string& ret) { +void RepairCommand::Help(std::string& ret) { ret.append(" "); ret.append(RepairCommand::Name()); ret.append("\n"); @@ -2517,12 +2541,13 @@ void DumpSstFile(std::string filename, bool output_hex, bool show_properties) { } // namespace -DBFileDumperCommand::DBFileDumperCommand(const vector& params, - const map& options, - const vector& flags) +DBFileDumperCommand::DBFileDumperCommand( + const std::vector& params, + const std::map& options, + const std::vector& flags) : LDBCommand(options, flags, true, BuildCmdLineOptions({})) {} -void DBFileDumperCommand::Help(string& ret) { +void DBFileDumperCommand::Help(std::string& ret) { ret.append(" "); ret.append(DBFileDumperCommand::Name()); ret.append("\n"); @@ -2547,7 +2572,7 @@ void DBFileDumperCommand::DoCommand() { } // remove the trailing '\n' manifest_filename.resize(manifest_filename.size() - 1); - string manifest_filepath = db_->GetName() + "/" + manifest_filename; + std::string manifest_filepath = db_->GetName() + "/" + manifest_filename; std::cout << manifest_filepath << std::endl; DumpManifestFile(manifest_filepath, false, false, false); std::cout << std::endl; diff --git a/util/autovector_test.cc b/util/autovector_test.cc index d72bd507f5..7999ea132c 100644 --- a/util/autovector_test.cc +++ b/util/autovector_test.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include "rocksdb/env.h" @@ -13,9 +14,10 @@ #include "util/testharness.h" #include "util/testutil.h" -namespace rocksdb { +using std::cout; +using std::endl; -using namespace std; +namespace rocksdb { class AutoVectorTest : public testing::Test {}; const unsigned long kSize = 8; @@ -197,8 +199,8 @@ TEST_F(AutoVectorTest, Iterators) { } namespace { -vector GetTestKeys(size_t size) { - vector keys; +std::vector GetTestKeys(size_t size) { + std::vector keys; keys.resize(size); int index = 0; @@ -209,9 +211,9 @@ vector GetTestKeys(size_t size) { } } // namespace -template +template void BenchmarkVectorCreationAndInsertion( - string name, size_t ops, size_t item_size, + std::string name, size_t ops, size_t item_size, const std::vector& items) { auto env = Env::Default(); @@ -231,7 +233,7 @@ void BenchmarkVectorCreationAndInsertion( } template -size_t BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) { +size_t BenchmarkSequenceAccess(std::string name, size_t ops, size_t elem_size) { TVector v; for (const auto& item : GetTestKeys(elem_size)) { v.push_back(item); @@ -255,9 +257,9 @@ size_t BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) { return total; } -// This test case only reports the performance between std::vector -// and autovector. We chose string for comparison because in most -// o our use cases we used std::vector. +// This test case only reports the performance between std::vector +// and autovector. We chose string for comparison because in most +// of our use cases we used std::vector. TEST_F(AutoVectorTest, PerfBench) { // We run same operations for kOps times in order to get a more fair result. size_t kOps = 100000; @@ -279,12 +281,10 @@ TEST_F(AutoVectorTest, PerfBench) { // pre-generated unique keys auto string_keys = GetTestKeys(kOps * 2 * kSize); for (auto insertions : { 0ul, 1ul, kSize / 2, kSize, 2 * kSize }) { - BenchmarkVectorCreationAndInsertion>( - "vector", kOps, insertions, string_keys - ); - BenchmarkVectorCreationAndInsertion>( - "autovector", kOps, insertions, string_keys - ); + BenchmarkVectorCreationAndInsertion>( + "std::vector", kOps, insertions, string_keys); + BenchmarkVectorCreationAndInsertion>( + "autovector", kOps, insertions, string_keys); cout << "-----------------------------------" << endl; } @@ -293,14 +293,13 @@ TEST_F(AutoVectorTest, PerfBench) { cout << "=====================================================" << endl; // pre-generated unique keys - vector int_keys(kOps * 2 * kSize); + std::vector int_keys(kOps * 2 * kSize); for (size_t i = 0; i < kOps * 2 * kSize; ++i) { int_keys[i] = i; } for (auto insertions : { 0ul, 1ul, kSize / 2, kSize, 2 * kSize }) { - BenchmarkVectorCreationAndInsertion>( - "vector", kOps, insertions, int_keys - ); + BenchmarkVectorCreationAndInsertion>( + "std::vector", kOps, insertions, int_keys); BenchmarkVectorCreationAndInsertion>( "autovector", kOps, insertions, int_keys ); @@ -312,12 +311,10 @@ TEST_F(AutoVectorTest, PerfBench) { cout << "Sequence Access Test" << endl; cout << "=====================================================" << endl; for (auto elem_size : { kSize / 2, kSize, 2 * kSize }) { - BenchmarkSequenceAccess>( - "vector", kOps, elem_size - ); - BenchmarkSequenceAccess>( - "autovector", kOps, elem_size - ); + BenchmarkSequenceAccess>("std::vector", kOps, + elem_size); + BenchmarkSequenceAccess>("autovector", kOps, + elem_size); cout << "-----------------------------------" << endl; } } diff --git a/util/cache_test.cc b/util/cache_test.cc index 3df71c0982..51cac72941 100644 --- a/util/cache_test.cc +++ b/util/cache_test.cc @@ -554,8 +554,8 @@ TEST_F(CacheTest, ApplyToAllCacheEntiresTest) { } cache_->ApplyToAllCacheEntries(callback, true); - sort(inserted.begin(), inserted.end()); - sort(callback_state.begin(), callback_state.end()); + std::sort(inserted.begin(), inserted.end()); + std::sort(callback_state.begin(), callback_state.end()); ASSERT_TRUE(inserted == callback_state); } diff --git a/util/env_hdfs.cc b/util/env_hdfs.cc index e82895ee02..f1d3f01480 100644 --- a/util/env_hdfs.cc +++ b/util/env_hdfs.cc @@ -471,7 +471,7 @@ Status HdfsEnv::GetChildren(const std::string& path, if (numEntries >= 0) { for(int i = 0; i < numEntries; i++) { char* pathname = pHdfsFileInfo[i].mName; - char* filename = rindex(pathname, '/'); + char* filename = std::rindex(pathname, '/'); if (filename != nullptr) { result->push_back(filename+1); } diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index cbc9b228fb..680704b235 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -197,8 +197,8 @@ class TestEnv : public EnvWrapper { void AssertWrittenFiles(std::vector& should_have_written) { MutexLock l(&mutex_); - sort(should_have_written.begin(), should_have_written.end()); - sort(written_files_.begin(), written_files_.end()); + std::sort(should_have_written.begin(), should_have_written.end()); + std::sort(written_files_.begin(), written_files_.end()); ASSERT_TRUE(written_files_ == should_have_written); } diff --git a/utilities/redis/redis_lists_test.cc b/utilities/redis/redis_lists_test.cc index 3c97be2714..57fb8f1408 100644 --- a/utilities/redis/redis_lists_test.cc +++ b/utilities/redis/redis_lists_test.cc @@ -25,13 +25,12 @@ #include "util/random.h" using namespace rocksdb; -using namespace std; namespace rocksdb { class RedisListsTest : public testing::Test { public: - static const string kDefaultDbName; + static const std::string kDefaultDbName; static Options options; RedisListsTest() { @@ -39,7 +38,7 @@ class RedisListsTest : public testing::Test { } }; -const string RedisListsTest::kDefaultDbName = +const std::string RedisListsTest::kDefaultDbName = test::TmpDir() + "/redis_lists_test"; Options RedisListsTest::options = Options(); @@ -60,7 +59,7 @@ void AssertListEq(const std::vector& result, TEST_F(RedisListsTest, SimpleTest) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Simple PushRight (should return the new length each time) ASSERT_EQ(redis.PushRight("k1", "v1"), 1); @@ -89,7 +88,7 @@ TEST_F(RedisListsTest, SimpleTest) { TEST_F(RedisListsTest, SimpleTest2) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Simple PushRight ASSERT_EQ(redis.PushLeft("k1", "v3"), 1); @@ -118,7 +117,7 @@ TEST_F(RedisListsTest, SimpleTest2) { TEST_F(RedisListsTest, IndexTest) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Empty Index check (return empty and should not crash or edit tempv) tempv = "yo"; @@ -177,7 +176,7 @@ TEST_F(RedisListsTest, IndexTest) { TEST_F(RedisListsTest, RangeTest) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Simple Pushes (will yield: [v6, v4, v4, v1, v2, v3]) redis.PushRight("k1", "v1"); @@ -260,7 +259,7 @@ TEST_F(RedisListsTest, RangeTest) { TEST_F(RedisListsTest, InsertTest) { RedisLists redis(kDefaultDbName, options, true); - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Insert on empty list (return 0, and do not crash) ASSERT_EQ(redis.InsertBefore("k1", "non-exist", "a"), 0); @@ -344,7 +343,7 @@ TEST_F(RedisListsTest, InsertTest) { TEST_F(RedisListsTest, SetTest) { RedisLists redis(kDefaultDbName, options, true); - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Set on empty list (return false, and do not crash) ASSERT_EQ(redis.Set("k1", 7, "a"), false); @@ -440,7 +439,7 @@ TEST_F(RedisListsTest, SetTest) { TEST_F(RedisListsTest, InsertPushSetTest) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // A series of pushes and insertions // Will result in [newbegin, z, a, aftera, x, newend] @@ -532,7 +531,7 @@ TEST_F(RedisListsTest, InsertPushSetTest) { TEST_F(RedisListsTest, TrimPopTest) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // A series of pushes and insertions // Will result in [newbegin, z, a, aftera, x, newend] @@ -602,7 +601,7 @@ TEST_F(RedisListsTest, TrimPopTest) { TEST_F(RedisListsTest, RemoveTest) { RedisLists redis(kDefaultDbName, options, true); // Destructive - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // A series of pushes and insertions // Will result in [newbegin, z, a, aftera, x, newend, a, a] @@ -691,7 +690,7 @@ TEST_F(RedisListsTest, RemoveTest) { // Test Multiple keys and Persistence TEST_F(RedisListsTest, PersistenceMultiKeyTest) { - string tempv; // Used below for all Index(), PopRight(), PopLeft() + std::string tempv; // Used below for all Index(), PopRight(), PopLeft() // Block one: populate a single key in the database { @@ -768,12 +767,12 @@ int manual_redis_test(bool destructive){ std::string command; while(true) { - cin >> command; + std::cin >> command; MakeUpper(&command); if (command == "LINSERT") { std::string k, t, p, v; - cin >> k >> t >> p >> v; + std::cin >> k >> t >> p >> v; MakeUpper(&t); if (t=="BEFORE") { std::cout << redis.InsertBefore(k, p, v) << std::endl; @@ -791,13 +790,13 @@ int manual_redis_test(bool destructive){ } else if (command == "LPOP") { std::string k; std::cin >> k; - string res; + std::string res; redis.PopLeft(k, &res); std::cout << res << std::endl; } else if (command == "RPOP") { std::string k; std::cin >> k; - string res; + std::string res; redis.PopRight(k, &res); std::cout << res << std::endl; } else if (command == "LREM") { @@ -829,18 +828,18 @@ int manual_redis_test(bool destructive){ std::string k; int idx; std::string v; - cin >> k >> idx >> v; + std::cin >> k >> idx >> v; redis.Set(k, idx, v); } else if (command == "LINDEX") { std::string k; int idx; std::cin >> k >> idx; - string res; + std::string res; redis.Index(k, idx, &res); std::cout << res << std::endl; } else if (command == "PRINT") { // Added by Deon std::string k; - cin >> k; + std::cin >> k; redis.Print(k); } else if (command == "QUIT") { return 0;