From 2dcfca817fa702c0bc97a09d445112d8459329c1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Apr 2020 23:25:54 +0100 Subject: Move boost multi index out of header --- netfs/lib/entCache.cpp | 39 ++++++++++++++++++++++++++++++++++----- netfs/lib/entCache.h | 16 +++++----------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index 6af0e24..9b78dff 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -3,6 +3,35 @@ #include #include #include +#include +#include +#include +#include + +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); + + +template +class EntCache::Ids : public boost::multi_index::multi_index_container, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique< + boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>, + boost::multi_index::ordered_unique< + boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>> + > > { + }; + +template +EntCache::EntCache() : + idcache(std::make_unique()) +{ +} + +template +EntCache::~EntCache() = default; template void @@ -45,7 +74,7 @@ typename EntCache::entry_ptr EntCache::getEntryNoFill(const key_t & key) const { SharedLock(lock); - auto & collection = idcache.template get(); + auto & collection = idcache->template get(); auto i = collection.find(key); if (i != collection.end()) { return *i; @@ -68,11 +97,11 @@ EntCache::fillCache() const { Lock(lock); setpwent(); - idcache.clear(); + idcache->clear(); std::array buf {}; struct passwd pwbuf {}, * pwp; while (getpwent_r(&pwbuf, buf.data(), buf.size(), &pwp) == 0) { - idcache.insert(std::make_shared(pwp->pw_uid, pwp->pw_name, pwp->pw_gid)); + idcache->insert(std::make_shared(pwp->pw_uid, pwp->pw_name, pwp->pw_gid)); } endpwent(); time(&fillTime); @@ -91,7 +120,7 @@ EntCache::fillCache() const Lock(lock); setgrent(); std::array buf {}; - idcache.clear(); + idcache->clear(); struct group grpbuf {}, * grp; EntCache instance; while (getgrent_r(&grpbuf, buf.data(), buf.size(), &grp) == 0) { @@ -103,7 +132,7 @@ EntCache::fillCache() const catch (const NetFS::SystemError &) { } } - idcache.insert(g); + idcache->insert(std::move(g)); } endgrent(); time(&fillTime); diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index 2833141..73cd36d 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -3,9 +3,6 @@ #include #include -#include -#include -#include #include #include @@ -31,6 +28,9 @@ class Group { template class EntCache : public EntryResolver { public: + EntCache(); + ~EntCache() override; + using id_t = decltype(entry_t::id); using name_t = decltype(entry_t::name); using entry_ptr = std::shared_ptr; @@ -45,14 +45,8 @@ class EntCache : public EntryResolver { template entry_ptr getEntryNoFill(const key_t &) const; - using IDs = boost::multi_index::multi_index_container, - boost::multi_index::indexed_by< - boost::multi_index::ordered_unique< - boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>, - boost::multi_index::ordered_unique< - boost::multi_index::tag, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>> - > >; - mutable IDs idcache; + class Ids; + std::unique_ptr idcache; mutable std::shared_mutex lock; mutable time_t fillTime {0}; }; -- cgit v1.2.3