add basic locale interface to ResPool, remove deprecated _gxx hashes
authorMichael Andres <ma@suse.de>
Thu, 14 Feb 2008 23:13:41 +0000 (23:13 +0000)
committerMichael Andres <ma@suse.de>
Thu, 14 Feb 2008 23:13:41 +0000 (23:13 +0000)
26 files changed:
zypp/@DOXYGEN/g_CodeSnippets
zypp/@DOXYGEN/n_ResPool_nomorenameiter [new file with mode: 0644]
zypp/Arch.cc
zypp/CMakeLists.txt
zypp/Capability.h
zypp/IdString.h
zypp/Locale.cc
zypp/Locale.h
zypp/PackageKeyword.h
zypp/ResPool.cc
zypp/ResPool.h
zypp/ZYpp.cc
zypp/ZYpp.h
zypp/base/Hash.h [deleted file]
zypp/base/LogTools.h
zypp/base/UniqueString.h [deleted file]
zypp/pool/PoolImpl.h
zypp/pool/PoolTraits.h
zypp/sat/Pool.cc
zypp/sat/Pool.h
zypp/sat/detail/PoolImpl.cc
zypp/sat/detail/PoolImpl.h
zypp/sat/detail/PoolMember.h
zypp/solver/detail/ResolverUpgrade.cc
zypp/zypp_detail/ZYppImpl.cc
zypp/zypp_detail/ZYppImpl.h

index 0ce7789..9775c39 100644 (file)
@@ -1,3 +1,27 @@
+// //////////////////////////////////////////////////////////////////////
+// If you prefer using iterator in a for' loop, but dislike to figure out
+// the exact type of the iterator, you may find the 'for_' macro convenient:
+// //////////////////////////////////////////////////////////////////////
+
+    #include "zypp/base/Easy.h"
+
+    for_( it, pool.byIdentBegin( kind, name ),
+              pool.byIdentEnd( kind, name ) )
+    {
+      PoolItem copy = *it;
+    }
+
+instead of:
+
+    for ( ResPool::byIdent_iterator it = pool.byIdentBegin( kind, name ),
+                                    end = pool.byIdentEnd( kind, name );
+          it != end, ++it )
+    {
+      PoolItem copy = *it;
+    }
+
+
+// //////////////////////////////////////////////////////////////////////
 // Avoid buggy code, that tries to erase elements, matching a
 // certain property from containers. Example:
 //
diff --git a/zypp/@DOXYGEN/n_ResPool_nomorenameiter b/zypp/@DOXYGEN/n_ResPool_nomorenameiter
new file mode 100644 (file)
index 0000000..2be1405
--- /dev/null
@@ -0,0 +1,71 @@
+
+I tagged the byName iterator as deprecated, so the compiler tells you
+where it is used. Please review the code and check whether byIdent is
+an appropriate replacement.
+
+
+--
+The 'old' zypp pool internally maintained a byName index, so it was a
+fast way to iterate the pool by name and filter by kind to visit e.g. 
+all packages named foo:
+
+    invokeOnEach( pool.byNameBegin( name ), pool.byNameEnd( name ),
+                  resfilter::ByKind( kind ),
+                 action() );
+
+    for_( it, pool.byNameBegin( name ), pool.byNameEnd( name ) )
+    {
+      if ( (*it)->kind() == kind )
+      {
+       ...
+      }
+    }
+
+This is no longer true.
+
+
+
+In contrary, byName now is a 'quite expensive' iteration. It's faster to 
+rewrite these loops using byIdent (and no filter):
+
+    invokeOnEach( pool.byIdentBegin( kind, name ), 
+                  pool.byIdentEnd( kind, name ),
+                 action() );
+
+    for_( it, pool.byIdentBegin( kind, name ), pool.byNameEnd( kind, name ) )
+    {
+      ...
+    }
+
+
+How to construct the byIdent iterator:
+
+    ResPool::byIdentBegin( poolItem )      // using this poolItems kind and name
+    ResPool::byIdentBegin( kind, name )    // explicit kind and name
+    ResPool::byIdentBegin<Package>( name ) // or templated kind
+
+
+
+--
+
+If you prefer using iterator in a for' loop, but dislike to figure out 
+the exact type of the iterator, you may find the 'for_' macro convenient:
+
+    #include "zypp/base/Easy.h"
+
+    for_( it, pool.byIdentBegin( kind, name ), 
+              pool.byIdentEnd( kind, name ) )
+    {
+      PoolItem copy = *it;
+    }
+
+
+instead of:
+
+    for ( ResPool::byIdent_iterator it = pool.byIdentBegin( kind, name ),
+                                    end = pool.byIdentEnd( kind, name );
+          it != end, ++it )
+    {
+      PoolItem copy = *it;
+    }
+
index 6d84242..979eebe 100644 (file)
@@ -238,6 +238,7 @@ namespace zypp
         defCompatibleWith( _ppc,       _ppc64 );
         //
         ///////////////////////////////////////////////////////////////////
+        dumpOn( USR ) << endl;
       }
 
     private:
