blob: ea941e8f5544c6ddcede60a80fa575ba565110cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#ifndef ENTCACHE_H
#define ENTCACHE_H
#include <string>
#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>
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:
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:
EntCache();
void fillCache() const;
template<class key_t>
entry_ptr getEntryNoFill(const key_t &) 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
|