aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/e_mask.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-01-23 12:51:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-01-23 12:51:46 +0000
commit653947f40135832b5e388a90f22adf069584034a (patch)
tree1347c3f78018092ff08df987f61479c9b950ac5c /paludis/repositories/e/e_mask.cc
parent62a3e9ef98827094e0daa27418c4a08677ba1458 (diff)
downloadpaludis-653947f40135832b5e388a90f22adf069584034a.tar.gz
paludis-653947f40135832b5e388a90f22adf069584034a.tar.xz
Share unaccepted keys
Diffstat (limited to 'paludis/repositories/e/e_mask.cc')
-rw-r--r--paludis/repositories/e/e_mask.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/paludis/repositories/e/e_mask.cc b/paludis/repositories/e/e_mask.cc
index e2aba5b5d..a2ff30ac8 100644
--- a/paludis/repositories/e/e_mask.cc
+++ b/paludis/repositories/e/e_mask.cc
@@ -19,10 +19,31 @@
#include <paludis/repositories/e/e_mask.hh>
#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/singleton-impl.hh>
+#include <paludis/util/hashes.hh>
+#include <unordered_map>
using namespace paludis;
using namespace paludis::erepository;
+namespace
+{
+ class EUnacceptedMask :
+ public UnacceptedMask
+ {
+ private:
+ Pimp<EUnacceptedMask> _imp;
+
+ public:
+ EUnacceptedMask(const char, const std::string &, const std::string &);
+ ~EUnacceptedMask();
+
+ char key() const;
+ const std::string description() const;
+ const std::string unaccepted_key_name() const;
+ };
+}
+
namespace paludis
{
template <>
@@ -160,3 +181,43 @@ ERepositoryMask::mask_key_name() const
return _imp->mask_key_name;
}
+namespace
+{
+ typedef std::tuple<char, std::string, std::string> EUnacceptedMaskIndex;
+}
+
+namespace paludis
+{
+ template <>
+ struct Imp<EUnacceptedMaskStore>
+ {
+ mutable Mutex mutex;
+ mutable std::unordered_map<EUnacceptedMaskIndex, std::shared_ptr<const UnacceptedMask>, Hash<EUnacceptedMaskIndex> > store;
+ };
+}
+
+EUnacceptedMaskStore::EUnacceptedMaskStore() :
+ _imp()
+{
+}
+
+EUnacceptedMaskStore::~EUnacceptedMaskStore()
+{
+}
+
+const std::shared_ptr<const UnacceptedMask>
+EUnacceptedMaskStore::fetch(const char c, const std::string & s, const std::string & k)
+{
+ EUnacceptedMaskIndex index(c, s, k);
+
+ Lock lock(_imp->mutex);
+ auto i(_imp->store.find(index));
+ if (i == _imp->store.end())
+ i = _imp->store.insert(std::make_pair(index, std::make_shared<EUnacceptedMask>(c, s, k))).first;
+
+ return i->second;
+}
+
+template class Singleton<EUnacceptedMaskStore>;
+template class Pimp<EUnacceptedMaskStore>;
+