index fe273b9..9de19c1 100644 (file)
@@ -223,7 +223,6 @@ SET( zypp_base_HEADERS
   base/Functional.h
   base/Gettext.h
   base/GzStream.h
-  base/Hash.h
   base/IOStream.h
   base/InputStream.h
   base/Iterator.h
@@ -241,7 +240,6 @@ SET( zypp_base_HEADERS
   base/String.h
   base/Regex.h
   base/Sysconfig.h
-  base/UniqueString.h
   base/Unit.h
   base/WatchFile.h
 )
index b0751b3..36bdc90 100644 (file)
@@ -13,7 +13,7 @@
 #define ZYPP_SAT_CAPABILITY_H
 
 #include <iosfwd>
-#include <set>
+#include <tr1/unordered_set>
 
 #include "zypp/base/SafeBool.h"
 #include "zypp/base/Deprecated.h"
@@ -34,7 +34,7 @@ namespace zypp
   class Capability;
   class CapDetail;
 
-  typedef std::set<Capability> CapabilitySet;
+  typedef std::tr1::unordered_set<Capability> CapabilitySet;
 
   ///////////////////////////////////////////////////////////////////
   //
@@ -54,7 +54,7 @@ namespace zypp
    * \endcode
    */
   class Capability: protected sat::detail::PoolMember,
-  private base::SafeBool<Capability>
+                    private base::SafeBool<Capability>
   {
     public:
       // legacy
@@ -302,4 +302,7 @@ namespace zypp
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
+
+ZYPP_DEFINE_ID_HASHABLE( ::zypp::Capability )
+
 #endif // ZYPP_SAT_CAPABILITY_H
index 92f8f71..ac82cc6 100644 (file)
@@ -208,4 +208,7 @@ namespace zypp
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
+
+ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString )
+
 #endif // ZYPP_SAT_IDSTR_H
index 10429af..e9927bf 100644 (file)
@@ -22,7 +22,7 @@ namespace zypp
 
   typedef std::map<std::string, std::string> OtherDefaultLanguage;
   static OtherDefaultLanguage otherDefaultLanguage;
-    
+
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : Locale::Impl
@@ -89,7 +89,7 @@ namespace zypp
 
       if (otherDefaultLanguage.find(code()) != otherDefaultLanguage.end())
          return LanguageCode(otherDefaultLanguage[code()]);
-           
+
       if ( _country.hasCode() )
         return _language;
 
@@ -142,6 +142,15 @@ namespace zypp
   //   METHOD NAME : Locale::Locale
   //   METHOD TYPE : Ctor
   //
+  Locale::Locale( IdString code_r )
+  : _pimpl( new Impl( code_r.asString() ) )
+  {}
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : Locale::Locale
+  //   METHOD TYPE : Ctor
+  //
   Locale::Locale( const std::string & code_r )
   : _pimpl( new Impl( code_r ) )
   {}
@@ -151,6 +160,15 @@ namespace zypp
   //   METHOD NAME : Locale::Locale
   //   METHOD TYPE : Ctor
   //
+  Locale::Locale( const char * code_r )
+  : _pimpl( new Impl( C_Str(code_r).c_str() ) )
+  {}
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : Locale::Locale
+  //   METHOD TYPE : Ctor
+  //
   Locale::Locale( const LanguageCode & language_r,
                   const CountryCode & country_r )
   : _pimpl( new Impl( language_r, country_r ) )
index 1859551..4540077 100644 (file)
 #define ZYPP_LOCALE_H
 
 #include <iosfwd>
+#include <tr1/unordered_set>
 
 #include "zypp/base/PtrTypes.h"
 
+#include "zypp/IdString.h"
 #include "zypp/LanguageCode.h"
 #include "zypp/CountryCode.h"
 
@@ -27,7 +29,9 @@ namespace zypp
   //
   //   CLASS NAME : Locale
   //
-  /** */
+  /**
+   * \todo migrate to IdString
+  */
   class Locale
   {
     friend std::ostream & operator<<( std::ostream & str, const Locale & obj );
@@ -42,8 +46,14 @@ namespace zypp
 
     /** Ctor taking a string. */
     explicit
+    Locale( IdString code_r );
+
+    explicit
     Locale( const std::string & code_r );
 
+    explicit
+    Locale( const char * code_r );
+
     /** Ctor taking LanguageCode and optional CountryCode. */
     Locale( const LanguageCode & language_r,
             const CountryCode & country_r = CountryCode() );
@@ -112,10 +122,23 @@ namespace zypp
   }
   //@}
 
+  ///////////////////////////////////////////////////////////////////
+
+  typedef std::tr1::unordered_set<Locale> LocaleSet;
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
 
+namespace std { namespace tr1 {
+  /** \relates ::zypp::Locale hash function */
+  template<> struct hash< ::zypp::Locale>
+  {
+    size_t operator()( const ::zypp::Locale & __s ) const
+    { return hash<std::string>()(__s.code()); }
+  };
+}}
+
 ///////////////////////////////////////////////////////////////////
 namespace std
 { /////////////////////////////////////////////////////////////////
index 688ef58..2c60e78 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef ZYPP_PACKAGEKEYWORD_H
 #define ZYPP_PACKAGEKEYWORD_H
 
-#include "zypp/base/UniqueString.h"
+#include "zypp/IdStringType.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -22,16 +22,25 @@ namespace zypp
   //
   //   CLASS NAME : PackageKeyword
   //
-  /** Package keywords. */
-  struct PackageKeyword : public base::UniqueString<PackageKeyword>
+  /** Package keywords.
+   * \see \ref IdStringType
+   */
+  class PackageKeyword : public IdStringType<PackageKeyword>
   {
-    PackageKeyword()
-    {}
+    public:
+      /** Default ctor: empty keyword */
+      PackageKeyword() {}
 
-    PackageKeyword( const std::string & name_r )
-      : base::UniqueString<PackageKeyword>( name_r )
-    {}
-  };
+      /** Ctor taking keyword as string. */
+      explicit PackageKeyword( sat::detail::IdType id_r )  : _str( IdString(id_r).c_str() ) {}
+      explicit PackageKeyword( const IdString & idstr_r )  : _str( idstr_r.c_str() ) {}
+      explicit PackageKeyword( const std::string & str_r ) : _str( str_r ) {}
+      explicit PackageKeyword( const char * cstr_r )       : _str( cstr_r ) {}
+
+    private:
+      friend class IdStringType<PackageKeyword>;
+      IdString _str;
+   };
   ///////////////////////////////////////////////////////////////////
 
   /////////////////////////////////////////////////////////////////
index dd2bd30..6fba802 100644 (file)
@@ -104,6 +104,32 @@ namespace zypp
   const pool::PoolTraits::Id2ItemT & ResPool::id2item() const
   { return _pimpl->id2item(); }
 
+  ///////////////////////////////////////////////////////////////////
+  //
+  // Forward to sat::Pool:
+  //
+  ///////////////////////////////////////////////////////////////////
+  void ResPool::setRequestedLocales( const LocaleSet & locales_r )
+  { sat::Pool::instance().setRequestedLocales( locales_r ); }
+
+  bool ResPool::addRequestedLocale( const Locale & locale_r )
+  { return sat::Pool::instance().addRequestedLocale( locale_r ); }
+
+  bool ResPool::eraseRequestedLocale( const Locale & locale_r )
+  { return sat::Pool::instance().eraseRequestedLocale( locale_r ); }
+
+  const LocaleSet & ResPool::getRequestedLocales() const
+  { return sat::Pool::instance().getRequestedLocales(); }
+
+  bool ResPool::isRequestedLocale( const Locale & locale_r ) const
+  { return sat::Pool::instance().isRequestedLocale( locale_r ); }
+
+  const LocaleSet & ResPool::getAvailableLocales() const
+  { return sat::Pool::instance().getAvailableLocales(); }
+
+  bool ResPool::isAvailableLocale( const Locale & locale_r ) const
+  { return sat::Pool::instance().isAvailableLocale( locale_r ); }
+
   /******************************************************************
   **
   **   FUNCTION NAME : operator<<
index 864e7f0..36cf562 100644 (file)
@@ -28,8 +28,6 @@ namespace zypp
   class SerialNumber;
   class ResPoolProxy;
 
-
-
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : ResPool
@@ -43,6 +41,8 @@ namespace zypp
    * the index is not yet implemented, they are realized as
    * an ordinary filter iterator. Do not provide filter iterators
    * here, if there is no index table for it.
+   *
+   * \include n_ResPool_nomorenameiter
   */
   class ResPool
   {
@@ -55,7 +55,7 @@ namespace zypp
       typedef pool::PoolTraits::const_iterator          const_iterator;
 
       typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
-      typedef pool::PoolTraits::AdditionalCapabilities  AdditionalCapabilities;
+      typedef pool::PoolTraits::AdditionalCapabilities    AdditionalCapabilities;
       typedef pool::PoolTraits::repository_iterator        repository_iterator;
 
     public:
@@ -111,72 +111,69 @@ namespace zypp
     public:
       /** \name Iterate through all PoolItems of a certain name and kind. */
       //@{
-      typedef pool::ByIdent ByIdent;
-      typedef pool::PoolTraits::Id2ItemT        Id2ItemT;
-      typedef transform_iterator<std::_Select2nd<Id2ItemT::value_type>, Id2ItemT::const_iterator> byIdent_iterator;
+      typedef pool::ByIdent                       ByIdent;
+      typedef pool::PoolTraits::byIdent_iterator  byIdent_iterator;
 
-      byIdent_iterator byIdentBegin( sat::detail::IdType id ) const
+      byIdent_iterator byIdentBegin( const ByIdent & ident_r ) const
       {
-        std::pair<Id2ItemT::const_iterator, Id2ItemT::const_iterator> it2
-             = id2item().equal_range(id);
-       return make_transform_iterator(it2.first, std::_Select2nd<Id2ItemT::value_type>());
-      }
-
-      byIdent_iterator byIdentEnd( sat::detail::IdType id ) const
-      {
-        std::pair<Id2ItemT::const_iterator, Id2ItemT::const_iterator> it2
-             = id2item().equal_range(id);
-       return make_transform_iterator(it2.second, std::_Select2nd<Id2ItemT::value_type>());
+       return make_transform_iterator( id2item().equal_range( ident_r.get() ).first,
+                                        pool::PoolTraits::Id2ItemValueSelector() );
       }
 
       byIdent_iterator byIdentBegin( ResKind kind_r, IdString name_r ) const
-      { return byIdentBegin( ByIdent(kind_r,name_r).get() ); }
+      { return byIdentBegin( ByIdent(kind_r,name_r) ); }
 
       byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
-      { return byIdentBegin( ByIdent(kind_r,name_r).get() ); }
+      { return byIdentBegin( ByIdent(kind_r,name_r) ); }
 
       template<class _Res>
       byIdent_iterator byIdentBegin( IdString name_r ) const
-      { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r).get() ); }
+      { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
 
       template<class _Res>
       byIdent_iterator byIdentBegin( const C_Str & name_r ) const
-      { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r).get() ); }
+      { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
 
       /** Derive name and kind from \ref PoolItem. */
       byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
-      { return byIdentBegin( ByIdent(pi_r.satSolvable()).get() ); }
+      { return byIdentBegin( ByIdent(pi_r.satSolvable()) ); }
       /** Derive name and kind from \ref sat::Solvable. */
       byIdent_iterator byIdentBegin( sat::Solvable slv_r ) const
-      { return byIdentBegin( ByIdent(slv_r).get() ); }
+      { return byIdentBegin( ByIdent(slv_r) ); }
       /** Takes a \ref sat::Solvable::ident string. */
       byIdent_iterator byIdentBegin( IdString ident_r ) const
-      { return byIdentBegin( ByIdent(ident_r).get() ); }
+      { return byIdentBegin( ByIdent(ident_r) ); }
 
 
+      byIdent_iterator byIdentEnd( const ByIdent & ident_r ) const
+      {
+       return make_transform_iterator( id2item().equal_range( ident_r.get() ).second,
+                                        pool::PoolTraits::Id2ItemValueSelector() );
+      }
+
       byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
-      { return byIdentEnd( ByIdent(kind_r,name_r).get() ); }
+      { return byIdentEnd( ByIdent(kind_r,name_r) ); }
 
       byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
-      { return byIdentEnd( ByIdent(kind_r,name_r).get() ); }
+      { return byIdentEnd( ByIdent(kind_r,name_r) ); }
 
       template<class _Res>
       byIdent_iterator byIdentEnd( IdString name_r ) const
-      { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r).get() ); }
+      { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
 
       template<class _Res>
       byIdent_iterator byIdentEnd( const C_Str & name_r ) const
-      { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r).get() ); }
+      { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
 
       /** Derive name and kind from \ref PoolItem. */
       byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
-      { return byIdentEnd( ByIdent(pi_r.satSolvable()).get() ); }
+      { return byIdentEnd( ByIdent(pi_r.satSolvable()) ); }
       /** Derive name and kind from \ref sat::Solvable. */
       byIdent_iterator byIdentEnd( sat::Solvable slv_r ) const
-      { return byIdentEnd( ByIdent(slv_r).get() ); }
+      { return byIdentEnd( ByIdent(slv_r) ); }
       /** Takes a \ref sat::Solvable::ident string. */
       byIdent_iterator byIdentEnd( IdString ident_r ) const
-      { return byIdentEnd( ByIdent(ident_r).get() ); }
+      { return byIdentEnd( ByIdent(ident_r) ); }
      //@}
 
     public:
@@ -236,7 +233,45 @@ namespace zypp
       repository_iterator knownRepositoriesEnd() const;
       //@}
 
-    public:
+     public:
+      /** \name Iterate through requested/available Locales.
+       */
+      //@{
+      /** Set the requested locales.
+       * Languages to be supported by the system, e.g. language specific
+       * packages to be installed.
+       */
+      void setRequestedLocales( const LocaleSet & locales_r );
+
+      /** Add one \ref Locale to the set of requested locales.
+       * Return \c true if \c locale_r was newly added to the set.
+      */
+      bool addRequestedLocale( const Locale & locale_r );
+
+      /** Erase one \ref Locale from the set of requested locales.
+      * Return \c false if \c locale_r was not found in the set.
+       */
+      bool eraseRequestedLocale( const Locale & locale_r );
+
+      /** Return the requested locales.
+       * \see \ref setRequestedLocales
+      */
+      const LocaleSet & getRequestedLocales() const;
+
+      /** Wheter this \ref Locale is in the set of requested locales. */
+      bool isRequestedLocale( const Locale & locale_r ) const;
+
+      /** Get the set of available locales.
+       * This is computed from the package data so it actually
+       * represents all locales packages claim to support.
+       */
+      const LocaleSet & getAvailableLocales() const;
+
+      /** Wheter this \ref Locale is in the set of available locales. */
+      bool isAvailableLocale( const Locale & locale_r ) const;
+      //@}
+
+   public:
       /** \name Handling addition capabilities in the pool in order for solving it in
        *  a solver run. This is used for tasks like needing a package with the name "foo".
        *  The solver has to evaluate a proper package by his own.
index 5cd4639..4d2d0bf 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "zypp/ZYpp.h"
 #include "zypp/zypp_detail/ZYppImpl.h"
+#include "zypp/sat/Pool.h"
 
 using std::endl;
 
@@ -99,16 +100,14 @@ namespace zypp
   ///////////////////////////////////////////////////////////////////
 
   void ZYpp::setRequestedLocales( const LocaleSet & locales_r )
-  { _pimpl->setRequestedLocales( locales_r ); }
+  { sat::Pool::instance().setRequestedLocales( locales_r ); }
 
-  ZYpp::LocaleSet ZYpp::getRequestedLocales() const
-  { return _pimpl->getRequestedLocales(); }
+  const LocaleSet & ZYpp::getRequestedLocales() const
+  { return sat::Pool::instance().getRequestedLocales(); }
 
-  ZYpp::LocaleSet ZYpp::getAvailableLocales() const
-  { return _pimpl->getAvailableLocales(); }
+  const LocaleSet & ZYpp::getAvailableLocales() const
+  { return sat::Pool::instance().getAvailableLocales(); }
 
-  void ZYpp::availableLocale( const Locale & locale_r )
-  { _pimpl->availableLocale( locale_r ); }
 
   Pathname ZYpp::homePath() const
   { return _pimpl->homePath(); }
index 8a5ee36..88381c6 100644 (file)
@@ -41,7 +41,6 @@ namespace zypp
   class ZYppFactory;
   class ResPool;
   class ResPoolProxy;
-  class Locale;
   class KeyRing;
 
   ///////////////////////////////////////////////////////////////////
@@ -129,30 +128,28 @@ namespace zypp
 
   public:
     /** \name move to pool
+     * \deprecated Use ResPool diretcly.
     */
     //@{
-    typedef std::set<Locale> LocaleSet;
     /** Set the requested locales.
      * Languages to be supported by the system, e.g. language specific
      * packages to be installed. This function operates on the pool,
      * so only the locales that are available as resolvables
      * are marked as requested. The rest is ignored.
+     * \deprecated Use ResPool diretcly.
     */
-    void setRequestedLocales( const LocaleSet & locales_r );
-    /** */
-    LocaleSet getRequestedLocales() const;
+    void setRequestedLocales( const LocaleSet & locales_r ) ZYPP_DEPRECATED;
+
+    /** \deprecated Use ResPool diretcly. */
+    const LocaleSet & getRequestedLocales() const ZYPP_DEPRECATED;
 
     /**
      * Get the set of available locales.
      * This is computed from the package data so it actually
      * represents all locales packages claim to support.
+     * \deprecated Use ResPool diretcly.
      */
-    LocaleSet getAvailableLocales() const;
-
-    /**
-     * internal use only
-     **/
-    void availableLocale( const Locale & locale_r );
+    const LocaleSet & getAvailableLocales() const ZYPP_DEPRECATED;
     //@}
 
   public:
diff --git a/zypp/base/Hash.h b/zypp/base/Hash.h
deleted file mode 100644 (file)
index dbd7e02..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file      zypp/base/Hash.h
- *
-*/
-#ifndef ZYPP_BASE_HASH_H
-#define ZYPP_BASE_HASH_H
-
-#include <string>
-
-#include <ext/hash_set>
-#include <ext/hash_map>
-
-///////////////////////////////////////////////////////////////////
-namespace __gnu_cxx
-{ /////////////////////////////////////////////////////////////////
-
-  /** Specialize hash function for std::string. */
-  template<>
-    struct hash<std::string>
-    {
-      size_t operator()( const std::string & __s ) const
-      { return __stl_hash_string(__s.c_str()); }
-    };
-
-  /////////////////////////////////////////////////////////////////
-} // namespace __gnu_cxx
-///////////////////////////////////////////////////////////////////
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
-  using __gnu_cxx::hash_set;
-  using __gnu_cxx::hash_map;
-
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_BASE_HASH_H
index dd1bed2..5ca601d 100644 (file)
@@ -18,6 +18,8 @@
 #include <list>
 #include <set>
 #include <map>
+#include <tr1/unordered_set>
+#include <tr1/unordered_map>
 #include "zypp/base/Logger.h"
 #include "zypp/base/Iterator.h"
 #include "zypp/base/Deprecated.h"
@@ -121,6 +123,10 @@ namespace zypp
     { return dumpRange( str, obj.begin(), obj.end() ); }
 
   template<class _Tp>
+    std::ostream & operator<<( std::ostream & str, const std::tr1::unordered_set<_Tp> & obj )
+    { return dumpRange( str, obj.begin(), obj.end() ); }
+
+  template<class _Tp>
     std::ostream & operator<<( std::ostream & str, const std::list<_Tp> & obj )
     { return dumpRange( str, obj.begin(), obj.end() ); }
 
@@ -203,14 +209,6 @@ namespace zypp
         MapEntry_const_iterator end() const
         { return make_transform_iterator( map().end(), Transformer() );}
 
-        /** \deprecated Use begin. */
-        ZYPP_DEPRECATED MapEntry_const_iterator map_begin() const
-        { return make_transform_iterator( map().begin(), Transformer() ); }
-
-        /** \deprecated Use end. */
-        ZYPP_DEPRECATED MapEntry_const_iterator map_end() const
-        { return make_transform_iterator( map().end(), Transformer() );}
-
       private:
         const _Map *const _map;
       };
