paludis Version 3.0.2
The one true package mangler
pool.hh
1/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3/*
4 * Copyright (c) 2011 Ciaran McCreesh
5 *
6 * This file is part of the Paludis package manager. Paludis is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU General
8 * Public License version 2, as published by the Free Software Foundation.
9 *
10 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifndef PALUDIS_GUARD_PALUDIS_UTIL_POOL_HH
21#define PALUDIS_GUARD_PALUDIS_UTIL_POOL_HH 1
22
23#include <paludis/util/pool-fwd.hh>
25#include <paludis/util/pimp.hh>
26#include <memory>
27
28namespace paludis
29{
30 class PoolKeysHasher;
32
33 template <typename T_>
34 class PALUDIS_VISIBLE Pool :
35 public Singleton<Pool<T_> >
36 {
37 friend class Singleton<Pool<T_> >;
38
39 private:
40 Pimp<Pool<T_> > _imp;
41
42 Pool();
43 ~Pool();
44
45 template <typename... Args_>
46 const std::shared_ptr<const T_> really_create(const Args_ & ...) const PALUDIS_ATTRIBUTE((warn_unused_result));
47
48 public:
49 template <typename... Args_>
50 const std::shared_ptr<const T_> create(const Args_ & ...) const PALUDIS_ATTRIBUTE((warn_unused_result));
51
52 // can't explicitly instantiate variadics
53
54 template <typename T1_>
55 const std::shared_ptr<const T_> create(const T1_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
56
57 template <typename T1_, typename T2_>
58 const std::shared_ptr<const T_> create(const T1_ &, const T2_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
59
60 template <typename T1_, typename T2_, typename T3_>
61 const std::shared_ptr<const T_> create(const T1_ &, const T2_ &, const T3_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
62
63 template <typename T1_, typename T2_, typename T3_, typename T4_>
64 const std::shared_ptr<const T_> create(const T1_ &, const T2_ &, const T3_ &, const T4_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
65 };
66
67 class PALUDIS_VISIBLE PoolKey
68 {
69 private:
70 int _tc;
71
72 protected:
73 explicit PoolKey(int tc);
74
75 virtual bool same_value(const PoolKey &) const = 0;
76
77 public:
78 virtual ~PoolKey() = 0;
79
80 virtual std::size_t hash() const = 0;
81
82 bool same_type_and_value(const PoolKey &) const;
83 };
84
85 template <typename T_>
86 class PALUDIS_VISIBLE ConcretePoolKey :
87 public PoolKey
88 {
89 friend class PoolKeysHasher;
90 friend class PoolKeysComparator;
91
92 private:
93 T_ _value;
94
95 public:
96 explicit ConcretePoolKey(const T_ &);
97
98 ~ConcretePoolKey() override;
99
100 std::size_t hash() const override;
101
102 bool same_value(const PoolKey &) const override;
103 };
104
105 class PALUDIS_VISIBLE PoolKeys
106 {
107 friend class PoolKeysHasher;
108 friend class PoolKeysComparator;
109
110 private:
111 Pimp<PoolKeys> _imp;
112
113 void add_one(const std::shared_ptr<const PoolKey> &);
114 void add();
115
116 public:
117 PoolKeys();
118 PoolKeys(const PoolKeys &);
119 ~PoolKeys();
120
121 template <typename Arg_, typename... Args_>
122 void add(const Arg_ &, const Args_ & ...);
123 };
124
126 {
127 public:
128 std::size_t operator() (const PoolKeys &) const PALUDIS_VISIBLE;
129 };
130
132 {
133 public:
134 bool operator() (const PoolKeys &, const PoolKeys &) const PALUDIS_VISIBLE;
135 };
136
138 {
139 private:
140 static int next();
141
142 public:
143 template <typename T_>
144 static int get();
145 };
146
147 extern template class Pimp<PoolKeys>;
148}
149
150#endif
Definition pimp.hh:52
Definition pool.hh:138
Definition pool.hh:132
Definition pool.hh:126
Definition pool.hh:106
#define PALUDIS_ATTRIBUTE(x)
Definition attributes.hh:53
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24