paludis Version 3.0.2
The one true package mangler
repository_factory.hh
1/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3/*
4 * Copyright (c) 2008, 2009, 2010, 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_REPOSITORY_FACTORY_HH
21#define PALUDIS_GUARD_PALUDIS_REPOSITORY_FACTORY_HH 1
22
23#include <paludis/repository_factory-fwd.hh>
25#include <paludis/util/pimp.hh>
27#include <paludis/util/wrapped_forward_iterator.hh>
31#include <paludis/name-fwd.hh>
32#include <functional>
33#include <memory>
34
35namespace paludis
36{
38
39 class PALUDIS_VISIBLE RepositoryFactory :
40 public Singleton<RepositoryFactory>
41 {
42 friend class Singleton<RepositoryFactory>;
43
44 private:
46
47 RepositoryFactory();
48 ~RepositoryFactory();
49
50 public:
51 typedef std::function<std::string (const std::string &)> KeyFunction;
52
53 typedef std::function<const std::shared_ptr<Repository>(
54 Environment * const,
55 const KeyFunction &
56 )> CreateFunction;
57
58 typedef std::function<const std::shared_ptr<const RepositoryNameSet> (
59 const Environment * const,
60 const KeyFunction &
61 )> DependenciesFunction;
62
63 typedef std::function<const RepositoryName (
64 const Environment * const,
65 const KeyFunction &
66 )> NameFunction;
67
68 typedef std::function<int (
69 const Environment * const,
70 const KeyFunction &
71 )> ImportanceFunction;
72
73 /**
74 * Construct a given repository, or throw ConfigurationError.
75 *
76 * If the repository to be created has dependencies upon another
77 * repository, that repository must have been created and added
78 * to the environment's package database first.
79 *
80 * The returned repository is <em>not</em> added to the Environment's
81 * package database.
82 *
83 * \param key_function should return the value for a given key. The
84 * 'format' key must return a value (e.g. 'ebuild'), which is used
85 * to select the return type. The 'repo_name' key's value should be
86 * the file that best describes the location of the file containing
87 * the repository config, if such a file exists. Other key names are
88 * repository defined, but typically include things like 'location'
89 * and 'sync'.
90 */
91 const std::shared_ptr<Repository> create(
92 Environment * const env,
93 const KeyFunction & key_function
94 ) const PALUDIS_ATTRIBUTE((warn_unused_result));
95
96 /**
97 * Find the name of the repository that would be constructed if the
98 * supplied parameters were passed to RepositoryFactory::create.
99 *
100 * \see RepositoryFactory::create for parameter documentation.
101 */
103 const Environment * const env,
104 const KeyFunction & key_function
105 ) const PALUDIS_ATTRIBUTE((warn_unused_result));
106
107 /**
108 * Find the importance of the repository that would be constructed if the
109 * supplied parameters were passed to RepositoryFactory::create.
110 *
111 * \see RepositoryFactory::create for parameter documentation.
112 */
114 const Environment * const env,
115 const KeyFunction & key_function
116 ) const PALUDIS_ATTRIBUTE((warn_unused_result));
117
118 /**
119 * Fetch the names of any repositories depended upon by a particular
120 * repository.
121 *
122 * \see RepositoryFactory::create for parameter documentation.
123 */
124 const std::shared_ptr<const RepositoryNameSet> dependencies(
125 const Environment * const env,
126 const KeyFunction & key_function
127 ) const PALUDIS_ATTRIBUTE((warn_unused_result));
128
129 /**
130 * Add a repository format.
131 *
132 * \param formats must have at least one value, and no value may be
133 * specified more than once across all invocations.
134 *
135 * \param name_function is used to implement RepositoryFactory::name.
136 *
137 * \param importance_function is used to implement RepositoryFactory::importance.
138 *
139 * \param create_function is used to implement RepositoryFactory::create.
140 *
141 * \param dependencies_function is used to implement
142 * RepositoryFactory::dependencies.
143 */
145 const std::shared_ptr<const Set<std::string> > & formats,
146 const NameFunction & name_function,
147 const ImportanceFunction & importance_function,
148 const CreateFunction & create_function,
149 const DependenciesFunction & dependencies_function
150 );
151
152 struct ConstIteratorTag;
154 ConstIterator begin_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
155 ConstIterator end_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
156 };
157
158 template <typename RepositoryClass_>
159 void register_repositories(const RepositoryClass_ * const, RepositoryFactory * const);
160
161 extern template class Pimp<RepositoryFactory>;
162 extern template class PALUDIS_VISIBLE WrappedForwardIterator<RepositoryFactory::ConstIteratorTag, const std::string>;
163}
164
165#endif
Definition environment.hh:203
Definition pimp.hh:52
void add_repository_format(const std::shared_ptr< const Set< std::string > > &formats, const NameFunction &name_function, const ImportanceFunction &importance_function, const CreateFunction &create_function, const DependenciesFunction &dependencies_function)
const std::shared_ptr< Repository > create(Environment *const env, const KeyFunction &key_function) const PALUDIS_ATTRIBUTE((warn_unused_result))
const RepositoryName name(const Environment *const env, const KeyFunction &key_function) const PALUDIS_ATTRIBUTE((warn_unused_result))
int importance(const Environment *const env, const KeyFunction &key_function) const PALUDIS_ATTRIBUTE((warn_unused_result))
const std::shared_ptr< const RepositoryNameSet > dependencies(const Environment *const env, const KeyFunction &key_function) const PALUDIS_ATTRIBUTE((warn_unused_result))
Definition set.hh:51
Definition singleton.hh:45
Definition wrapped_forward_iterator.hh:42
WrappedValue< RepositoryNameTag > RepositoryName
Definition name-fwd.hh:105
#define PALUDIS_ATTRIBUTE(x)
Definition attributes.hh:53
#define PALUDIS_VISIBLE
Definition attributes.hh:59
Definition about_metadata-fwd.hh:24