@@ -329,6 +327,10 @@ namespace zypp
     std::ostream & operator<<( std::ostream & str, const std::map<_Key, _Tp> & obj )
     { return str << dumpMap( obj ); }
 
+  template<class _Key, class _Tp>
+    std::ostream & operator<<( std::ostream & str, const std::tr1::unordered_map<_Key, _Tp> & obj )
+    { return str << dumpMap( obj ); }
+
   /** Print stream status bits.
    * Prints the values of a streams \c good, \c eof, \c failed and \c bad bit.
    *
diff --git a/zypp/base/UniqueString.h b/zypp/base/UniqueString.h
deleted file mode 100644 (file)
index b9c2ac5..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file      zypp/base/UniqueString.h
- *
-*/
-#ifndef ZYPP_BASE_UNIQUESTRING_H
-#define ZYPP_BASE_UNIQUESTRING_H
-
-#include <iosfwd>
-#include <string>
-
-#include <zypp/base/Hash.h>
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-  namespace base
-  { /////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : UniqueString
-    //
-    /** Immutable strings with unique representation in memory.
-     *
-     * Each UniqueString provides a <tt>const std::string</tt>.
-     * This string is stored in a unifying hash, that way equal
-     * UniqueStrings share their string representation in memory.
-     *
-     * At the same time the unifying hash contains all the string
-     * values created so far. Static methods are provided to query
-     * the hash contents.
-     *
-     * Uses CRTP to provide the unifying hash.
-     *
-     * \code
-     *   struct KeyWord : public base::UniqueString<KeyWord>
-     *   {
-     *     KeyWord()
-     *     {}
-     *     KeyWord( const std::string & name_r )
-     *       :base::UniqueString<KeyWord>( name_r )
-     *     {}
-     *   };
-     *
-     *   int main( int argc, char * argv[] )
-     *   {
-     *     KeyWord();
-     *     KeyWord( "a" );
-     *     KeyWord( "b" );
-     *     KeyWord( "c" );
-     *     KeyWord( "a" );
-     *     KeyWord( "c" );
-     *
-     *     DBG << "Known KeyWords: " << KeyWord::allSize() << endl;
-     *     for ( KeyWord::const_iterator it = KeyWord::allBegin(); it != KeyWord::allEnd(); ++it )
-     *     {
-     *       DBG << *it << endl;
-     *     }
-     *
-     *     return 0;
-     *   }
-     * \endcode
-     * \code
-     * Known KeyWords: 3
-     * a
-     * b
-     * c
-     * \endcode
-    */
-    template<class _Derived>
-       class UniqueString
-    {
-    protected:
-      /** Default ctor provides an empty string. */
-      UniqueString()
-      {}
-
-      /** Ctor taking a name to store. */
-      UniqueString( const std::string & name_r )
-      {
-       if ( !name_r.empty() )
-       {
-         _name = *(this->hash().insert( name_r ).first);
-       }
-      }
-
-      /** Dtor */
-      virtual ~UniqueString()
-      {}
-
-    public:
-      /** Explicit conversion to string. */
-      const std::string & asString() const
-      { return _name; }
-
-      /** Explicit conversion to string (convenience). */
-      const std::string & str() const
-      { return asString(); }
-
-      /** Implicit conversion to string. */
-      operator const std::string & () const
-      { return asString(); }
-
-      /** Short for <tt>str().size()</tt>. */
-      std::string::size_type size() const
-      { return asString().size(); }
-
-      /** Short for <tt>str().empty()</tt>. */
-      bool empty() const
-      { return asString().empty(); }
-
-      /** Short for <tt>str().compare( s )</tt>.*/
-      int compare( const std::string & rhs ) const
-      {        return asString().compare( rhs ); }
-
-    public:
-      typedef hash_set<std::string>::size_type size_type;
-      typedef hash_set<std::string>::const_iterator const_iterator;
-
-      /** Whether there are known UniqueStrings. */
-      static bool allEmpty()
-      { return hash().empty(); }
-
-      /** Number of known UniqueStrings. */
-      static size_type allSize()
-      { return hash().size(); }
-
-      /** Iterator to the 1st UniqueString. */
-      static const_iterator allBegin()
-      { return hash().begin(); }
-
-      /** Iterator behind the last UniqueString. */
-      static const_iterator allEnd()
-      { return hash().end(); }
-
-    private:
-      /** Provides the static hash to unify the strings. */
-      static hash_set<std::string> & hash()
-      {
-       static hash_set<std::string> _value;
-       return _value;
-      }
-
-    private:
-      /** Immutable string. */
-      std::string _name;
-    };
-    ///////////////////////////////////////////////////////////////////
-
-    /** \relates UniqueString operator == */
-    template<class _Derived>
-       inline bool operator==( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs.str() == rhs.str() ); }
-    /** \relates UniqueString operator == */
-    template<class _Derived>
-       inline bool operator==( const UniqueString<_Derived> & lhs, const std::string & rhs )
-    { return ( lhs.str() == rhs ); }
-    /** \relates UniqueString operator == */
-    template<class _Derived>
-       inline bool operator==( const std::string & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs == rhs.str() ); }
-
-
-    /** \relates UniqueString operator != */
-    template<class _Derived>
-       inline bool operator!=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs.str() != rhs.str() ); }
-    /** \relates UniqueString operator != */
-    template<class _Derived>
-       inline bool operator!=( const UniqueString<_Derived> & lhs, const std::string & rhs )
-    { return ( lhs.str() != rhs ); }
-    /** \relates UniqueString operator != */
-    template<class _Derived>
-       inline bool operator!=( const std::string & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs != rhs.str() ); }
-
-
-    /** \relates UniqueString operator < */
-    template<class _Derived>
-       inline bool operator<( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs.str() < rhs.str() ); }
-    /** \relates UniqueString operator < */
-    template<class _Derived>
-       inline bool operator<( const UniqueString<_Derived> & lhs, const std::string & rhs )
-    { return ( lhs.str() < rhs ); }
-    /** \relates UniqueString operator < */
-    template<class _Derived>
-       inline bool operator<( const std::string & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs < rhs.str() ); }
-
-
-    /** \relates UniqueString operator > */
-    template<class _Derived>
-       inline bool operator>( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs.str() > rhs.str() ); }
-    /** \relates UniqueString operator > */
-    template<class _Derived>
-       inline bool operator>( const UniqueString<_Derived> & lhs, const std::string & rhs )
-    { return ( lhs.str() > rhs ); }
-    /** \relates UniqueString operator > */
-    template<class _Derived>
-       inline bool operator>( const std::string & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs > rhs.str() ); }
-
-
-    /** \relates UniqueString operator <= */
-    template<class _Derived>
-       inline bool operator<=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs.str() <= rhs.str() ); }
-    /** \relates UniqueString operator <= */
-    template<class _Derived>
-       inline bool operator<=( const UniqueString<_Derived> & lhs, const std::string & rhs )
-    { return ( lhs.str() <= rhs ); }
-    /** \relates UniqueString operator <= */
-    template<class _Derived>
-       inline bool operator<=( const std::string & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs <= rhs.str() ); }
-
-
-    /** \relates UniqueString operator >= */
-    template<class _Derived>
-       inline bool operator>=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs.str() >= rhs.str() ); }
-    /** \relates UniqueString operator >= */
-    template<class _Derived>
-       inline bool operator>=( const UniqueString<_Derived> & lhs, const std::string & rhs )
-    { return ( lhs.str() >= rhs ); }
-    /** \relates UniqueString operator >= */
-    template<class _Derived>
-       inline bool operator>=( const std::string & lhs, const UniqueString<_Derived> & rhs )
-    { return ( lhs >= rhs.str() ); }
-
-    /** \relates UniqueString Stream output */
-    template<class _Derived>
-       inline std::ostream & operator<<( std::ostream & str, const UniqueString<_Derived> & obj )
-    { return str << obj.str(); }
-
-    /////////////////////////////////////////////////////////////////
-  } // namespace base
-  ///////////////////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_BASE_UNIQUESTRING_H
index 10e6635..bb5d7ed 100644 (file)
@@ -13,9 +13,9 @@
 #define ZYPP_POOL_POOLIMPL_H
 
 #include <iosfwd>
