From 5fe2c7c14d81cc22d47bf69d880ee2a49608a0de Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 12:01:50 +0800 Subject: [PATCH] kv: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- src/kv/RocksDBStore.cc | 12 ++++++------ src/kv/RocksDBStore.h | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 40cf417248725..4bd2495eedecc 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -757,7 +757,7 @@ void RocksDBStore::sharding_def_to_columns(const std::vector& shar columns.push_back(sharding_def[i].name); } else { for (size_t j = 0; j < sharding_def[i].shard_cnt; j++) { - columns.push_back(sharding_def[i].name + "-" + to_string(j)); + columns.push_back(sharding_def[i].name + "-" + std::to_string(j)); } } } @@ -781,7 +781,7 @@ int RocksDBStore::create_shards(const rocksdb::Options& opt, if (p.shard_cnt == 1) cf_name = p.name; else - cf_name = p.name + "-" + to_string(idx); + cf_name = p.name + "-" + std::to_string(idx); rocksdb::ColumnFamilyHandle *cf; status = db->CreateColumnFamily(cf_opt, cf_name, &cf); if (!status.ok()) { @@ -1040,7 +1040,7 @@ int RocksDBStore::verify_sharding(const rocksdb::Options& opt, emplace_cf(column, 0, column.name, cf_opt); } else { for (size_t i = 0; i < column.shard_cnt; i++) { - std::string cf_name = column.name + "-" + to_string(i); + std::string cf_name = column.name + "-" + std::to_string(i); emplace_cf(column, i, cf_name, cf_opt); } } @@ -2772,14 +2772,14 @@ public: if (iters[0]->Valid()) { if (iters[i]->Valid()) { if (keyless(iters[0], iters[i])) { - swap(iters[0], iters[i]); + std::swap(iters[0], iters[i]); } } else { //iters[i] empty } } else { if (iters[i]->Valid()) { - swap(iters[0], iters[i]); + std::swap(iters[0], iters[i]); } } //it might happen that cf was empty @@ -3171,7 +3171,7 @@ int RocksDBStore::reshard_cleanup(const RocksDBStore::columns_t& current_columns new_sharding_columns.push_back(name); } else { for (size_t i = 0; i < handle.handles.size(); i++) { - new_sharding_columns.push_back(name + "-" + to_string(i)); + new_sharding_columns.push_back(name + "-" + std::to_string(i)); } } } diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 529b4ffa621ab..41ec9520c5826 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -92,12 +92,12 @@ class RocksDBStore : public KeyValueDB { */ public: struct ColumnFamily { - string name; //< name of this individual column family + std::string name; //< name of this individual column family size_t shard_cnt; //< count of shards - string options; //< configure option string for this CF + std::string options; //< configure option string for this CF uint32_t hash_l; //< first character to take for hash calc. uint32_t hash_h; //< last character to take for hash calc. - ColumnFamily(const string &name, size_t shard_cnt, const string &options, + ColumnFamily(const std::string &name, size_t shard_cnt, const std::string &options, uint32_t hash_l, uint32_t hash_h) : name(name), shard_cnt(shard_cnt), options(options), hash_l(hash_l), hash_h(hash_h) {} }; @@ -142,7 +142,7 @@ private: static void sharding_def_to_columns(const std::vector& sharding_def, std::vector& columns); int create_shards(const rocksdb::Options& opt, - const vector& sharding_def); + const std::vector& sharding_def); int apply_sharding(const rocksdb::Options& opt, const std::string& sharding_text); int verify_sharding(const rocksdb::Options& opt, @@ -470,7 +470,7 @@ err: return static_cast(bbt_opts.block_cache->GetUsage()); } - virtual int64_t get_cache_usage(string prefix) const override { + virtual int64_t get_cache_usage(std::string prefix) const override { auto it = cf_bbt_opts.find(prefix); if (it != cf_bbt_opts.end() && it->second.block_cache) { return static_cast(it->second.block_cache->GetUsage()); @@ -486,15 +486,15 @@ err: virtual std::shared_ptr get_priority_cache() const override { - return dynamic_pointer_cast( + return std::dynamic_pointer_cast( bbt_opts.block_cache); } virtual std::shared_ptr - get_priority_cache(string prefix) const override { + get_priority_cache(std::string prefix) const override { auto it = cf_bbt_opts.find(prefix); if (it != cf_bbt_opts.end()) { - return dynamic_pointer_cast( + return std::dynamic_pointer_cast( it->second.block_cache); } return nullptr; -- 2.39.5