summaryrefslogtreecommitdiff
path: root/netfs/lib/entCache.h
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/lib/entCache.h')
-rw-r--r--netfs/lib/entCache.h66
1 files changed, 50 insertions, 16 deletions
diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h
index c16cd0b..ea941e8 100644
--- a/netfs/lib/entCache.h
+++ b/netfs/lib/entCache.h
@@ -1,37 +1,71 @@
#ifndef ENTCACHE_H
#define ENTCACHE_H
-#include <pwd.h>
-#include <grp.h>
#include <string>
-#include <boost/bimap.hpp>
+#include <set>
+#include <IceUtil/Shared.h>
+#include <IceUtil/Handle.h>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/member.hpp>
+#include <boost/multi_index/ordered_index.hpp>
#include <boost/thread/shared_mutex.hpp>
-template<class id_t, class name_t>
+class User : public IceUtil::Shared {
+ public:
+ User(uid_t, const std::string &, gid_t);
+ uid_t id;
+ std::string name;
+ gid_t group;
+};
+
+class Group : public IceUtil::Shared {
+ public:
+ Group(gid_t, const std::string &);
+
+ bool hasMember(uid_t) const;
+
+ gid_t id;
+ std::string name;
+ std::set<uid_t> members;
+};
+
+template<class entry_t>
class EntCache {
public:
- EntCache();
+ typedef decltype(entry_t::id) id_t;
+ typedef decltype(entry_t::name) name_t;
+ typedef IceUtil::Handle<entry_t> entry_ptr;
+
virtual ~EntCache();
const id_t & getID(const name_t & ) const;
const name_t & getName(const id_t &) const;
+ template<class key_t>
+ entry_ptr getEntry(const key_t &) const;
+
+ static const EntCache<entry_t> instance;
protected:
- virtual void fillCache() const = 0;
- typedef boost::bimap<id_t, name_t> IDs;
- mutable IDs idcache;
- mutable boost::shared_mutex lock;
-};
+ EntCache();
-class UserEntCache : public EntCache<uid_t, std::string> {
- private:
void fillCache() const;
-};
+ template<class key_t>
+ entry_ptr getEntryNoFill(const key_t &) const;
-class GroupEntCache : public EntCache<gid_t, std::string> {
- private:
- void fillCache() const;
+ typedef boost::multi_index::multi_index_container<IceUtil::Handle<entry_t>,
+ boost::multi_index::indexed_by<
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<id_t>, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id)>,
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<std::string>, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name)>
+ > > IDs;
+ mutable IDs idcache;
+ mutable boost::shared_mutex lock;
+ mutable time_t fillTime;
};
+typedef EntCache<User> UserEntCache;
+typedef EntCache<Group> GroupEntCache;
+
#endif