-#include <map>
 
 #include "zypp/base/Easy.h"
+#include "zypp/base/LogTools.h"
 #include "zypp/base/SerialNumber.h"
 #include "zypp/base/Deprecated.h"
 
@@ -81,6 +81,12 @@ namespace zypp
         size_type size() const
         { return satpool().solvablesSize(); }
 
+        const_iterator begin() const
+        { return make_filter_begin( pool::ByPoolItem(), store() ); }
+
+        const_iterator end() const
+        { return make_filter_end( pool::ByPoolItem(), store() ); }
+
       public:
         /** Return the corresponding \ref PoolItem.
          * Pool and sat pool should be in sync. Returns an empty
@@ -88,9 +94,7 @@ namespace zypp
          * \see \ref PoolItem::satSolvable.
          */
         PoolItem find( const sat::Solvable & slv_r ) const
-        {
-          return store()[slv_r.id()];
-        }
+        { return store()[slv_r.id()]; }
 
         ///////////////////////////////////////////////////////////////////
         //
@@ -209,30 +213,6 @@ namespace zypp
                   pi = PoolItem( s );
               }
             }
-#if 0
-            // pass 1: delete no longer existing solvables
-            for ( ContainerT::iterator it = _store.begin(); it != _store.end(); /**/ )
-            {
-              if ( ! it->first ) // solvable became invalid
-                _store.erase( it++ ); // postfix! Incrementing before erase
-              else
-                ++it;
-            }
-
-            // pass 2: add new solvables
-            sat::Pool pool( satpool() );
-            if ( _store.size() != pool.solvablesSize() )
-            {
-              for_( it, pool.solvablesBegin(), pool.solvablesEnd() )
-              {
-                PoolItem & pi( _store[*it] );
-                if ( ! pi ) // newly created
-                {
-                  pi = PoolItem( *it );
-                }
-              }
-            }
-#endif
             _storeDirty = false;
           }
           return _store;
