environment_factory.hh

00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2008 Ciaran McCreesh
00005  *
00006  * This file is part of the Paludis package manager. Paludis is free software;
00007  * you can redistribute it and/or modify it under the terms of the GNU General
00008  * Public License version 2, as published by the Free Software Foundation.
00009  *
00010  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013  * details.
00014  *
00015  * You should have received a copy of the GNU General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef PALUDIS_GUARD_PALUDIS_ENVIRONMENT_FACTORY_HH
00021 #define PALUDIS_GUARD_PALUDIS_ENVIRONMENT_FACTORY_HH 1
00022 
00023 #include <paludis/environment_factory-fwd.hh>
00024 #include <paludis/util/attributes.hh>
00025 #include <paludis/util/instantiation_policy.hh>
00026 #include <paludis/util/private_implementation_pattern.hh>
00027 #include <paludis/util/set-fwd.hh>
00028 #include <paludis/util/fs_entry-fwd.hh>
00029 #include <paludis/environment-fwd.hh>
00030 #include <tr1/memory>
00031 #include <tr1/functional>
00032 
00033 namespace paludis
00034 {
00035     class PALUDIS_VISIBLE FallBackToAnotherFormatError
00036     {
00037     };
00038 
00039     /**
00040      * Factory for Environment creation.
00041      *
00042      * \ingroup g_environment
00043      * \since 0.30
00044      */
00045     class PALUDIS_VISIBLE EnvironmentFactory :
00046         private PrivateImplementationPattern<EnvironmentFactory>,
00047         public InstantiationPolicy<EnvironmentFactory, instantiation_method::SingletonTag>
00048     {
00049         friend class InstantiationPolicy<EnvironmentFactory, instantiation_method::SingletonTag>;
00050 
00051         private:
00052             EnvironmentFactory();
00053             ~EnvironmentFactory();
00054 
00055             void _load_dir(const FSEntry &);
00056 
00057         public:
00058             typedef std::tr1::function<const std::tr1::shared_ptr<Environment>(const std::string &)> CreateFunction;
00059 
00060             /**
00061              * Create an Environment subclass from the specified spec.
00062              *
00063              * \param spec The environment spec, which is in the form
00064              *     env:suffix, where env is the string representing an
00065              *     Environment's kind (e.g. "paludis", "portage") and
00066              *     suffix is the information to pass to the constructing
00067              *     function (for paludis, a config suffix, and for portage,
00068              *     a location). If env is not specified, it defaults to
00069              *     trying paludis then portage. If suffix is not specified,
00070              *     it defaults to an empty string. If no colon is present,
00071              *     the supplied string is taken as env (this includes an
00072              *     empty string).
00073              */
00074             const std::tr1::shared_ptr<Environment> create(const std::string & spec) const
00075                 PALUDIS_ATTRIBUTE((warn_unused_result));
00076 
00077             /**
00078              * Add a repository format.
00079              *
00080              * \param formats must have at least one value, and no value may be
00081              * specified more than once across all invocations.
00082              *
00083              * \param create_function is used to implement EnvironmentFactory::create.
00084              */
00085             void add_environment_format(
00086                     const std::tr1::shared_ptr<const Set<std::string> > & formats,
00087                     const CreateFunction & create_function
00088                     );
00089     };
00090 
00091 #ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
00092     extern template class PrivateImplementationPattern<EnvironmentFactory>;
00093     extern template class InstantiationPolicy<EnvironmentFactory, instantiation_method::SingletonTag>;
00094 #endif
00095 }
00096 
00097 #endif

Generated on Mon Sep 21 10:36:08 2009 for paludis by  doxygen 1.5.4