package_id.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2007, 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_PACKAGE_ID_HH
00021 #define PALUDIS_GUARD_PALUDIS_PACKAGE_ID_HH 1
00022 
00023 #include <paludis/package_id-fwd.hh>
00024 
00025 #include <paludis/util/attributes.hh>
00026 #include <paludis/util/operators.hh>
00027 #include <paludis/util/private_implementation_pattern.hh>
00028 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00029 #include <paludis/util/fs_entry-fwd.hh>
00030 
00031 #include <paludis/action-fwd.hh>
00032 #include <paludis/dep_spec-fwd.hh>
00033 #include <paludis/dep_tree-fwd.hh>
00034 #include <paludis/mask-fwd.hh>
00035 #include <paludis/metadata_key-fwd.hh>
00036 #include <paludis/metadata_key_holder.hh>
00037 #include <paludis/name-fwd.hh>
00038 #include <paludis/repository-fwd.hh>
00039 #include <paludis/contents-fwd.hh>
00040 #include <paludis/version_spec-fwd.hh>
00041 #include <paludis/choice-fwd.hh>
00042 
00043 #include <tr1/memory>
00044 
00045 /** \file
00046  * Declarations for PackageID classes.
00047  *
00048  * \ingroup g_package_id
00049  *
00050  * \section Examples
00051  *
00052  * - \ref example_package_id.cc "example_package_id.cc" (for package IDs)
00053  * - \ref example_action.cc "example_action.cc" (for actions)
00054  * - \ref example_metadata_key.cc "example_metadata_key.cc" (for metadata keys)
00055  * - \ref example_mask.cc "example_mask.cc" (for masks)
00056  */
00057 
00058 namespace paludis
00059 {
00060     class PackageDatabase;
00061 
00062     /**
00063      * A PackageID represents a unique package version in a particular
00064      * Repository.
00065      *
00066      * All PackageID instances have some basic identification data:
00067      *
00068      * - A name
00069      * - A version
00070      * - A slot (which will be '0' if slots aren't used)
00071      * - An owning repository
00072      *
00073      * It should be noted that the above together are not sufficient to uniquely
00074      * identify a package. Some repositories support multiple slots per version
00075      * of a package, and some repositories support additional affixes that
00076      * prevent a package from being uniquely identifiable merely by the above.
00077      *
00078      * PackageID instances also have:
00079      *
00080      * - A collection of metadata keys. Some of these keys have a particular
00081      *   specific role in certain places. These can be fetched via blah_key()
00082      *   methods, all of which may return an empty pointer. Other keys have no
00083      *   meaningful global role, and can only be fetched using the iteration
00084      *   methods.
00085      *
00086      * - A collection (often empty) of masks. A masked package cannot be
00087      *   installed.
00088      *
00089      * A PackageID instance may support certain actions, which are represented
00090      * via an Action subclass instance.
00091      */
00092     class PALUDIS_VISIBLE PackageID :
00093         private PrivateImplementationPattern<PackageID>,
00094         public equality_operators::HasEqualityOperators,
00095         public MetadataKeyHolder
00096     {
00097         private:
00098             PrivateImplementationPattern<PackageID>::ImpPtr & _imp;
00099 
00100         protected:
00101             /**
00102              * Add a new Mask.
00103              */
00104             virtual void add_mask(const std::tr1::shared_ptr<const Mask> &) const;
00105 
00106             /**
00107              * This method will be called before any of the mask iteration
00108              * methods does its work. It can be used by subclasses to implement
00109              * as-needed loading of masks.
00110              */
00111             virtual void need_masks_added() const = 0;
00112 
00113         public:
00114             ///\name Basic operations
00115             ///\{
00116 
00117             PackageID();
00118             virtual ~PackageID() = 0;
00119 
00120             std::size_t hash() const PALUDIS_ATTRIBUTE((warn_unused_result));
00121 
00122             ///\}
00123 
00124             /**
00125              * Return our canonical string representation.
00126              *
00127              * This method (which is called by paludis::stringify()) should be
00128              * used when outputting a PackageID or a PackageID's version. Some
00129              * repositories need to display additional information to identify a
00130              * package, so outputting merely the name and / or version may be
00131              * insufficient.
00132              */
00133             virtual const std::string canonical_form(const PackageIDCanonicalForm) const = 0;
00134 
00135             /**
00136              * What is our package name?
00137              *
00138              * Use canonical_form instead for outputtting.
00139              */
00140             virtual const QualifiedPackageName name() const = 0;
00141 
00142             /**
00143              * What is our package version?
00144              *
00145              * Use canonical_form instead for outputtting.
00146              */
00147             virtual const VersionSpec version() const = 0;
00148 
00149             /**
00150              * What is our package's slot?
00151              */
00152             virtual const SlotName slot() const = 0;
00153 
00154             /**
00155              * What is our owning repository?
00156              */
00157             virtual const std::tr1::shared_ptr<const Repository> repository() const = 0;
00158 
00159             ///\name Specific metadata keys
00160             ///\{
00161 
00162             /**
00163              * The virtual_for_key, if non-zero, indicates that we are an
00164              * (old-style) virtual for another package. This affects dependency
00165              * resolution.
00166              */
00167             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::tr1::shared_ptr<const PackageID> > > virtual_for_key() const = 0;
00168 
00169             /**
00170              * The keywords_key, if non-zero, is used by FindUnusedPackagesTask
00171              * to determine whether a package is unused.
00172              */
00173             virtual const std::tr1::shared_ptr<const MetadataCollectionKey<KeywordNameSet> > keywords_key() const = 0;
00174 
00175             /**
00176              * The provide_key, if non-zero, indicates that a package provides
00177              * certain old-style virtuals. This affects dependency resolution.
00178              */
00179             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<ProvideSpecTree> > provide_key() const = 0;
00180 
00181             /**
00182              * The contains_key, if non-zero, indicates that a package contains
00183              * other packages. This affects dependency resolution. */
00184             virtual const std::tr1::shared_ptr<const MetadataCollectionKey<PackageIDSequence> > contains_key() const = 0;
00185 
00186             /**
00187              * The contained_in_key, if non-zero, indicates that a package is
00188              * contained in another package. This affects dependency resolution.
00189              */
00190             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::tr1::shared_ptr<const PackageID> > > contained_in_key() const = 0;
00191 
00192             /**
00193              * The build_dependencies_key, if non-zero, indicates a package's
00194              * build-time dependencies.
00195              */
00196             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > build_dependencies_key() const = 0;
00197 
00198             /**
00199              * The run_dependencies_key, if non-zero, indicates a package's
00200              * run-time dependencies.
00201              */
00202             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > run_dependencies_key() const = 0;
00203 
00204             /**
00205              * The post_dependencies_key, if non-zero, indicates a package's
00206              * post-merge dependencies.
00207              */
00208             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > post_dependencies_key() const = 0;
00209 
00210             /**
00211              * The suggested_dependencies_key, if non-zero, indicates a package's
00212              * suggested post-merge dependencies.
00213              */
00214             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<DependencySpecTree> > suggested_dependencies_key() const = 0;
00215 
00216             /**
00217              * The fetches_key, if non-zero, indicates files that have to be fetched
00218              * in order to install a package.
00219              */
00220             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<FetchableURISpecTree> > fetches_key() const = 0;
00221 
00222             /**
00223              * The homepage_key, if non-zero, describes a package's homepages.
00224              */
00225             virtual const std::tr1::shared_ptr<const MetadataSpecTreeKey<SimpleURISpecTree> > homepage_key() const = 0;
00226 
00227             /**
00228              * The short_description_key, if non-zero, provides a short (no more
00229              * than a few hundred characters) description of a package.
00230              */
00231             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::string> > short_description_key() const = 0;
00232 
00233             /**
00234              * The long_description_key, if non-zero, provides a long
00235              * description of a package.
00236              */
00237             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::string> > long_description_key() const = 0;
00238 
00239             /**
00240              * The contents_key, if non-zero, contains the contents of a
00241              * package. For installed packages, this means the files installed;
00242              * for installable packages, this means the files that will be
00243              * installed (if known, which it may be for some binary packages).
00244              */
00245             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::tr1::shared_ptr<const Contents> > > contents_key() const = 0;
00246 
00247             /**
00248              * The installed_time_key, if non-zero, contains the time a package
00249              * was installed. It affects dependency resolution if DepList is
00250              * using dl_reinstall_scm_daily or dl_reinstall_scm_weekly.
00251              */
00252             virtual const std::tr1::shared_ptr<const MetadataTimeKey> installed_time_key() const = 0;
00253 
00254             /**
00255              * The from_repositories key, if non-zero, contains the set of repositories
00256              * that the ID is 'from'. An ID can be 'from' multiple repositories if, for
00257              * example, it was built via a binary package.
00258              */
00259             virtual const std::tr1::shared_ptr<const MetadataCollectionKey<Set<std::string> > > from_repositories_key() const = 0;
00260 
00261             /**
00262              * The fs_location_key, if non-zero, indicates the filesystem
00263              * location (for example, the ebuild file or VDB directory) that
00264              * best describes the location of a PackageID.
00265              */
00266             virtual const std::tr1::shared_ptr<const MetadataValueKey<FSEntry> > fs_location_key() const = 0;
00267 
00268             /**
00269              * The transient_key, if non-zero, indicates whether this
00270              * PackageID's originating repository is volatile.
00271              */
00272             virtual const std::tr1::shared_ptr<const MetadataValueKey<bool> > transient_key() const = 0;
00273 
00274             /**
00275              * The choices_key, if non-zero, contains zero or more
00276              * MetadataValueKey<std::tr1::shared_ptr<const Choice> > child
00277              * keys holding choice information for this ID.
00278              */
00279             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::tr1::shared_ptr<const Choices> > > choices_key() const = 0;
00280 
00281             ///\}
00282 
00283             ///\name Actions
00284             ///\{
00285 
00286             /**
00287              * Do we support a particular action?
00288              *
00289              * Attempting to call perform_action with an unsupported action type
00290              * will lead to an UnsupportedActionError. However, in performance
00291              * critical code and in situations where creating a full Action
00292              * subclass instance is non-trivial, supports_action is much
00293              * simpler.
00294              */
00295             virtual bool supports_action(const SupportsActionTestBase &) const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00296 
00297             /**
00298              * Perform the specified action.
00299              */
00300             virtual void perform_action(Action &) const = 0;
00301 
00302             ///\}
00303 
00304             ///\name Masks
00305             ///\{
00306 
00307             struct MasksConstIteratorTag;
00308             typedef WrappedForwardIterator<MasksConstIteratorTag, std::tr1::shared_ptr<const Mask> > MasksConstIterator;
00309 
00310             MasksConstIterator begin_masks() const PALUDIS_ATTRIBUTE((warn_unused_result));
00311             MasksConstIterator end_masks() const PALUDIS_ATTRIBUTE((warn_unused_result));
00312 
00313             /**
00314              * Do we have any masks? Equivalent to begin_masks() != end_masks().
00315              */
00316             bool masked() const PALUDIS_ATTRIBUTE((warn_unused_result));
00317 
00318             /**
00319              * Invalidate any masks.
00320              *
00321              * PackageID implementations may cache masks. This can cause
00322              * problems if the operating environment changes. Calling this
00323              * method will clear any masks held by the PackageID.
00324              */
00325             virtual void invalidate_masks() const;
00326 
00327             /**
00328              * Do we break Portage, and if so, why?
00329              *
00330              * This method may be used by Environment implementations to apply a "we don't
00331              * want packages that break Portage" mask.
00332              */
00333             virtual std::tr1::shared_ptr<const Set<std::string> > breaks_portage() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00334 
00335             ///\}
00336 
00337             ///\name Extra comparisons
00338             ///\{
00339 
00340             /**
00341              * Perform an arbitrary less than comparison on another PackageID.
00342              *
00343              * Used by PackageIDSetComparator and operator==. This function
00344              * should not be used by anything else.
00345              *
00346              * This function will only be called if the other PackageID has the
00347              * same name, version and repository as this. If this is not enough
00348              * to uniquely identify an ID (e.g. if there is an affix, or if multiple
00349              * slots per version are allowed), then this function's
00350              * implementation must differentiate appropriately.
00351              */
00352             virtual bool arbitrary_less_than_comparison(const PackageID &) const
00353                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00354 
00355             /**
00356              * Provide any additional hash information for a PackageID.
00357              *
00358              * The standard PackageID hash incorporates the repository name, the
00359              * package name and the version of the package. If this function is
00360              * defined, its value is also used when determining a hash. This can
00361              * provide increased performance if a repository uses affixes or
00362              * multiple slots per version.
00363              */
00364             virtual std::size_t extra_hash_value() const
00365                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00366 
00367             ///\}
00368     };
00369 
00370     /**
00371      * PackageID instances are equality-comparable.
00372      *
00373      * \ingroup g_package_id
00374      * \since 0.26
00375      */
00376     bool operator== (const PackageID &, const PackageID &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
00377 
00378     /**
00379      * A comparison functor that uses PackageID::arbitrary_less_than_comparison
00380      * to provide a meaningless but stable ordering for PackageIDSet.
00381      *
00382      * \ingroup g_package_id
00383      * \since 0.26
00384      * \nosubgrouping
00385      */
00386     class PALUDIS_VISIBLE PackageIDSetComparator
00387     {
00388         public:
00389             /**
00390              * Perform an arbitrary less-than comparison.
00391              */
00392             bool operator() (const std::tr1::shared_ptr<const PackageID> &,
00393                     const std::tr1::shared_ptr<const PackageID> &) const;
00394     };
00395 
00396     /**
00397      * A comparison functor that provides a less-than comparison on PackageID
00398      * instances according to, in order, their name, their version, their
00399      * repository's importance according to the supplied PackageDatabase,
00400      * and PackageID::arbitrary_less_than_comparison.
00401      *
00402      * \ingroup g_package_id
00403      * \since 0.26
00404      * \nosubgrouping
00405      */
00406     class PALUDIS_VISIBLE PackageIDComparator :
00407         private PrivateImplementationPattern<PackageIDComparator>
00408     {
00409         public:
00410             ///\name Standard library typedefs
00411             ///\{
00412 
00413             typedef bool result_type;
00414 
00415             ///\}
00416 
00417             ///\name Basic operations
00418             ///\{
00419 
00420             PackageIDComparator(const PackageDatabase * const);
00421             PackageIDComparator(const PackageIDComparator &);
00422             ~PackageIDComparator();
00423 
00424             ///\}
00425 
00426             /**
00427              * Perform the less-than comparison.
00428              */
00429             bool operator() (const std::tr1::shared_ptr<const PackageID> &,
00430                     const std::tr1::shared_ptr<const PackageID> &) const;
00431     };
00432 }
00433 
00434 #endif

Generated on Sun Nov 30 23:01:32 2008 for paludis by  doxygen 1.5.5