@@ -241,23 +221,21 @@ namespace zypp
        const Id2ItemT & id2item () const
        {
          checkSerial();
-         if (_id2itemDirty)
+         if ( _id2itemDirty )
          {
-           _id2itemDirty = false;
            store();
-           _id2item = Id2ItemT(size());
-           const_iterator it = make_filter_begin( ByPoolItem(), store() );
-           const_iterator e = make_filter_end( ByPoolItem(), store() );
-           for (; it != e; ++it)
-             {
-               sat::detail::IdType id;
-               const sat::Solvable &s = (*it)->satSolvable();
-               id = s.ident().id();
-               if (s.isKind( ResKind::srcpackage ))
-                 id = -id;
-               _id2item.insert(std::make_pair(id, *it));
-             }
-         }
+           _id2item = Id2ItemT( size() );
+            for_( it, begin(), end() )
+            {
+              const sat::Solvable &s = (*it)->satSolvable();
+              sat::detail::IdType id = s.ident().id();
+              if ( s.isKind( ResKind::srcpackage ) )
+                id = -id;
+              _id2item.insert( std::make_pair( id, *it ) );
+            }
+            //INT << _id2item << endl;
+           _id2itemDirty = false;
+          }
          return _id2item;
        }
 
@@ -270,6 +248,7 @@ namespace zypp
         {
           if ( _watcher.remember( serial() ) )
             invalidate();
+          satpool().prepare(); // always ajust dependencies.
         }
 
         void invalidate() const
