From 92da4c00cd558c05b6a0a970f7035e77fde08f61 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 16 Jul 2016 11:15:31 +0200 Subject: [PATCH] use std c++11 initializer instead of create_xx hacks --- src/common/rclconfig.cpp | 25 ++++++++++------------ src/index/mimetype.cpp | 3 +-- src/internfile/extrameta.cpp | 2 +- src/utils/smallut.h | 41 ------------------------------------ 4 files changed, 13 insertions(+), 58 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 5c7ce07d..6f6ec642 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -52,8 +52,6 @@ using namespace std; -typedef pair RclPII; - // Static, logically const, RclConfig members are initialized once from the // first object build during process initialization. @@ -268,8 +266,7 @@ RclConfig::RclConfig(const string *argcnf) return; // Default is no threading - m_thrConf = create_vector - (RclPII(-1, 0))(RclPII(-1, 0))(RclPII(-1, 0)); + m_thrConf = {{-1, 0}, {-1, 0}, {-1, 0}}; m_ptrans = new ConfSimple(path_cat(m_confdir, "ptrans").c_str()); @@ -432,8 +429,7 @@ bool RclConfig::getConfParam(const string &name, vector *vip, void RclConfig::initThrConf() { // Default is no threading - m_thrConf = create_vector - (RclPII(-1, 0))(RclPII(-1, 0))(RclPII(-1, 0)); + m_thrConf = {{-1, 0}, {-1, 0}, {-1, 0}}; vector vq; vector vt; @@ -444,12 +440,16 @@ void RclConfig::initThrConf() // If the first queue size is 0, autoconf is requested. if (vq.size() > 0 && vq[0] == 0) { - LOGDEB("RclConfig::initThrConf: autoconf requested\n" ); CpuConf cpus; if (!getCpuConf(cpus) || cpus.ncpus < 1) { LOGERR("RclConfig::initThrConf: could not retrieve cpu conf\n" ); cpus.ncpus = 1; } + if (cpus.ncpus != 1) { + LOGDEB("RclConfig::initThrConf: autoconf requested. " << + cpus.ncpus << " concurrent threads available.\n"); + } + // Arbitrarily set threads config based on number of CPUS. This also // depends on the IO setup actually, so we're bound to be wrong... if (cpus.ncpus == 1) { @@ -457,14 +457,11 @@ void RclConfig::initThrConf() // it seems that the best config here is no threading } else if (cpus.ncpus < 4) { // Untested so let's guess... - m_thrConf = create_vector - (RclPII(2, 2))(RclPII(2, 2))(RclPII(2, 1)); + m_thrConf = {{2, 2}, {2, 2}, {2, 1}}; } else if (cpus.ncpus < 6) { - m_thrConf = create_vector - (RclPII(2, 4))(RclPII(2, 2))(RclPII(2, 1)); + m_thrConf = {{2, 4}, {2, 2}, {2, 1}}; } else { - m_thrConf = create_vector - (RclPII(2, 5))(RclPII(2, 3))(RclPII(2, 1)); + m_thrConf = {{2, 5}, {2, 3}, {2, 1}}; } goto out; } else if (vq.size() > 0 && vq[0] < 0) { @@ -485,7 +482,7 @@ void RclConfig::initThrConf() // Normal case: record info from config m_thrConf.clear(); for (unsigned int i = 0; i < 3; i++) { - m_thrConf.push_back(RclPII(vq[i], vt[i])); + m_thrConf.push_back({vq[i], vt[i]}); } out: diff --git a/src/index/mimetype.cpp b/src/index/mimetype.cpp index 11b7154f..cce8aff3 100644 --- a/src/index/mimetype.cpp +++ b/src/index/mimetype.cpp @@ -58,8 +58,7 @@ static string mimetypefromdata(RclConfig *cfg, const string &fn, bool usfc) // 'file' fallback if the configured command (default: // xdg-mime) is not found - static const vector tradfilecmd = - create_vector(FILE_PROG) ("-i") (fn); + static const vector tradfilecmd = {{FILE_PROG}, {"-i"}, {fn}}; vector cmd; string scommand; diff --git a/src/internfile/extrameta.cpp b/src/internfile/extrameta.cpp index 836b3755..12070172 100644 --- a/src/internfile/extrameta.cpp +++ b/src/internfile/extrameta.cpp @@ -99,7 +99,7 @@ void reapMetaCmds(RclConfig* cfg, const string& path, const vector& reapers = cfg->getMDReapers(); if (reapers.empty()) return; - map smap = create_map('f', path); + map smap = {{'f', path}}; for (vector::const_iterator rp = reapers.begin(); rp != reapers.end(); rp++) { vector cmd; diff --git a/src/utils/smallut.h b/src/utils/smallut.h index 09b05071..2bbd2015 100644 --- a/src/utils/smallut.h +++ b/src/utils/smallut.h @@ -218,45 +218,4 @@ private: Internal *m; }; -// Code for static initialization of an stl map. Somewhat like Boost.assign. -// Ref: http://stackoverflow.com/questions/138600/initializing-a-static-stdmapint-int-in-c -// Example use: map m = create_map (1,2) (3,4) (5,6) (7,8); - -template -class create_map { -private: - std::map m_map; -public: - create_map(const T& key, const U& val) { - m_map[key] = val; - } - - create_map& operator()(const T& key, const U& val) { - m_map[key] = val; - return *this; - } - - operator std::map() { - return m_map; - } -}; -template -class create_vector { -private: - std::vector m_vector; -public: - create_vector(const T& val) { - m_vector.push_back(val); - } - - create_vector& operator()(const T& val) { - m_vector.push_back(val); - return *this; - } - - operator std::vector() { - return m_vector; - } -}; - #endif /* _SMALLUT_H_INCLUDED_ */