diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-03-04 21:59:48 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-03-05 12:43:49 +0000 |
commit | c7542bf7b1cd90641e55924d5abd3b71da681d73 (patch) | |
tree | 4749615849f316f7082cc87d0e9f385e82567b6d | |
parent | Fix string_view_support includes (diff) | |
download | icetray-c7542bf7b1cd90641e55924d5abd3b71da681d73.tar.bz2 icetray-c7542bf7b1cd90641e55924d5abd3b71da681d73.tar.xz icetray-c7542bf7b1cd90641e55924d5abd3b71da681d73.zip |
Simplify a few bits of code with fold expressions
-rw-r--r-- | icetray/icetray/abstractCachingDatabaseClient.cpp | 5 | ||||
-rw-r--r-- | icetray/icetray/abstractCachingDatabaseClient.h | 17 | ||||
-rw-r--r-- | icetray/icetray/abstractDatabaseClient.h | 13 | ||||
-rw-r--r-- | icetray/icetray/logger.h | 11 |
4 files changed, 10 insertions, 36 deletions
diff --git a/icetray/icetray/abstractCachingDatabaseClient.cpp b/icetray/icetray/abstractCachingDatabaseClient.cpp index 3671f63..fcd5ed5 100644 --- a/icetray/icetray/abstractCachingDatabaseClient.cpp +++ b/icetray/icetray/abstractCachingDatabaseClient.cpp @@ -16,9 +16,4 @@ namespace IceTray { AbstractDatabaseClient(d) { } - - void - AbstractCachingDatabaseClient::keyPushParams(CacheKey &) - { - } } diff --git a/icetray/icetray/abstractCachingDatabaseClient.h b/icetray/icetray/abstractCachingDatabaseClient.h index e9e91e7..eac937c 100644 --- a/icetray/icetray/abstractCachingDatabaseClient.h +++ b/icetray/icetray/abstractCachingDatabaseClient.h @@ -18,6 +18,7 @@ // IWYU pragma: no_include "cache.impl.h" // IWYU pragma: no_include <boost/multi_index/detail/bidir_node_iterator.hpp> // IWYU pragma: no_include <boost/operators.hpp> +// IWYU pragma: no_include <variant> namespace IceTray { class DLL_PUBLIC AbstractCachingDatabaseClient : public AbstractDatabaseClient { @@ -32,11 +33,8 @@ namespace IceTray { inline Domain fetchCache(const SqlSource & sql, time_t cacheTime, const Params &... params) { - CacheKey key; - key.reserve(sizeof...(Params) + 2); - key.push_back(*sql.getCommandOptions()->hash); - key.push_back(typeid(Domain).hash_code()); - keyPushParams(key, params...); + const CacheKey key {sql.getCommandOptions()->hash.value_or(0), typeid(Domain).hash_code(), + (std::hash<Params>()(params))...}; if (auto cached = cache.get(key)) { return std::any_cast<Domain>(*cached); } @@ -46,15 +44,6 @@ namespace IceTray { } private: - template<typename Param, typename... Params> - static void inline keyPushParams(CacheKey & k, const Param & p, const Params &... params) - { - k.push_back(std::hash<Param>()(p)); - keyPushParams(k, params...); - } - - static void keyPushParams(CacheKey &); - using Cache = AdHoc::Cache<CacheItem, CacheKey>; Cache cache; }; diff --git a/icetray/icetray/abstractDatabaseClient.h b/icetray/icetray/abstractDatabaseClient.h index cc81251..85f95b2 100644 --- a/icetray/icetray/abstractDatabaseClient.h +++ b/icetray/icetray/abstractDatabaseClient.h @@ -51,7 +51,7 @@ namespace IceTray { const Params &... params) { auto s = sql.select(c); - bind(0, s.get(), params...); + bind(s.get(), params...); return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Domain>(s.get(), typeIdCol); } @@ -68,20 +68,17 @@ namespace IceTray { modify(DB::Connection * c, const SqlSource & sql, const Params &... params) { auto s = sql.modify(c); - bind(0, s.get(), params...); + bind(s.get(), params...); return s->execute(); } protected: - template<typename Param, typename... Params> - static void inline bind(unsigned int offset, DB::Command * cmd, const Param & p, const Params &... params) + template<typename... Params> static void inline bind(DB::Command * cmd, const Params &... params) { - cmd->bindParam(offset, p); - bind(offset + 1, cmd, params...); + unsigned int offset {}; + (cmd->bindParam(offset++, params), ...); } - static void inline bind(unsigned int, DB::Command *) { } - DB::ConnectionPoolPtr db; }; } diff --git a/icetray/icetray/logger.h b/icetray/icetray/logger.h index d625217..81b64c6 100644 --- a/icetray/icetray/logger.h +++ b/icetray/icetray/logger.h @@ -72,20 +72,13 @@ namespace IceTray { const auto fl = firstFor(priority); if (fl != logs.end()) { auto fmt = AdHoc::Buffer::getFormat(msgfmt); - messagebf(fl, priority, fmt, args...); + (fmt % ... % args); + messagebf(fl, priority, fmt); } } private: void message(LogLevelWriters::const_iterator fl, LogLevel priority, const std::string & msg) const; - template<typename Arg, typename... OtherArgs> - void - messagebf(LogLevelWriters::const_iterator fl, LogLevel priority, boost::format & f, const Arg & arg, - const OtherArgs &... otherargs) const - { - f % arg; - messagebf(fl, priority, f, otherargs...); - } void messagebf(LogLevelWriters::const_iterator fl, LogLevel priority, const boost::format & f) const; LogLevelWriters::const_iterator firstFor(LogLevel priority) const; |