index b399879..e44c6f2 100644 (file)
 
 #include <set>
 #include <map>
+#include <list>
+#include <vector>
 #include <tr1/unordered_map>
 
 #include "zypp/base/Iterator.h"
+#include "zypp/base/Iterator.h"
 
 #include "zypp/PoolItem.h"
 #include "zypp/sat/Pool.h"
@@ -41,17 +44,21 @@ namespace zypp
       { return pi; }
     };
 
-    /** Main filter selecting PoolItems bu \c name and \c kind.
+    /** Main filter selecting PoolItems by \c name and \c kind.
      *
     */
     class ByIdent
     {
       public:
-        ByIdent( sat::Solvable slv_r )
+        ByIdent()
+        : _id( 0 )
+        {}
+
+        explicit ByIdent( sat::Solvable slv_r )
         : _id( makeIdent( slv_r ) )
         {}
 
-        ByIdent( IdString ident_r )
+        explicit ByIdent( IdString ident_r )
         : _id( ident_r.id() )
         {}
 
@@ -120,18 +127,27 @@ namespace zypp
     {
     public:
       typedef sat::detail::SolvableIdType              SolvableIdType;
+
       /** pure items  */
-#if 0
-       typedef std::map<sat::Solvable,PoolItem>                ItemContainerT;
-       typedef MapKVIteratorTraits<ItemContainerT>::Value_const_iterator
-                                                               const_iterator;
-#endif
       typedef std::vector<PoolItem>                    ItemContainerT;
       typedef ItemContainerT::const_iterator            item_iterator;
       typedef filter_iterator<ByPoolItem,ItemContainerT::const_iterator>
                                                        const_iterator;
       typedef ItemContainerT::size_type                        size_type;
-      typedef std::tr1::unordered_multimap<sat::detail::IdType, PoolItem>      Id2ItemT;
+
+      /** ident index */
+      typedef std::tr1::unordered_multimap<sat::detail::IdType, PoolItem>
+                                                        Id2ItemT;
+      typedef std::_Select2nd<Id2ItemT::value_type>     Id2ItemValueSelector;
+      typedef transform_iterator<Id2ItemValueSelector, Id2ItemT::const_iterator>
+                                                        byIdent_iterator;
+
+
+      /* list of known Repositories */
+      typedef std::list<Repository>                     RepoContainerT;
+      typedef RepoContainerT::const_iterator           repository_iterator;
+
+
 
       // internal organization
       typedef std::list<zypp::CapAndItem>              CapItemContainerT;      // (why,who) pairs
@@ -144,9 +160,6 @@ namespace zypp
       /** hashed by capability index */
       typedef const_capitemiterator                     byCapabilityIndex_iterator;
 
-      /* list of known Repositories */
-      typedef std::list<Repository>                     RepoContainerT;
-      typedef RepoContainerT::const_iterator           repository_iterator;
 
       typedef PoolImpl                   Impl;
       typedef shared_ptr<PoolImpl>       Impl_Ptr;
index f2903ed..baf8f5b 100644 (file)
@@ -49,7 +49,7 @@ namespace zypp
     const SerialNumber & Pool::serial() const
     { return myPool().serial(); }
 
-    void Pool::prepare()
+    void Pool::prepare() const
     { return myPool().prepare(); }
 
     bool Pool::reposEmpty() const
@@ -147,8 +147,30 @@ namespace zypp
       return ret;
     }
 
+    /////////////////////////////////////////////////////////////////
+
+    void Pool::setRequestedLocales( const LocaleSet & locales_r )
+    { myPool().setRequestedLocales( locales_r ); }
+
+    bool Pool::addRequestedLocale( const Locale & locale_r )
+    { return myPool().addRequestedLocale( locale_r ); }
+
+    bool Pool::eraseRequestedLocale( const Locale & locale_r )
+    { return myPool().eraseRequestedLocale( locale_r ); }
+
+    const LocaleSet & Pool::getRequestedLocales() const
+    { return myPool().getRequestedLocales(); }
+
+    bool Pool::isRequestedLocale( const Locale & locale_r ) const
+    { return myPool().isRequestedLocale( locale_r ); }
+
+    const LocaleSet & Pool::getAvailableLocales() const
+    {  return myPool().getAvailableLocales(); }
+
+    bool Pool::isAvailableLocale( const Locale & locale_r ) const
+    { return myPool().isAvailableLocale( locale_r ); }
 
-    /******************************************************************
+   /******************************************************************
     **
     ** FUNCTION NAME : operator<<
     ** FUNCTION TYPE : std::ostream &
index e68eaaa..eb15f1f 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "zypp/sat/detail/PoolMember.h"
 #include "zypp/sat/Repo.h"
+#include "zypp/Locale.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -62,7 +63,7 @@ namespace zypp
         const SerialNumber & serial() const;
 
         /** Update housekeeping data if necessary (e.g. whatprovides). */
-        void prepare();
+        void prepare() const;
 
       public:
         /** Whether \ref Pool contains repos. */
@@ -103,8 +104,6 @@ namespace zypp
         { return reposInsert( systemRepoName() ); }
 
       public:
-
-      public:
         /** Load \ref Solvables from a solv-file into a \ref Repo named \c name_r.
          * In case of an exception the \ref Repo is removed from the \ref Pool.
          * \throws Exception if loading the solv-file fails.
@@ -132,6 +131,43 @@ namespace zypp
         SolvableIterator solvablesEnd() const;
 
       public:
+        /** \name Requested locales. */
+        //@{
+        /** Set the requested locales.
+         * Languages to be supported by the system, e.g. language specific
+         * packages to be installed.
+         */
+        void setRequestedLocales( const LocaleSet & locales_r );
+
+        /** Add one \ref Locale to the set of requested locales.
+         * Return \c true if \c locale_r was newly added to the set.
+        */
+        bool addRequestedLocale( const Locale & locale_r );
+
+        /** Erase one \ref Locale from the set of requested locales.
+        * Return \c false if \c locale_r was not found in the set.
+         */
+        bool eraseRequestedLocale( const Locale & locale_r );
+
+        /** Return the requested locales.
+         * \see \ref setRequestedLocales
+        */
+        const LocaleSet & getRequestedLocales() const;
+
+        /** Wheter this \ref Locale is in the set of requested locales. */
+        bool isRequestedLocale( const Locale & locale_r ) const;
+
+        /** Get the set of available locales.
+         * This is computed from the package data so it actually
+         * represents all locales packages claim to support.
+         */
+        const LocaleSet & getAvailableLocales() const;
+
+        /** Wheter this \ref Locale is in the set of available locales. */
+        bool isAvailableLocale( const Locale & locale_r ) const;
+        //@}
+
+      public:
         /** Expert backdoor. */
         ::_Pool * get() const;
       private:
index c8a4704..7d2ca3d 100644 (file)
@@ -62,9 +62,14 @@ namespace zypp
          }
       }
 
-      static detail::IdType nsCallback( struct _Pool *, void *data, detail::IdType lhs, detail::IdType rhs )
+      detail::IdType PoolImpl::nsCallback( struct _Pool *, void *data, detail::IdType lhs, detail::IdType rhs )
       {
-        //T << Cability( lhs ) << (const char *)data << Capability( rhs ) << endl;
+        if ( lhs == NAMESPACE_LANGUAGE )
+        {
+          const std::tr1::unordered_set<IdString> & locale2Solver( reinterpret_cast<PoolImpl*>(data)->_locale2Solver );
+          return locale2Solver.find( IdString(rhs) ) == locale2Solver.end() ? -1 : 0;
+        }
+        DBG << Capability( lhs ) << " vs. " << Capability( rhs ) << endl;
         return 0;
       }
 
