Imported Upstream version 16.0.3
[platform/upstream/libzypp.git] / zypp / ResPool.h
index 2657598..b64b7ad 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <iosfwd>
 
-#include "zypp/base/Deprecated.h"
+#include "zypp/APIConfig.h"
 #include "zypp/base/Iterator.h"
 
 #include "zypp/pool/PoolTraits.h"
@@ -27,6 +27,7 @@ namespace zypp
 
   class SerialNumber;
   class ResPoolProxy;
+  class Resolver;
 
   ///////////////////////////////////////////////////////////////////
   //
@@ -42,6 +43,18 @@ namespace zypp
    * an ordinary filter iterator. Do not provide filter iterators
    * here, if there is no index table for it.
    *
+   * For most (*Begin,*End) iterator-pairs there's also an \ref Iterable
+   * provided, so you can use then in range-based for loops:
+   * \code
+   *   // classic:
+   *   for_( it, pool.filterBegin(myfilter), pool.filterEnd(myfilter) )
+   *   { ... }
+   *
+   *   // range based:
+   *   for ( const PoolItem & pi : pool.filter(myfilter) )
+   *   { ... }
+   * \endcode
+   *
    * \include n_ResPool_nomorenameiter
   */
   class ResPool
@@ -62,6 +75,9 @@ namespace zypp
       /** preliminary */
       ResPoolProxy proxy() const;
 
+      /** The Resolver */
+      Resolver & resolver() const;
+
     public:
       /** The pools serial number. Changing whenever the
        * whenever the content changes. (Resolvables or
@@ -97,15 +113,19 @@ namespace zypp
       { return( resolvable_r ? find( resolvable_r->satSolvable() ) : PoolItem() ); }
 
     public:
-      /** \name Iterate over all PoolItems matching a \c _Filter. */
+      /** \name Iterate over all PoolItems matching a \c TFilter. */
       //@{
-      template<class _Filter>
-      filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
+      template<class TFilter>
+      filter_iterator<TFilter,const_iterator> filterBegin( const TFilter & filter_r ) const
       { return make_filter_begin( filter_r, *this ); }
 
-      template<class _Filter>
-      filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
+      template<class TFilter>
+      filter_iterator<TFilter,const_iterator> filterEnd( const TFilter & filter_r ) const
       { return make_filter_end( filter_r, *this ); }
+
+      template<class TFilter>
+      Iterable<filter_iterator<TFilter,const_iterator> > filter( const TFilter & filter_r ) const
+      { return makeIterable( filterBegin( filter_r ), filterEnd( filter_r ) ); }
       //@}
 
       /** \name Iterate over all PoolItems by status.
@@ -132,6 +152,9 @@ namespace zypp
 
       filter_iterator<filter::ByStatus,const_iterator> byStatusEnd( const filter::ByStatus & filter_r ) const
       { return make_filter_end( filter_r, *this ); }
+
+      Iterable<filter_iterator<filter::ByStatus,const_iterator> > byStatus( const filter::ByStatus & filter_r ) const
+      { return makeIterable( byStatusBegin( filter_r ), byStatusEnd( filter_r ) ); }
       //@}
 
     public:
@@ -152,13 +175,13 @@ namespace zypp
       byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
       { return byIdentBegin( ByIdent(kind_r,name_r) ); }
 
-      template<class _Res>
+      template<class TRes>
       byIdent_iterator byIdentBegin( IdString name_r ) const
-      { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
+      { return byIdentBegin( ByIdent(ResTraits<TRes>::kind,name_r) ); }
 
-      template<class _Res>
+      template<class TRes>
       byIdent_iterator byIdentBegin( const C_Str & name_r ) const
-      { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
+      { return byIdentBegin( ByIdent(ResTraits<TRes>::kind,name_r) ); }
 
       /** Derive name and kind from \ref PoolItem. */
       byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
@@ -183,13 +206,13 @@ namespace zypp
       byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
       { return byIdentEnd( ByIdent(kind_r,name_r) ); }
 
-      template<class _Res>
+      template<class TRes>
       byIdent_iterator byIdentEnd( IdString name_r ) const
