]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: build without "using namespace std"
authorKefu Chai <kchai@redhat.com>
Wed, 11 Aug 2021 03:42:44 +0000 (11:42 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 13 Aug 2021 04:21:38 +0000 (12:21 +0800)
* 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 <kchai@redhat.com>
27 files changed:
src/tools/RadosDump.cc
src/tools/RadosDump.h
src/tools/ceph-client-debug.cc
src/tools/ceph-dencoder/ceph_dencoder.cc
src/tools/ceph-dencoder/denc_plugin.h
src/tools/ceph-dencoder/denc_registry.h
src/tools/ceph_authtool.cc
src/tools/ceph_conf.cc
src/tools/ceph_dedup_tool.cc
src/tools/ceph_kvstore_tool.cc
src/tools/ceph_monstore_tool.cc
src/tools/ceph_objectstore_tool.cc
src/tools/ceph_osdomap_tool.cc
src/tools/crushtool.cc
src/tools/immutable_object_cache/ObjectCacheStore.h
src/tools/immutable_object_cache/Types.cc
src/tools/kvstore_tool.cc
src/tools/monmaptool.cc
src/tools/osdmaptool.cc
src/tools/psim.cc
src/tools/rados/PoolDump.cc
src/tools/rados/RadosImport.cc
src/tools/rados/rados.cc
src/tools/radosacl.cc
src/tools/rbd_wnbd/rbd_wnbd.cc
src/tools/rebuild_mondb.cc
src/tools/scratchtoolpp.cc

index 420cd9fc61391d062b39e423a41fd237074d4c37..014041bff84be95b9b9b4e125ec489899ca423a8 100644 (file)
@@ -14,6 +14,9 @@
 
 #include "RadosDump.h"
 
+using std::cerr;
+using std::cout;
+
 int RadosDump::read_super()
 {
   bufferlist ebl;
index 213351e17b0b448797ed288c2556c25bcb99c3b2..dd7951d22ae5cea2cb0cf44eed44b8b7428e1ed9 100644 (file)
@@ -219,15 +219,15 @@ struct data_section {
 };
 
 struct attr_section {
-  map<string,bufferlist,less<>> data;
-  explicit attr_section(const map<string,bufferlist,less<>> &data) : data(data) { }
-  explicit attr_section(map<string, bufferptr, less<>> &data_)
+  using data_t = std::map<std::string,bufferlist,std::less<>>;
+  data_t data;
+  explicit attr_section(const data_t &data) : data(data) { }
+  explicit attr_section(std::map<std::string, bufferptr, std::less<>> &data_)
   {
-    for (std::map<std::string, bufferptr>::iterator i = data_.begin();
-         i != data_.end(); ++i) {
+    for (auto& [k, v] : data_) {
       bufferlist bl;
-      bl.push_back(i->second);
-      data[i->first] = bl;
+      bl.push_back(v);
+      data.emplace(k, std::move(bl));
     }
   }
 
@@ -263,8 +263,8 @@ struct omap_hdr_section {
 };
 
 struct omap_section {
-  map<string, bufferlist> omap;
-  explicit omap_section(const map<string, bufferlist> &omap) :
+  std::map<std::string, bufferlist> omap;
+  explicit omap_section(const std::map<std::string, bufferlist> &omap) :
     omap(omap) { }
   omap_section() { }
 
@@ -289,7 +289,7 @@ struct metadata_section {
   PastIntervals past_intervals;
   OSDMap osdmap;
   bufferlist osdmap_bl;  // Used in lieu of encoding osdmap due to crc checking
-  map<eversion_t, hobject_t> divergent_priors;
+  std::map<eversion_t, hobject_t> divergent_priors;
   pg_missing_t missing;
 
   metadata_section(
@@ -332,14 +332,14 @@ struct metadata_section {
     if (struct_v >= 6) {
       decode(past_intervals, bl);
     } else if (struct_v > 1) {
-      cout << "NOTICE: Older export with classic past_intervals" << std::endl;
+      std::cout << "NOTICE: Older export with classic past_intervals" << std::endl;
     } else {
-      cout << "NOTICE: Older export without past_intervals" << std::endl;
+      std::cout << "NOTICE: Older export without past_intervals" << std::endl;
     }
     if (struct_v > 2) {
       osdmap.decode(bl);
     } else {
-      cout << "WARNING: Older export without OSDMap information" << std::endl;
+      std::cout << "WARNING: Older export without OSDMap information" << std::endl;
     }
     if (struct_v > 3) {
       decode(divergent_priors, bl);
index 7a43c9c2a6d26f91aeea3605170a135b1e7d5723..5e0b4c4390de22d141da42f66f28539a6c0e969b 100644 (file)
@@ -26,6 +26,8 @@
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_client
 
+using namespace std;
+
 void usage()
 {
   std::cout << "Usage: ceph-client-debug [options] <inode number>" << std::endl;
index 03f0adf99f5dc21027fd77cc51594954b62e5bfc..f8969cb1a895a2c9912f2c5c59e7e014ec9395fd 100644 (file)
@@ -30,6 +30,8 @@
 
 namespace fs = std::filesystem;
 
+using namespace std;
+
 void usage(ostream &out)
 {
   out << "usage: ceph-dencoder [commands ...]" << std::endl;
index 3b17a4f55da8e31c4bb6169f3a5a9d9044290b8d..a203551eadc5516805711998b3757c8981f1e7a3 100644 (file)
@@ -30,7 +30,7 @@ public:
 #endif
   }
   const dencoders_t& register_dencoders() {
-    static constexpr string_view REGISTER_DENCODERS_FUNCTION = "register_dencoders\0";
+    static constexpr std::string_view REGISTER_DENCODERS_FUNCTION = "register_dencoders\0";
 
     assert(mod);
     using register_dencoders_t = void (*)(DencoderPlugin*);
index dc1db36d3f221baf6f1ca89957e8a95a8a876b7f..aad52cbf710527dd9cd57f73ba78a2b5e0964912 100644 (file)
@@ -42,7 +42,7 @@ template<class T>
 class DencoderBase : public Dencoder {
 protected:
   T* m_object;
-  list<T*> m_list;
+  std::list<T*> m_list;
   bool stray_okay;
   bool nondeterministic;
 
@@ -66,7 +66,7 @@ public:
       return e.what();
     }
     if (!stray_okay && !p.end()) {
-      ostringstream ss;
+      std::ostringstream ss;
       ss << "stray data at end of buffer, offset " << p.get_off();
       return ss.str();
     }
@@ -84,14 +84,14 @@ public:
   int num_generated() override {
     return m_list.size();
   }
-  string select_generated(unsigned i) override {
+  std::string select_generated(unsigned i) override {
     // allow 0- or 1-based (by wrapping)
     if (i == 0)
       i = m_list.size();
     if ((i == 0) || (i > m_list.size()))
       return "invalid id for generated object";
     m_object = *(std::next(m_list.begin(), i-1));
-    return string();
+    return {};
   }
 
   bool is_deterministic() override {
@@ -162,13 +162,13 @@ public:
 template<class T>
 class MessageDencoderImpl : public Dencoder {
   ref_t<T> m_object;
-  list<ref_t<T>> m_list;
+  std::list<ref_t<T>> m_list;
 
 public:
   MessageDencoderImpl() : m_object{make_message<T>()} {}
   ~MessageDencoderImpl() override {}
 
-  string decode(bufferlist bl, uint64_t seek) override {
+  std::string decode(bufferlist bl, uint64_t seek) override {
     auto p = bl.cbegin();
     p.seek(seek);
     try {
@@ -176,7 +176,7 @@ public:
       if (!n)
        throw std::runtime_error("failed to decode");
       if (n->get_type() != m_object->get_type()) {
-       stringstream ss;
+       std::stringstream ss;
        ss << "decoded type " << n->get_type() << " instead of expected " << m_object->get_type();
        throw std::runtime_error(ss.str());
       }
@@ -186,11 +186,11 @@ public:
       return e.what();
     }
     if (!p.end()) {
-      ostringstream ss;
+      std::ostringstream ss;
       ss << "stray data at end of buffer, offset " << p.get_off();
       return ss.str();
     }
-    return string();
+    return {};
   }
 
   void encode(bufferlist& out, uint64_t features) override {
@@ -207,14 +207,14 @@ public:
   int num_generated() override {
     return m_list.size();
   }
-  string select_generated(unsigned i) override {
+  std::string select_generated(unsigned i) override {
     // allow 0- or 1-based (by wrapping)
     if (i == 0)
       i = m_list.size();
     if ((i == 0) || (i > m_list.size()))
       return "invalid id for generated object";
     m_object = *(std::next(m_list.begin(), i-1));
-    return string();
+    return {};
   }
   bool is_deterministic() override {
     return true;
index c650cc880496c1074be37431c9409fadf023db28..8f627fa4bdea8b137da5647fddac6d9876010c2a 100644 (file)
 #include "auth/Auth.h"
 #include "auth/KeyRing.h"
 
+using std::map;
+using std::string;
+using std::vector;
+using std::cerr;
+using std::cout;
+
 void usage()
 {
   cout << "usage: ceph-authtool keyringfile [OPTIONS]...\n"
index d26cbb03994969a93e5e211a442fc6479e6dc2b6..a88e75b425aac75c3cd19d796cce39abfa684cc2 100644 (file)
 
 using std::deque;
 using std::string;
+using std::unique_ptr;
+using std::cerr;
+using std::cout;
+using std::vector;
 
 static void usage(std::ostream& out)
 {
@@ -248,7 +252,7 @@ int main(int argc, const char **argv)
        cerr << "unable to parse option: '" << *i << "'" << std::endl;
        cerr << "args:";
        for (auto arg : orig_args) {
-         cerr << " " << quoted(arg);
+         cerr << " " << std::quoted(arg);
        }
        cerr << std::endl;
        usage(cerr);
index e215fbe3887b43e9e5ce2fefccbc0f4f42ce5d09..507ff99b8f49915586ce65941c8c73e42cc1d993 100644 (file)
@@ -49,6 +49,8 @@
 #include "global/signal_handler.h"
 #include "common/CDC.h"
 
+using namespace std;
+
 struct EstimateResult {
   std::unique_ptr<CDC> cdc;
 
index fdcf54fb1dddbd4349fd901e500ed1ba6857d23e..4d32415ad16e179bf301013e72f45b883f8aa6f9 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "kvstore_tool.h"
 
+using namespace std;
+
 void usage(const char *pname)
 {
   std::cout << "Usage: " << pname << " <leveldb|rocksdb|bluestore-kv> <store path> command [args...]\n"
index 05c815f0e39c361e7e131f7637f2e5f6784f923b..69782690b4053951c0c7a20ae7a57477297925cc 100644 (file)
@@ -38,6 +38,8 @@
 
 namespace po = boost::program_options;
 
+using namespace std;
+
 class TraceIter {
   int fd;
   unsigned idx;
index c4d30cc444b10c285928074736be4d891cb3ef1d..8690bd96a1887027f9fd02e6ee3ec86cd3bbb67f 100644 (file)
@@ -46,6 +46,7 @@
 #include "include/compat.h"
 #include "include/util.h"
 
+using namespace std;
 namespace po = boost::program_options;
 
 #ifdef INTERNAL_TEST
index 8e15851d848ee561da159ec1845a506742c4895e..507587d3684da642b8e6803c32fc9da27dfe9425 100644 (file)
@@ -22,6 +22,7 @@
 #include "os/filestore/DBObjectMap.h"
 #include "kv/KeyValueDB.h"
 
+using namespace std;
 namespace po = boost::program_options;
 
 int main(int argc, char **argv) {
index 6d996e73da16233d2e545ceaf7ca779ee9cdf128..4a064931cda4f05fbdc35043c90b246c64bb88c3 100644 (file)
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_crush
 
+using std::cerr;
+using std::cout;
+using std::decay_t;
+using std::ifstream;
+using std::ios;
+using std::is_same_v;
+using std::map;
+using std::ofstream;
+using std::pair;
+using std::set;
+using std::string;
+using std::vector;
 
 const char *infn = "stdin";
 
index 607921320aef4541f4f6c9565ab08ee501e15f11..4cf4ca0d9a607b5c18ed3cef976433d9066d934a 100644 (file)
@@ -20,8 +20,8 @@ class Context;
 namespace ceph {
 namespace immutable_obj_cache {
 
-typedef shared_ptr<librados::Rados> RadosRef;
-typedef shared_ptr<librados::IoCtx> IoCtxRef;
+typedef std::shared_ptr<librados::Rados> RadosRef;
+typedef std::shared_ptr<librados::IoCtx> IoCtxRef;
 
 class ObjectCacheStore {
  public:
index 860017d6aae0a7adffd32e36244a99294edcb922..fc3eaa308a159c7e19e1db789fdf83744f2a1ac1 100644 (file)
@@ -112,7 +112,7 @@ void ObjectCacheReadData::decode_payload(bufferlist::const_iterator i,
 }
 
 ObjectCacheReadReplyData::ObjectCacheReadReplyData(uint16_t t, uint64_t s,
-                                                   string cache_path)
+                                                   std::string cache_path)
   : ObjectCacheRequest(t, s), cache_path(cache_path) {}
 ObjectCacheReadReplyData::ObjectCacheReadReplyData(uint16_t t, uint64_t s)
   : ObjectCacheRequest(t, s) {}
index 88d2b50722c39cf6bdca8c09a2510abca71e47aa..1e01b1792e775073a67337650b09307c0444b934 100644 (file)
@@ -12,6 +12,8 @@
 #include "kv/KeyValueDB.h"
 #include "kv/KeyValueHistogram.h"
 
+using namespace std;
+
 StoreTool::StoreTool(const string& type,
                     const string& path,
                     bool to_repair,
index 23962997d218c7ad8fa288226244607fb87969bd..ae8fccf53921c2e826ae2582ae8ee9d85ea93a05 100644 (file)
 #include "include/str_list.h"
 #include "mon/MonMap.h"
 
+using std::cerr;
+using std::cout;
+using std::list;
+using std::map;
+using std::ostream;
+using std::set;
+using std::string;
+using std::string_view;
+using std::vector;
 
 void usage()
 {
index b876d6148ce790b7be53f1490f9625e078d2c16f..0cbaffcd1a6c0aa66c0e7df4982812abedd441cd 100644 (file)
@@ -26,6 +26,7 @@
 #include "global/global_init.h"
 #include "osd/OSDMap.h"
 
+using namespace std;
 
 void usage()
 {
index 90e6fb95899fb27f775e4f3b2e45bb8d4875ddf4..965b09d0bc5c5c115c1f8fdb5703b53403798a4d 100644 (file)
@@ -4,6 +4,8 @@
 #include "osd/OSDMap.h"
 #include "include/buffer.h"
 
+using namespace std;
+
 int main(int argc, char **argv)
 {
   /*
index 207017036eec5dd1163e363c40dafd1b1b28a7d8..9f51a1391631cb233a1e9f32591a52583d0dd025 100644 (file)
 #include "PoolDump.h"
 
 using namespace librados;
+using std::cerr;
+using std::less;
+using std::map;
+using std::string;
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rados
index 0a901b70945961a6c81173c6d067d9885ef9e59b..0b27c077b214c31b7b2b88c8e0021306c1e5aec3 100644 (file)
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rados
 
+using std::cerr;
+using std::cout;
+using std::map;
+using std::string;
+
 int RadosImport::import(std::string pool, bool no_overwrite)
 {
   librados::IoCtx ioctx;
index 79aa7cc634f1bd04e5cf101375b6d714d742d7b1..75a7ad07c43dd9bb02505c9b9185cc265a84e19a 100644 (file)
 
 #include "osd/ECUtil.h"
 
+using namespace std::chrono_literals;
 using namespace librados;
 using ceph::util::generate_random_number;
+using std::cerr;
+using std::cout;
+using std::dec;
+using std::hex;
+using std::less;
+using std::list;
+using std::map;
+using std::multiset;
+using std::ofstream;
+using std::ostream;
+using std::pair;
+using std::set;
+using std::string;
+using std::unique_ptr;
+using std::vector;
 
 // two steps seem to be necessary to do this right
 #define STR(x) _STR(x)
@@ -989,7 +1005,7 @@ int LoadGen::run()
       ++total_sec;
       std::streamsize original_precision = cout.precision();
       cout.precision(3);
-      cout << setw(5) << total_sec << ": throughput=" << rate  << "MB/sec" << " pending data=" << sent - completed << std::endl;
+      cout << std::setw(5) << total_sec << ": throughput=" << rate  << "MB/sec" << " pending data=" << sent - completed << std::endl;
       cout.precision(original_precision);
       stamp_time = now; 
     }
index 3b071705b018c96ffb8ab0a3d3383f1a58bf94b3..3bfef8fb1576ed295bf37752ea9f469ee42c9104 100644 (file)
@@ -19,6 +19,7 @@
 #include "include/types.h"
 #include "include/rados/librados.hpp"
 
+using namespace std;
 using namespace librados;
 
 void buf_to_hex(const unsigned char *buf, int len, char *str)
index d2bb9d8e96e917c2e9100b81c159de14b2322ac0..0c11c28fe28d0424a9f721e14b8c045f353e1c83 100644 (file)
@@ -53,6 +53,7 @@
 #undef dout_prefix
 #define dout_prefix *_dout << "rbd-wnbd: "
 
+using namespace std;
 using boost::locale::conv::utf_to_utf;
 
 std::wstring to_wstring(const std::string& str)
index 8e3d5b45888024813bf35a1cf422fe5a61d0c057..17e4dadcfdd4fa8a8557e8883ace159b5a0b6304 100644 (file)
@@ -5,6 +5,8 @@
 #include "os/ObjectStore.h"
 #include "osd/OSD.h"
 
+using namespace std;
+
 static int update_auth(const string& keyring_path,
                        const OSDSuperblock& sb,
                        MonitorDBStore& ms);
index 26a35bebce7081e15e5dc53302b57ede626c54c3..0794e42f4bc18d52e4ca209f0865d7f5cb833400 100644 (file)
@@ -27,6 +27,8 @@ using namespace librados;
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 
+using namespace std;
+
 void buf_to_hex(const unsigned char *buf, int len, char *str)
 {
   str[0] = '\0';