@@ -101,8 +106,7 @@ namespace zypp
 
         // set namespace callback
         _pool->nscallback = &nsCallback;
-        _pool->nscallbackdata = (void*)" NAMESPACE ";
-        SEC << _pool->nscallback << endl;
+        _pool->nscallbackdata = (void*)this;
       }
 
       ///////////////////////////////////////////////////////////////////
@@ -125,16 +129,34 @@ namespace zypp
           else if ( a2 ) DBG << a1 << " " << a2 << endl;
           else           DBG << a1 << endl;
         }
-        _serial.setDirty();
+        _serial.setDirty();       // pool content change
+        _localeCollector.clear(); // available locales may change
+
+        // invaldate dependency/namespace related indices:
+        depSetDirty();
+      }
+
+      void PoolImpl::depSetDirty( const char * a1, const char * a2, const char * a3 )
+      {
+        if ( a1 )
+        {
+          if      ( a3 ) DBG << a1 << " " << a2 << " " << a3 << endl;
+          else if ( a2 ) DBG << a1 << " " << a2 << endl;
+          else           DBG << a1 << endl;
+        }
         ::pool_freewhatprovides( _pool );
       }
 
-      void PoolImpl::prepare()
+      void PoolImpl::prepare() const
       {
         if ( _watcher.remember( _serial ) )
         {
-           // sat solver claims to handle this on it's own:
-           ::pool_createwhatprovides( _pool );
+          /* nothing to do here, but _watcher MUST remember... */
+        }
+        if ( ! _pool->whatprovides )
+        {
+          DBG << "pool_createwhatprovides..." << endl;
+          ::pool_createwhatprovides( _pool );
         }
       }
 
@@ -144,7 +166,6 @@ namespace zypp
       {
         setDirty(__FUNCTION__, repo_r->name );
         int ret = ::repo_add_solv( repo_r , file_r  );
-
         if ( ret == 0 )
         {
           // Filter out unwanted archs
@@ -184,10 +205,54 @@ namespace zypp
             blockBegin = blockSize = 0;
           }
         }
-
         return ret;
       }
 
+      ///////////////////////////////////////////////////////////////////
+
+      // need on demand and id based Locale
+      void _locale_hack( const LocaleSet & locales_r,
+                         std::tr1::unordered_set<IdString> & locale2Solver )
+      {
+        std::tr1::unordered_set<IdString>( 2*locales_r.size() ).swap( locale2Solver ) ;
+        for_( it, locales_r.begin(),locales_r.end() )
+        {
+          for ( Locale l( *it ); l != Locale::noCode; l = l.fallback() )
+            locale2Solver.insert( IdString( l.code() ) );
+        }
+        DBG << "New Solver Locales: " << locale2Solver << endl;
+      }
+
+
+      void PoolImpl::setRequestedLocales( const LocaleSet & locales_r )
+      {
+        depSetDirty( "setRequestedLocales" );
+        _requestedLocales = locales_r;
+        DBG << "New RequestedLocales: " << locales_r << endl;
+        _locale_hack( _requestedLocales, _locale2Solver );
+      }
+
+      bool PoolImpl::addRequestedLocale( const Locale & locale_r )
+      {
+        if ( _requestedLocales.insert( locale_r ).second )
+        {
+          depSetDirty( "addRequestedLocale", locale_r.code().c_str() );
+          _locale_hack( _requestedLocales, _locale2Solver );
+          return true;
+        }
+        return false;
+      }
+
+      bool PoolImpl::eraseRequestedLocale( const Locale & locale_r )
+      {
+        if ( _requestedLocales.erase( locale_r ) )
+        {
+          depSetDirty( "addRequestedLocale", locale_r.code().c_str() );
+          _locale_hack( _requestedLocales, _locale2Solver );
+          return true;
+        }
+        return false;
+      }
 
       /////////////////////////////////////////////////////////////////
     } // namespace detail
index f870c3c..03cd829 100644 (file)
@@ -20,11 +20,14 @@ extern "C"
 #include <satsolver/repo_solv.h>
 }
 #include <iosfwd>
+#include <tr1/unordered_set>
 
 #include "zypp/base/NonCopyable.h"
 #include "zypp/base/SerialNumber.h"
 #include "zypp/sat/detail/PoolMember.h"
 #include "zypp/RepoInfo.h"
+#include "zypp/Locale.h"
+#include "zypp/IdString.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -51,25 +54,31 @@ namespace zypp
           ~PoolImpl();
 
           /** Pointer style access forwarded to sat-pool. */
-           ::_Pool * operator->()
-           { return _pool; }
+          ::_Pool * operator->()
+          { return _pool; }
 
         public:
           /** Serial number changing whenever the content changes. */
           const SerialNumber & serial() const
           { return _serial; }
 
-
           /** Update housekeeping data (e.g. whatprovides).
            * \todo actually requires a watcher.
-          */
-          void prepare();
+           */
+          void prepare() const;
 
-        public:
-          /** Invalidate housekeeping data (e.g. whatprovides).
-          */
+        private:
+          /** Invalidate housekeeping data (e.g. whatprovides) if the
+           *  pools content changed.
+           */
           void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
 
+          /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
+           */
+          void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
+
+          static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
+
         public:
           /** \name Actions invalidating housekeeping data.
            *
@@ -134,7 +143,7 @@ namespace zypp
         public:
           /** Get id of the first valid \ref Solvable.
            * This is the next valid after the system solvable.
-          */
+           */
           SolvableIdType getFirstId()  const
           { return getNextId( 1 ); }
 
@@ -164,6 +173,42 @@ namespace zypp
           void eraseRepoInfo( RepoIdType id_r )
           { _repoinfos.erase( id_r ); }
 
+        public:
+          /** \name Requested locales. */
+          //@{
+          void setRequestedLocales( const LocaleSet & locales_r );
+          bool addRequestedLocale( const Locale & locale_r );
+          bool eraseRequestedLocale( const Locale & locale_r );
+
+          const LocaleSet & getRequestedLocales() const
+          { return _requestedLocales; }
+
+          bool isRequestedLocale( const Locale & locale_r ) const
+          {
+            LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
+            return it != _requestedLocales.end();
+          }
+
+          const LocaleSet & getAvailableLocales() const
+          {
+            if ( _availableLocales.size() != _localeCollector.size() )
+            {
+              _availableLocales.clear();
+              for_( it, _localeCollector.begin(), _localeCollector.end() )
+                _availableLocales.insert( Locale( *it ) );
+            }
+            return _availableLocales;
+          }
+
+          bool isAvailableLocale( const Locale & locale_r ) const
+          {
+            const LocaleSet & avl( getAvailableLocales() );
+            LocaleSet::const_iterator it( avl.find( locale_r ) );
+            return it != avl.end();
+          }
+
+        //@}
+
         private:
           /** sat-pool. */
           ::_Pool * _pool;
@@ -173,6 +218,12 @@ namespace zypp
           SerialNumberWatcher _watcher;
           /** Additional \ref RepoInfo. */
           std::map<RepoIdType,RepoInfo> _repoinfos;
+
+          /**  */
+          LocaleSet _requestedLocales;
+          mutable LocaleSet _availableLocales;
+          mutable std::tr1::unordered_set<IdString> _localeCollector;
+          mutable std::tr1::unordered_set<IdString> _locale2Solver;
       };
       ///////////////////////////////////////////////////////////////////
 
