Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / Repository.h
index 6ffedcf..6ed1725 100644 (file)
 #define ZYPP_SAT_REPOSITORY_H
 
 #include <iosfwd>
-#include "zypp/base/SafeBool.h"
 #include "zypp/Pathname.h"
 #include "zypp/sat/detail/PoolMember.h"
+#include "zypp/sat/LookupAttr.h"     // LookupAttrTools.h included at EOF
 #include "zypp/sat/Solvable.h"
-#include "zypp/sat/SolvAttr.h"
 #include "zypp/RepoInfo.h"
 #include "zypp/Date.h"
+#include "zypp/CpeId.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
-    namespace sat
-    {
-      template<class _ResultT, class _AttrT>
-      class ArrayAttr;
-    }
-
     namespace detail
     {
       struct ByRepository;
@@ -41,16 +35,17 @@ namespace zypp
     // CLASS NAME : Repository
     //
     /** */
-    class Repository : protected sat::detail::PoolMember,
-                       private base::SafeBool<Repository>
+    class Repository : protected sat::detail::PoolMember
     {
     public:
         typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
         typedef sat::detail::size_type size_type;
         typedef sat::detail::RepoIdType IdType;
-        typedef sat::ArrayAttr<std::string,std::string> UpdateKeys;
+
         typedef sat::ArrayAttr<std::string,std::string> Keywords;
-        typedef sat::ArrayAttr<std::string,std::string> Products;
+
+       typedef std::string ContentRevision;
+       typedef std::string ContentIdentifier;
 
     public:
         /** Default ctor creates \ref noRepository.*/
@@ -65,10 +60,10 @@ namespace zypp
         /** Represents no \ref Repository. */
         static const Repository noRepository;
 
-#ifndef SWIG // Swig treats it as syntax error
         /** Evaluate \ref Repository in a boolean context (\c != \c noRepository). */
-        using base::SafeBool<Repository>::operator bool_type;
-#endif
+        explicit operator bool() const
+        { return get() != nullptr; }
+
         /** Reserved system repository alias \c @System. */
         static const std::string & systemRepoAlias();
 
@@ -77,16 +72,48 @@ namespace zypp
 
     public:
          /**
-          * Short unique, convenience string to refer to a repo.
+          * Short unique string to identify a repo.
           * ie: openSUSE-10.3
           *
           * If you are looking for a label to display
-          * see \ref info() which provides \ref RepoInfo::name()
+          * see \ref name().
           * ie: "openSUSE 10.3 Main repository"
           *
           */
         std::string alias() const;
 
+        /** Label to display for this repo. */
+        std::string name() const;
+
+       /** Alias or name, according to \ref ZConfig::repoLabelIsAlias */
+       std::string label() const;
+
+       /** User string: \ref label (alias or name) */
+       std::string asUserString() const
+       { return label(); }
+
+    public:
+       /** Timestamp or arbitrary user supplied string.
+        * \c /repomd/revision/text() in \c repomd.xml.
+        */
+       ContentRevision contentRevision() const;
+
+       /** Unique string identifying a repositories content.
+        * \c /repomd/tags/repo/text() in \c repomd.xml.
+        * \code
+        * <repomd ....>
+        *  <tags>
+        *   <repo>obsrepository://build.suse.de/SUSE:Factory:Head:Internal/standard</repo>
+        * \endcode
+        * Semantically the value is just a plain string, even
+        * if OBS often uses the location of the project as
+        * unique identifyer.
+        */
+       ContentIdentifier contentIdentifier() const;
+
+       /** Whether \a id_r matches this repos content identifier. */
+       bool hasContentIdentifier( const ContentIdentifier & id_r ) const;
+
         /**
          * Timestamp when this repository was generated
          *
@@ -103,7 +130,7 @@ namespace zypp
          * specify when it was generated.
          *
          */
-        zypp::Date generatedTimestamp() const;
+        Date generatedTimestamp() const;
 
         /**
          * Suggested expiration timestamp.
@@ -121,36 +148,41 @@ namespace zypp
          * an expiration date.
          *
          */
-        zypp::Date suggestedExpirationTimestamp() const;
+        Date suggestedExpirationTimestamp() const;
 
         /**
          * repository keywords (tags)
          */
         Keywords keywords() const;
 
+       /** Whether \a val_r is present in keywords. */
+       bool hasKeyword( const std::string & val_r ) const;
+
         /**
          * The suggested expiration date of this repository
          * already passed
          *
+         * rpm-md repositories can provide this tag using the
+         * expire extension tag:
+         * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
          */
         bool maybeOutdated() const;
 
-        /**
-         * if the repository claims to update something then
-         * it is an update repository
-         *
-         * This is implemented by looking at an "update" keyword
-         * on the repository tags
+        /** Hint whether the Repo may provide updates for a product.
+        *
+         * Either the repository claims to update a product via a repository updates
+         * tag in it's metadata or a known product lists the repositories ContentIdentifier
+        * as required update repo.
          */
         bool isUpdateRepo() const;
 
-        /**
-         * wether the repository claims to update something \ref prod
-         * with key \ref cpename
-         *
-         * See http://cpe.mitre.org/ for more information on CPE
-         */
-        bool providesUpdatesFor( const std::string &cpename ) const;
+        /** Hint whether the Repo may provide updates for a product identified by it's \ref CpeId
+        *
+         * Either the repository claims to update a product via a repository updates
+         * tag in it's metadata or a known product lists the repositories ContentIdentifier
+        * as required update repo.
+        */
+        bool providesUpdatesFor( const CpeId & cpeid_r ) const;
 
         /** Whether \ref Repository contains solvables. */
         bool solvablesEmpty() const;
@@ -165,13 +197,15 @@ namespace zypp
         SolvableIterator solvablesEnd() const;
 
     public:
-#if 0
-      /** Query class for Repository */
+
+      /** Query class for Repository related products */
       class ProductInfoIterator;
 
       /**
        * Get an iterator to the beginning of the repository
        * compatible distros.
+       * \note This is only a hint. There is no guarantee that
+       * the repository is built for that product.
        * \see Repository::ProductInfoIterator
        */
       ProductInfoIterator compatibleWithProductBegin() const;
@@ -184,19 +218,22 @@ namespace zypp
       ProductInfoIterator compatibleWithProductEnd() const;
 
       /**
-       * Get an iterator to the beginning of the repository
-       * compatible distros.
+       * Get an iterator to the beginning of distos the repository
+       * provides upadates for.
+       * \note This is only a hint within the repositories metadata.
+       * The same realation might be expressed by a product listing
+       * this repositories ContentIdentifier as required update repo.
        * \see Repository::ProductInfoIterator
        */
       ProductInfoIterator updatesProductBegin() const;
 
       /**
-       * Get an iterator to the end of the repository
-       * compatible distros.
+       * Get an iterator to the end of distos the repository
+       * provides upadates for.
        * \see Repository::ProductInfoIterator
        */
       ProductInfoIterator updatesProductEnd() const;
-#endif
+
     public:
         /** Return any associated \ref RepoInfo. */
         RepoInfo info() const;
@@ -257,11 +294,18 @@ namespace zypp
         ::_Repo * get() const;
         /** Expert backdoor. */
         IdType id() const { return _id; }
-    private:
-#ifndef SWIG // Swig treats it as syntax error
-        friend base::SafeBool<Repository>::operator bool_type() const;
-#endif
-        bool boolTest() const { return get(); }
+        /** libsolv internal priorities.
+         * Unlike the \ref RepoInfo priority which tries to be YUM conform
+         * (H[1-99]L), this one is the solvers internal priority representation.
+         * It is type \c int and as one might expect it, the higher the value
+         * the higher the priority. Subpriority is currently used to express
+         * media preferences (\see \ref MediaPriority).
+         */
+        //@{
+        int satInternalPriority() const;
+        int satInternalSubPriority() const;
+        //@}
+
     private:
         IdType _id;
     };
@@ -270,6 +314,9 @@ namespace zypp
     /** \relates Repository Stream output */
     std::ostream & operator<<( std::ostream & str, const Repository & obj );
 
+    /** \relates Repository XML output */
+    std::ostream & dumpAsXmlOn( std::ostream & str, const Repository & obj );
+
     /** \relates Repository */
     inline bool operator==( const Repository & lhs, const Repository & rhs )
     { return lhs.get() == rhs.get(); }
@@ -283,6 +330,55 @@ namespace zypp
     { return lhs.get() < rhs.get(); }
 
     ///////////////////////////////////////////////////////////////////
+    /**
+     * Query class for Repository related products
+     *
+     * Products are identified by CpeIds within the repositories metadata.
+     * \see http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29.2C_extensions_to_repomd.xml
+     *
+     * The iterator does not provide a dereference
+     * operator so you can do * on it, but you can
+     * access the attributes of each related product
+     * directly from the iterator.
+     *
+     * \code
+     * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
+     * {
+     *   cout << it.label() << ": " << it.cpeid() << endl;
+     * }
+     * \endcode
+     *
+     */
+    class Repository::ProductInfoIterator : public boost::iterator_adaptor<
+        Repository::ProductInfoIterator    // Derived
+        , sat::LookupAttr::iterator        // Base
+        , int                              // Value
+        , boost::forward_traversal_tag     // CategoryOrTraversal
+        , int                              // Reference
+    >
+    {
+      public:
+        ProductInfoIterator()
+        {}
+
+        /** Product label */
+        std::string label() const;
+
+        /** The Common Platform Enumeration name for this product. */
+        CpeId cpeId() const;
+
+      private:
+        friend class Repository;
+        /** Hide ctor as just a limited set of attributes is valid. */
+        explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
+
+      private:
+        friend class boost::iterator_core_access;
+        int dereference() const { return 0; }
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : Repository::EraseFromPool
     //
@@ -318,6 +414,7 @@ namespace zypp
            { repository_r.eraseFromPool(); }
     };
     ///////////////////////////////////////////////////////////////////
+
     ///////////////////////////////////////////////////////////////////
     namespace detail
     { /////////////////////////////////////////////////////////////////
@@ -326,128 +423,59 @@ namespace zypp
       //       CLASS NAME : RepositoryIterator
       //
       /** */
-       class RepositoryIterator : public boost::iterator_adaptor<
+      class RepositoryIterator : public boost::iterator_adaptor<
            RepositoryIterator                            // Derived
                           , ::_Repo **                   // Base
-                          , Repository                   // Value
+                           , Repository                   // Value
                           , boost::forward_traversal_tag // CategoryOrTraversal
                           , Repository                   // Reference
                             >
-       {
+      {
         public:
-           RepositoryIterator()
-               : RepositoryIterator::iterator_adaptor_( 0 )
-               {}
+          RepositoryIterator()
+          : RepositoryIterator::iterator_adaptor_( 0 )
+          {}
 
-           explicit RepositoryIterator( ::_Repo ** p )
-               : RepositoryIterator::iterator_adaptor_( p )
-               {}
+          explicit RepositoryIterator( ::_Repo ** p )
+          : RepositoryIterator::iterator_adaptor_( p )
+          {}
 
         private:
-           friend class boost::iterator_core_access;
-
-           Repository dereference() const
-               { return Repository( *base() ); }
-       };
-       ///////////////////////////////////////////////////////////////////
-       ///////////////////////////////////////////////////////////////////
-       //
-       //      CLASS NAME : ByRepository
-       //
-       /** Functor filtering \ref Solvable by \ref Repository.*/
-       struct ByRepository
-       {
+          friend class boost::iterator_core_access;
+
+          Repository dereference() const
+          { return Repository( *base() ); }
+
+          void increment();
+      };
+      ///////////////////////////////////////////////////////////////////
+      ///////////////////////////////////////////////////////////////////
+      //
+      //       CLASS NAME : ByRepository
+      //
+      /** Functor filtering \ref Solvable by \ref Repository.*/
+      struct ByRepository
+      {
         public:
-           ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
-           ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
-           ByRepository() {}
+          ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
+          ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
+          ByRepository() {}
 
-           bool operator()( const sat::Solvable & slv_r ) const
-               { return slv_r.repository() == _repository; }
+          bool operator()( const sat::Solvable & slv_r ) const
+          { return slv_r.repository() == _repository; }
 
         private:
-           Repository _repository;
-       };
-       ///////////////////////////////////////////////////////////////////
-       /////////////////////////////////////////////////////////////////
+          Repository _repository;
+      };
+      ///////////////////////////////////////////////////////////////////
+      /////////////////////////////////////////////////////////////////
     } // namespace detail
     ///////////////////////////////////////////////////////////////////
-
-    /////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
 
-#include "zypp/sat/LookupAttr.h"
-
-#if 0
-
-namespace zypp
-{
-  /**
-   * Query class for Repository related products
-   *
-   * The iterator does not provide a dereference
-   * operator so you can do * on it, but you can
-   * access the attributes of each related product
-   * directly from the iterator.
-   *
-   * \code
-   * for ( Repository::ProductInfoIterator it = repo->compatibleWithProductBegin();
-   *       it != repo->compatibleWithProductEnd();
-   *       ++it )
-   * {
-   *   cout << it.cpeid() << endl;
-   * }
-   * \endcode
-   *
-   */
-  class Repository::ProductInfoIterator : public boost::iterator_adaptor<
-      Repository::ProductInfoIterator    // Derived
-      , sat::LookupAttr::iterator        // Base
-      , int                              // Value
-      , boost::forward_traversal_tag     // CategoryOrTraversal
-      , int
-  >
-  {
-    public:
-      ProductInfoIterator() {}
-      explicit ProductInfoIterator( const sat::Solvable & val_r,
-                                    const sat::SolvAttr & arrayid );
-
-      /**
-       * Product label
-       */
-      std::string label() const;
-
-      /**
-       * The Common Platform Enumeration name
-       * for this product.
-       *
-       * See http://cpe.mitre.org
-       */
-      std::string cpeid() const;
-
-    private:
-      friend class boost::iterator_core_access;
-      int dereference() const { return 0; }
-  };
-
-  inline Repository::ProductInfoIterator Repository::compatibleWithProductBegin() const
-  { return ProductInfoIterator(satSolvable(), sat::SolvAttr::repositoryDistros); }
-
-  inline Repository::ProductInfoIterator Repository::compatibleWithProductEnd() const
-  { return ProductInfoIterator(); }
-
-  inline Repository::ProductInfoIterator Repository::updatesProductBegin() const
-  { return ProductInfoIterator(satSolvable(), , sat::SolvAttr::repositoryUpdates); }
-
-  inline Repository::ProductInfoIterator Repository::updatesProductEnd() const
-  { return ProductInfoIterator(); }
-
-
-}
-#endif
+// Late include as sat::ArrayAttr requires Repository.h
+#include "zypp/sat/LookupAttrTools.h"
 
 #endif // ZYPP_SAT_REPOSITORY_H
-
-