paludis  Version 2.0.0
environment_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_ENVIRONMENT_FACTORY_HH
21 #define PALUDIS_GUARD_PALUDIS_ENVIRONMENT_FACTORY_HH 1
22 
23 #include <paludis/environment_factory-fwd.hh>
25 #include <paludis/util/pimp.hh>
26 #include <paludis/util/set-fwd.hh>
27 #include <paludis/util/no_type.hh>
30 #include <memory>
31 #include <functional>
32 
33 namespace paludis
34 {
35  extern template class PALUDIS_VISIBLE Singleton<EnvironmentFactory>;
36 
38  {
39  };
40 
41  /**
42  * Factory for Environment creation.
43  *
44  * \ingroup g_environment
45  * \since 0.30
46  */
49  {
50  friend class Singleton<EnvironmentFactory>;
51 
52  private:
54 
57 
58  public:
59  typedef std::function<const std::shared_ptr<Environment>(const std::string &)> CreateFunction;
60 
61  /**
62  * Create an Environment subclass from the specified spec.
63  *
64  * \param spec The environment spec, which is in the form
65  * env:suffix, where env is the string representing an
66  * Environment's kind (e.g. "paludis", "portage") and
67  * suffix is the information to pass to the constructing
68  * function (for paludis, a config suffix, and for portage,
69  * a location). If env is not specified, it defaults to
70  * trying paludis then portage. If suffix is not specified,
71  * it defaults to an empty string. If no colon is present,
72  * the supplied string is taken as env (this includes an
73  * empty string).
74  */
75  const std::shared_ptr<Environment> create(const std::string & spec) const
76  PALUDIS_ATTRIBUTE((warn_unused_result));
77 
78  /**
79  * Add a repository format.
80  *
81  * \param formats must have at least one value, and no value may be
82  * specified more than once across all invocations.
83  *
84  * \param create_function is used to implement EnvironmentFactory::create.
85  */
86  void add_environment_format(
87  const std::shared_ptr<const Set<std::string> > & formats,
88  const CreateFunction & create_function
89  );
90  };
91 
92  template <typename EnvironmentClass_>
93  void register_environment(const EnvironmentClass_ * const, EnvironmentFactory * const);
94 
95  extern template class Pimp<EnvironmentFactory>;
96 }
97 
98 #endif
Definition: pimp.hh:51
Definition: set-fwd.hh:35
Definition: environment_factory.hh:37
Definition: environment_factory.hh:47
#define PALUDIS_ATTRIBUTE(x)
Definition: attributes.hh:64
#define PALUDIS_VISIBLE
Definition: attributes.hh:71