index ad3aebc..82f4337 100644 (file)
@@ -13,6 +13,8 @@
 #define ZYPP_SAT_DETAIL_POOLMEMBER_H
 
 #include "zypp/base/Iterator.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Easy.h"
 
 extern "C"
 {
@@ -21,6 +23,16 @@ struct _Repo;
 struct _Pool;
 }
 
+#define ZYPP_DEFINE_ID_HASHABLE(C)           \
+namespace std { namespace tr1 {              \
+  template<class _Tp> struct hash;           \
+  template<> struct hash<C>                  \
+  {                                          \
+    size_t operator()( const C & __s ) const \
+    { return __s.id(); }                     \
+  };                                         \
+}}
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
index 36fc5a4..8ddc6fa 100644 (file)
@@ -599,6 +599,10 @@ Resolver::doUpgrade( UpgradeStatistics & opt_stats_r )
        bool requested_locale_match = false;
        Capabilities freshens( guess->dep( Dep::FRESHENS ) );
 
+#warning THIS DOES NO LONGER WORK, CREATE SAT::sOLVABLE::WHATEVERISNEEDED (IN DOUBT ASK MA@)
+// We no longer have any 'locale()' deps in FRESHENS!
+// Providing 'bool sat::Solvable::supportsRequestedLocale()' should simplify this code.
+// Maybe an enum instead of bool ( yes, no and via fallback list )
        // is this a language package ?
        for (Capabilities::const_iterator cit = freshens.begin(); cit != freshens.end(); ++cit) {
            string citName = cit->asString();
@@ -625,8 +629,7 @@ Resolver::doUpgrade( UpgradeStatistics & opt_stats_r )
                    break;
                } else {
                    freshens = item->dep( Dep::FRESHENS );
-                   ZYpp::Ptr z = zypp::getZYpp();
-                   ZYpp::LocaleSet requested_locales = z->getRequestedLocales();
+                   const LocaleSet & requested_locales = sat::Pool::instance().getRequestedLocales();
 
                    // try to find a match of the locale freshens with one of the requested locales
 
index 96afdfd..ee1529d 100644 (file)
@@ -164,113 +164,6 @@ namespace zypp
     }
 
     //------------------------------------------------------------------------
-    // locales
-
-    /** */
-    void ZYppImpl::setRequestedLocales( const LocaleSet & locales_r )
-    {
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-     ResPool mpool( ResPool::instance() );
-      // assert all requested are available
-      for ( LocaleSet::const_iterator it = locales_r.begin();
-            it != locales_r.end(); ++it )
-        {
-          NameKindProxy select( nameKindProxy<Language>( mpool, it->code() ) );
-          if ( select.installedEmpty() && select.availableEmpty() )
-            _pool.insert( Language::availableInstance( *it ) );
-        }
-
-      // now adjust status
-      for ( ResPool::byKind_iterator it = mpool.byKindBegin<Language>();
-            it != mpool.byKindEnd<Language>(); ++it )
-        {
-          NameKindProxy select( nameKindProxy<Language>( mpool, (*it)->name() ) );
-          if ( locales_r.find( Locale( (*it)->name() ) ) != locales_r.end() )
-            {
-              // Language is requested
-              if ( select.installedEmpty() )
-                {
-                  if ( select.availableEmpty() )
-                    {
-                      // no item ==> provide available to install
-                      _pool.insert( Language::availableInstance( Locale((*it)->name()) ) );
-                      select = nameKindProxy<Language>( mpool, (*it)->name() );
-                    }
-                  // available only ==> to install
-                  select.availableBegin()->status().setTransactValue( ResStatus::TRANSACT, ResStatus::USER );
-                }
-              else
-                {
-                  // installed ==> keep it
-                  select.installedBegin()->status().setTransactValue( ResStatus::KEEP_STATE, ResStatus::USER );
-                  if ( ! select.availableEmpty() )
-                    {
-                      // both items ==> keep
-                      select.availableBegin()->status().resetTransact( ResStatus::USER );
-                    }
-                }
-            }
-          else
-            {
-              // Language is NOT requested
-              if ( ! select.installedEmpty() )
-                select.installedBegin()->status().setTransactValue( ResStatus::TRANSACT, ResStatus::USER );
-              if ( ! select.availableEmpty() )
-                select.availableBegin()->status().resetTransact( ResStatus::USER );
-            }
-        }
-#endif
-    }
-
-    /** */
-    ZYppImpl::LocaleSet ZYppImpl::getAvailableLocales() const
-    {
-      ZYpp::LocaleSet ret;
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-      ResPool mpool( ResPool::instance() );
-      for ( ResPool::byKind_iterator it = mpool.byKindBegin<Language>();
-            it != mpool.byKindEnd<Language>(); ++it )
-        {
-          if ( (*it).status().isUninstalled() ) // available!
-            ret.insert( Locale( (*it)->name() ) );
-        }
-#endif
-      return ret;
-    }
-
-    /** */
-    ZYppImpl::LocaleSet ZYppImpl::getRequestedLocales() const
-    {
-      ZYpp::LocaleSet ret;
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-     ResPool mpool( ResPool::instance() );
-      for ( ResPool::byKind_iterator it = mpool.byKindBegin<Language>();
-            it != mpool.byKindEnd<Language>(); ++it )
-        {
-          NameKindProxy select( nameKindProxy<Language>( mpool, (*it)->name() ) );
-          if ( ! select.installedEmpty()
-               && select.installedBegin()->status().getTransactValue() != ResStatus::TRANSACT )
-            ret.insert( Locale( (*it)->name() ) );
-          else if ( ! select.availableEmpty()
-                    && select.availableBegin()->status().getTransactValue() == ResStatus::TRANSACT )
-            ret.insert( Locale( (*it)->name() ) );
-        }
-#endif
-      return ret;
-    }
-
-    void ZYppImpl::availableLocale( const Locale & locale_r )
-    {
-#warning REIMPLEMENT WITHOUT LANGUAGE RESOLVABLE
-#if 0
-      _pool.insert( Language::availableInstance( locale_r ) );
-#endif
-    }
-
-    //------------------------------------------------------------------------
     // target store path
 
     Pathname ZYppImpl::homePath() const
@@ -287,6 +180,7 @@ namespace zypp
 
     int ZYppImpl::applyLocks()
     {
+#warning make the /etc/zypp/locks path an option zconfig.
       Pathname locksrcPath( "/etc/zypp/locks" );
       try
       {
index d749223..452d364 100644 (file)
@@ -17,7 +17,6 @@
 #include "zypp/TmpPath.h"
 #include "zypp/Target.h"
 #include "zypp/Resolver.h"
-#include "zypp/Locale.h"
 #include "zypp/KeyRing.h"
 #include "zypp/ZYppCommit.h"
 #include "zypp/ResTraits.h"
@@ -88,18 +87,6 @@ namespace zypp
       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
 
     public:
-      typedef std::set<Locale> LocaleSet;
-      /** */
-      void setRequestedLocales( const LocaleSet & locales_r );
-      /** */
-      LocaleSet getRequestedLocales() const;
-      /** */
-      LocaleSet getAvailableLocales() const;
-
-      /** internal use */
-      void availableLocale( const Locale & locale_r );
-
-    public:
       /** Get the path where zypp related plugins store persistent data and caches   */
       Pathname homePath() const;