repository_factory.hh

00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2008, 2009 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_REPOSITORY_FACTORY_HH
00021 #define PALUDIS_GUARD_PALUDIS_REPOSITORY_FACTORY_HH 1
00022 
00023 #include <paludis/repository_factory-fwd.hh>
00024 #include <paludis/util/attributes.hh>
00025 #include <paludis/util/private_implementation_pattern.hh>
00026 #include <paludis/util/instantiation_policy.hh>
00027 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00028 #include <paludis/util/fs_entry-fwd.hh>
00029 #include <paludis/environment-fwd.hh>
00030 #include <paludis/repository-fwd.hh>
00031 #include <paludis/name-fwd.hh>
00032 #include <tr1/functional>
00033 #include <tr1/memory>
00034 
00035 namespace paludis
00036 {
00037     class PALUDIS_VISIBLE RepositoryFactory :
00038         private PrivateImplementationPattern<RepositoryFactory>,
00039         public InstantiationPolicy<RepositoryFactory, instantiation_method::SingletonTag>
00040     {
00041         friend class InstantiationPolicy<RepositoryFactory, instantiation_method::SingletonTag>;
00042 
00043         private:
00044             RepositoryFactory();
00045             ~RepositoryFactory();
00046 
00047             void _load_dir(const FSEntry &);
00048 
00049         public:
00050             typedef std::tr1::function<std::string (const std::string &)> KeyFunction;
00051 
00052             typedef std::tr1::function<const std::tr1::shared_ptr<Repository>(
00053                     Environment * const,
00054                     const KeyFunction &
00055                     )> CreateFunction;
00056 
00057             typedef std::tr1::function<const std::tr1::shared_ptr<const RepositoryNameSet> (
00058                     const Environment * const,
00059                     const KeyFunction &
00060                     )> DependenciesFunction;
00061 
00062             typedef std::tr1::function<const RepositoryName (
00063                     const Environment * const,
00064                     const KeyFunction &
00065                     )> NameFunction;
00066 
00067             typedef std::tr1::function<int (
00068                     const Environment * const,
00069                     const KeyFunction &
00070                     )> ImportanceFunction;
00071 
00072             /**
00073              * Construct a given repository, or throw ConfigurationError.
00074              *
00075              * If the repository to be created has dependencies upon another
00076              * repository, that repository must have been created and added
00077              * to the environment's package database first.
00078              *
00079              * The returned repository is <em>not</em> added to the Environment's
00080              * package database.
00081              *
00082              * \param key_function should return the value for a given key. The
00083              * 'format' key must return a value (e.g. 'ebuild'), which is used
00084              * to select the return type. The 'repo_name' key's value should be
00085              * the file that best describes the location of the file containing
00086              * the repository config, if such a file exists. Other key names are
00087              * repository defined, but typically include things like 'location'
00088              * and 'sync'.
00089              */
00090             const std::tr1::shared_ptr<Repository> create(
00091                     Environment * const env,
00092                     const KeyFunction & key_function
00093                     ) const PALUDIS_ATTRIBUTE((warn_unused_result));
00094 
00095             /**
00096              * Find the name of the repository that would be constructed if the
00097              * supplied parameters were passed to RepositoryFactory::create.
00098              *
00099              * \see RepositoryFactory::create for parameter documentation.
00100              */
00101             const RepositoryName name(
00102                     const Environment * const env,
00103                     const KeyFunction & key_function
00104                     ) const PALUDIS_ATTRIBUTE((warn_unused_result));
00105 
00106             /**
00107              * Find the importance of the repository that would be constructed if the
00108              * supplied parameters were passed to RepositoryFactory::create.
00109              *
00110              * \see RepositoryFactory::create for parameter documentation.
00111              */
00112             int importance(
00113                     const Environment * const env,
00114                     const KeyFunction & key_function
00115                     ) const PALUDIS_ATTRIBUTE((warn_unused_result));
00116 
00117             /**
00118              * Fetch the names of any repositories depended upon by a particular
00119              * repository.
00120              *
00121              * \see RepositoryFactory::create for parameter documentation.
00122              */
00123             const std::tr1::shared_ptr<const RepositoryNameSet> dependencies(
00124                     const Environment * const env,
00125                     const KeyFunction & key_function
00126                     ) const PALUDIS_ATTRIBUTE((warn_unused_result));
00127 
00128             /**
00129              * Add a repository format.
00130              *
00131              * \param formats must have at least one value, and no value may be
00132              * specified more than once across all invocations.
00133              *
00134              * \param name_function is used to implement RepositoryFactory::name.
00135              *
00136              * \param importance_function is used to implement RepositoryFactory::importance.
00137              *
00138              * \param create_function is used to implement RepositoryFactory::create.
00139              *
00140              * \param dependencies_function is used to implement
00141              * RepositoryFactory::dependencies.
00142              */
00143             void add_repository_format(
00144                     const std::tr1::shared_ptr<const Set<std::string> > & formats,
00145                     const NameFunction & name_function,
00146                     const ImportanceFunction & importance_function,
00147                     const CreateFunction & create_function,
00148                     const DependenciesFunction & dependencies_function
00149                     );
00150 
00151             struct ConstIteratorTag;
00152             typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
00153             ConstIterator begin_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
00154             ConstIterator end_keys() const PALUDIS_ATTRIBUTE((warn_unused_result));
00155     };
00156 
00157 #ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
00158     extern template class PrivateImplementationPattern<RepositoryFactory>;
00159     extern template class InstantiationPolicy<RepositoryFactory, instantiation_method::SingletonTag>;
00160 #endif
00161 }
00162 
00163 #endif

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