-      { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
+      { return byIdentEnd( ByIdent(ResTraits<TRes>::kind,name_r) ); }
 
-      template<class _Res>
+      template<class TRes>
       byIdent_iterator byIdentEnd( const C_Str & name_r ) const
-      { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
+      { return byIdentEnd( ByIdent(ResTraits<TRes>::kind,name_r) ); }
 
       /** Derive name and kind from \ref PoolItem. */
       byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
@@ -200,6 +223,33 @@ namespace zypp
       /** Takes a \ref sat::Solvable::ident string. */
       byIdent_iterator byIdentEnd( IdString ident_r ) const
       { return byIdentEnd( ByIdent(ident_r) ); }
+
+
+      Iterable<byIdent_iterator> byIdent( const ByIdent & ident_r ) const
+      { return makeIterable( byIdentBegin( ident_r ), byIdentEnd( ident_r ) ); }
+
+      Iterable<byIdent_iterator> byIdent( ResKind kind_r, IdString name_r ) const
+      { return makeIterable( byIdentBegin( kind_r, name_r ), byIdentEnd(  kind_r, name_r ) ); }
+
+      Iterable<byIdent_iterator> byIdent( ResKind kind_r, const C_Str & name_r ) const
+      { return makeIterable( byIdentBegin(  kind_r, name_r ), byIdentEnd(  kind_r, name_r ) ); }
+
+      template<class TRes>
+      Iterable<byIdent_iterator> byIdent( IdString name_r ) const
+      { return makeIterable( byIdentBegin<TRes>( name_r ), byIdentEnd<TRes>( name_r ) ); }
+
+      template<class TRes>
+      Iterable<byIdent_iterator> byIdent( const C_Str & name_r ) const
+      { return makeIterable( byIdentBegin<TRes>( name_r ), byIdentEnd<TRes>( name_r ) ); }
+
+      Iterable<byIdent_iterator> byIdent( const PoolItem & pi_r ) const
+      { return makeIterable( byIdentBegin( pi_r ), byIdentEnd( pi_r ) ); }
+
+      Iterable<byIdent_iterator> byIdent(sat::Solvable slv_r ) const
+      { return makeIterable( byIdentBegin( slv_r ), byIdentEnd( slv_r ) ); }
+
+      Iterable<byIdent_iterator> byIdent( IdString ident_r ) const
+      { return makeIterable( byIdentBegin( ident_r ), byIdentEnd( ident_r ) ); }
      //@}
 
     public:
@@ -211,16 +261,23 @@ namespace zypp
       byKind_iterator byKindBegin( const ResKind & kind_r ) const
       { return make_filter_begin( ByKind(kind_r), *this ); }
 
-      template<class _Res>
+      template<class TRes>
           byKind_iterator byKindBegin() const
-      { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
+      { return make_filter_begin( resfilter::byKind<TRes>(), *this ); }
 
       byKind_iterator byKindEnd( const ResKind & kind_r ) const
       { return make_filter_end( ByKind(kind_r), *this ); }
 
-      template<class _Res>
+      template<class TRes>
           byKind_iterator byKindEnd() const
-      { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
+      { return make_filter_end( resfilter::byKind<TRes>(), *this ); }
+
+      Iterable<byKind_iterator> byKind( const ResKind & kind_r ) const
+      { return makeIterable( byKindBegin( kind_r ), byKindEnd( kind_r ) ); }
+
+      template<class TRes>
+      Iterable<byKind_iterator> byKind() const
+      { return makeIterable( byKindBegin<TRes>(), byKindEnd<TRes>() ); }
       //@}
 
     public:
@@ -234,6 +291,9 @@ namespace zypp
 
       byName_iterator byNameEnd( const std::string & name_r ) const
       { return make_filter_end( ByName(name_r), *this ); }
+
+      Iterable<byName_iterator> byName( const std::string & name_r ) const
+      { return makeIterable( byNameBegin( name_r ), byNameEnd( name_r ) ); }
       //@}
 
     public:
@@ -252,9 +312,12 @@ namespace zypp
       repository_iterator knownRepositoriesEnd() const;
 
       /** Find a \ref Repository named \c alias_r.
-       * Returns \ref Repository::norepository if there is no such \ref Repository.
+       * Returns \ref Repository::noRepository if there is no such \ref Repository.
        */
       Repository reposFind( const std::string & alias_r ) const;
+
+      Iterable<repository_iterator> knownRepositories() const
+      { return makeIterable( knownRepositoriesBegin(), knownRepositoriesEnd() ); }
       //@}
 
     public:
@@ -303,7 +366,7 @@ namespace zypp
       */
       const LocaleSet & getRequestedLocales() const;
 
-      /** Wheter this \ref Locale is in the set of requested locales. */
+      /** Whether this \ref Locale is in the set of requested locales. */
       bool isRequestedLocale( const Locale & locale_r ) const;
 
       /** Get the set of available locales.
@@ -312,46 +375,11 @@ namespace zypp
        */
       const LocaleSet & getAvailableLocales() const;
 
-      /** Wheter this \ref Locale is in the set of available locales. */
+      /** Whether this \ref Locale is in the set of available locales. */
       bool isAvailableLocale( const Locale & locale_r ) const;
       //@}
 
     public:
-      /** \name Handle automatic soft-locks.
-       *
-       * Solvables with and ident listed here are per default created with
-       * a setSoftLock applied. I.e. the \ref Resolver should not automatically
-       * select them, if they are just recommended.
-       *
-       * This list is considered when adding new repos to the pool. It is
-       * \b not the list of currently softLocked items.
-       *
-       * Mainly used to re-apply soft-locks remembered during the last commit.
-       */
-      //@{
-      typedef pool::PoolTraits::AutoSoftLocks          AutoSoftLocks;
-      typedef pool::PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
-
-      bool autoSoftLocksEmpty() const;
-      size_type autoSoftLocksSize() const;
-      autoSoftLocks_iterator autoSoftLocksBegin() const;
-      autoSoftLocks_iterator autoSoftLocksEnd() const;
-
-      /** Set a new soft-lock list.
-       * The soft-locks of existing PoolItems are adjusted according
-       * to the list. (usually called on target load)
-      */
-      void setAutoSoftLocks( const AutoSoftLocks & newLocks_r );
-
-      /** Suggest a new soft-lock list based on the current selection.
-       * Based on the the current soft-lock list. Items tagged to be
-       * installed are removed, and those tagged to be deleted are added.
-       * (usually remembered on commit).
-      */
-      void getActiveSoftLocks( AutoSoftLocks & activeLocks_r );
-      //@}
-
-    public:
       /** \name Handle hard locks (e.g set from /etc/zypp/locks).
        *
        * As this kind of lock is query based, it's quite expensive.
@@ -367,6 +395,9 @@ namespace zypp
       hardLockQueries_iterator hardLockQueriesBegin() const;
       hardLockQueries_iterator hardLockQueriesEnd() const;
 
+      Iterable<hardLockQueries_iterator> hardLockQueries() const
+      { return makeIterable( hardLockQueriesBegin(), hardLockQueriesEnd() ); }
+
       /** Set a new set of queries.
        * The hard-locks of existing PoolItems are adjusted according
        * to the queries. (usually called on target load)