From 698902b53805a436fbdeb6021f7bc0e02a73e91d Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Thu, 14 Feb 2008 23:13:41 +0000 Subject: [PATCH] add basic locale interface to ResPool, remove deprecated _gxx hashes --- zypp/@DOXYGEN/g_CodeSnippets | 24 +++ zypp/@DOXYGEN/n_ResPool_nomorenameiter | 71 +++++++ zypp/Arch.cc | 1 + zypp/CMakeLists.txt | 2 - zypp/Capability.h | 9 +- zypp/IdString.h | 3 + zypp/Locale.cc | 22 ++- zypp/Locale.h | 25 ++- zypp/PackageKeyword.h | 27 ++- zypp/ResPool.cc | 26 +++ zypp/ResPool.h | 99 ++++++---- zypp/ZYpp.cc | 13 +- zypp/ZYpp.h | 19 +- zypp/base/Hash.h | 46 ----- zypp/base/LogTools.h | 18 +- zypp/base/UniqueString.h | 252 ------------------------- zypp/pool/PoolImpl.h | 65 +++---- zypp/pool/PoolTraits.h | 37 ++-- zypp/sat/Pool.cc | 26 ++- zypp/sat/Pool.h | 42 ++++- zypp/sat/detail/PoolImpl.cc | 85 ++++++++- zypp/sat/detail/PoolImpl.h | 69 ++++++- zypp/sat/detail/PoolMember.h | 12 ++ zypp/solver/detail/ResolverUpgrade.cc | 7 +- zypp/zypp_detail/ZYppImpl.cc | 108 +---------- zypp/zypp_detail/ZYppImpl.h | 13 -- 26 files changed, 547 insertions(+), 574 deletions(-) create mode 100644 zypp/@DOXYGEN/n_ResPool_nomorenameiter delete mode 100644 zypp/base/Hash.h delete mode 100644 zypp/base/UniqueString.h diff --git a/zypp/@DOXYGEN/g_CodeSnippets b/zypp/@DOXYGEN/g_CodeSnippets index 0ce7789d4..9775c39f9 100644 --- a/zypp/@DOXYGEN/g_CodeSnippets +++ b/zypp/@DOXYGEN/g_CodeSnippets @@ -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 index 000000000..2be14057e --- /dev/null +++ b/zypp/@DOXYGEN/n_ResPool_nomorenameiter @@ -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( 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; + } + diff --git a/zypp/Arch.cc b/zypp/Arch.cc index 6d84242dc..979eebeda 100644 --- a/zypp/Arch.cc +++ b/zypp/Arch.cc @@ -238,6 +238,7 @@ namespace zypp defCompatibleWith( _ppc, _ppc64 ); // /////////////////////////////////////////////////////////////////// + dumpOn( USR ) << endl; } private: diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index fe273b980..9de19c16e 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -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 ) diff --git a/zypp/Capability.h b/zypp/Capability.h index b0751b3c6..36bdc9072 100644 --- a/zypp/Capability.h +++ b/zypp/Capability.h @@ -13,7 +13,7 @@ #define ZYPP_SAT_CAPABILITY_H #include -#include +#include #include "zypp/base/SafeBool.h" #include "zypp/base/Deprecated.h" @@ -34,7 +34,7 @@ namespace zypp class Capability; class CapDetail; - typedef std::set CapabilitySet; + typedef std::tr1::unordered_set CapabilitySet; /////////////////////////////////////////////////////////////////// // @@ -54,7 +54,7 @@ namespace zypp * \endcode */ class Capability: protected sat::detail::PoolMember, - private base::SafeBool + private base::SafeBool { public: // legacy @@ -302,4 +302,7 @@ namespace zypp ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// + +ZYPP_DEFINE_ID_HASHABLE( ::zypp::Capability ) + #endif // ZYPP_SAT_CAPABILITY_H diff --git a/zypp/IdString.h b/zypp/IdString.h index 92f8f71cb..ac82cc6c3 100644 --- a/zypp/IdString.h +++ b/zypp/IdString.h @@ -208,4 +208,7 @@ namespace zypp ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// + +ZYPP_DEFINE_ID_HASHABLE( ::zypp::IdString ) + #endif // ZYPP_SAT_IDSTR_H diff --git a/zypp/Locale.cc b/zypp/Locale.cc index 10429af88..e9927bf3a 100644 --- a/zypp/Locale.cc +++ b/zypp/Locale.cc @@ -22,7 +22,7 @@ namespace zypp typedef std::map 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; @@ -137,6 +137,15 @@ namespace zypp : _pimpl( Impl::nullimpl() ) {} + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : Locale::Locale + // METHOD TYPE : Ctor + // + Locale::Locale( IdString code_r ) + : _pimpl( new Impl( code_r.asString() ) ) + {} + /////////////////////////////////////////////////////////////////// // // METHOD NAME : Locale::Locale @@ -146,6 +155,15 @@ namespace zypp : _pimpl( new Impl( code_r ) ) {} + /////////////////////////////////////////////////////////////////// + // + // 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 diff --git a/zypp/Locale.h b/zypp/Locale.h index 185955140..454007744 100644 --- a/zypp/Locale.h +++ b/zypp/Locale.h @@ -13,9 +13,11 @@ #define ZYPP_LOCALE_H #include +#include #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 ); @@ -41,9 +45,15 @@ namespace zypp Locale(); /** 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 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()(__s.code()); } + }; +}} + /////////////////////////////////////////////////////////////////// namespace std { ///////////////////////////////////////////////////////////////// diff --git a/zypp/PackageKeyword.h b/zypp/PackageKeyword.h index 688ef589a..2c60e7815 100644 --- a/zypp/PackageKeyword.h +++ b/zypp/PackageKeyword.h @@ -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 + /** Package keywords. + * \see \ref IdStringType + */ + class PackageKeyword : public IdStringType { - PackageKeyword() - {} + public: + /** Default ctor: empty keyword */ + PackageKeyword() {} - PackageKeyword( const std::string & name_r ) - : base::UniqueString( 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; + IdString _str; + }; /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// diff --git a/zypp/ResPool.cc b/zypp/ResPool.cc index dd2bd3091..6fba802d7 100644 --- a/zypp/ResPool.cc +++ b/zypp/ResPool.cc @@ -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<< diff --git a/zypp/ResPool.h b/zypp/ResPool.h index 864e7f0e8..36cf562b2 100644 --- a/zypp/ResPool.h +++ b/zypp/ResPool.h @@ -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, 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 it2 - = id2item().equal_range(id); - return make_transform_iterator(it2.first, std::_Select2nd()); - } - - byIdent_iterator byIdentEnd( sat::detail::IdType id ) const - { - std::pair it2 - = id2item().equal_range(id); - return make_transform_iterator(it2.second, std::_Select2nd()); + 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 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 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 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 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. diff --git a/zypp/ZYpp.cc b/zypp/ZYpp.cc index 5cd46395c..4d2d0bfef 100644 --- a/zypp/ZYpp.cc +++ b/zypp/ZYpp.cc @@ -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(); } diff --git a/zypp/ZYpp.h b/zypp/ZYpp.h index 8a5ee36b2..88381c673 100644 --- a/zypp/ZYpp.h +++ b/zypp/ZYpp.h @@ -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 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 index dbd7e02a6..000000000 --- a/zypp/base/Hash.h +++ /dev/null @@ -1,46 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/base/Hash.h - * -*/ -#ifndef ZYPP_BASE_HASH_H -#define ZYPP_BASE_HASH_H - -#include - -#include -#include - -/////////////////////////////////////////////////////////////////// -namespace __gnu_cxx -{ ///////////////////////////////////////////////////////////////// - - /** Specialize hash function for std::string. */ - template<> - struct hash - { - 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 diff --git a/zypp/base/LogTools.h b/zypp/base/LogTools.h index dd1bed2d1..5ca601df5 100644 --- a/zypp/base/LogTools.h +++ b/zypp/base/LogTools.h @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "zypp/base/Logger.h" #include "zypp/base/Iterator.h" #include "zypp/base/Deprecated.h" @@ -120,6 +122,10 @@ namespace zypp std::ostream & operator<<( std::ostream & str, const std::set<_Tp> & obj ) { return dumpRange( str, obj.begin(), obj.end() ); } + template + std::ostream & operator<<( std::ostream & str, const std::tr1::unordered_set<_Tp> & obj ) + { return dumpRange( str, obj.begin(), obj.end() ); } + template 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 + 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 index b9c2ac577..000000000 --- a/zypp/base/UniqueString.h +++ /dev/null @@ -1,252 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/base/UniqueString.h - * -*/ -#ifndef ZYPP_BASE_UNIQUESTRING_H -#define ZYPP_BASE_UNIQUESTRING_H - -#include -#include - -#include - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace base - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : UniqueString - // - /** Immutable strings with unique representation in memory. - * - * Each UniqueString provides a const std::string. - * 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( const std::string & name_r ) - * :base::UniqueString( 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 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 str().size(). */ - std::string::size_type size() const - { return asString().size(); } - - /** Short for str().empty(). */ - bool empty() const - { return asString().empty(); } - - /** Short for str().compare( s ).*/ - int compare( const std::string & rhs ) const - { return asString().compare( rhs ); } - - public: - typedef hash_set::size_type size_type; - typedef hash_set::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 & hash() - { - static hash_set _value; - return _value; - } - - private: - /** Immutable string. */ - std::string _name; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates UniqueString operator == */ - template - inline bool operator==( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs.str() == rhs.str() ); } - /** \relates UniqueString operator == */ - template - inline bool operator==( const UniqueString<_Derived> & lhs, const std::string & rhs ) - { return ( lhs.str() == rhs ); } - /** \relates UniqueString operator == */ - template - inline bool operator==( const std::string & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs == rhs.str() ); } - - - /** \relates UniqueString operator != */ - template - inline bool operator!=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs.str() != rhs.str() ); } - /** \relates UniqueString operator != */ - template - inline bool operator!=( const UniqueString<_Derived> & lhs, const std::string & rhs ) - { return ( lhs.str() != rhs ); } - /** \relates UniqueString operator != */ - template - inline bool operator!=( const std::string & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs != rhs.str() ); } - - - /** \relates UniqueString operator < */ - template - inline bool operator<( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs.str() < rhs.str() ); } - /** \relates UniqueString operator < */ - template - inline bool operator<( const UniqueString<_Derived> & lhs, const std::string & rhs ) - { return ( lhs.str() < rhs ); } - /** \relates UniqueString operator < */ - template - inline bool operator<( const std::string & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs < rhs.str() ); } - - - /** \relates UniqueString operator > */ - template - inline bool operator>( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs.str() > rhs.str() ); } - /** \relates UniqueString operator > */ - template - inline bool operator>( const UniqueString<_Derived> & lhs, const std::string & rhs ) - { return ( lhs.str() > rhs ); } - /** \relates UniqueString operator > */ - template - inline bool operator>( const std::string & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs > rhs.str() ); } - - - /** \relates UniqueString operator <= */ - template - inline bool operator<=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs.str() <= rhs.str() ); } - /** \relates UniqueString operator <= */ - template - inline bool operator<=( const UniqueString<_Derived> & lhs, const std::string & rhs ) - { return ( lhs.str() <= rhs ); } - /** \relates UniqueString operator <= */ - template - inline bool operator<=( const std::string & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs <= rhs.str() ); } - - - /** \relates UniqueString operator >= */ - template - inline bool operator>=( const UniqueString<_Derived> & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs.str() >= rhs.str() ); } - /** \relates UniqueString operator >= */ - template - inline bool operator>=( const UniqueString<_Derived> & lhs, const std::string & rhs ) - { return ( lhs.str() >= rhs ); } - /** \relates UniqueString operator >= */ - template - inline bool operator>=( const std::string & lhs, const UniqueString<_Derived> & rhs ) - { return ( lhs >= rhs.str() ); } - - /** \relates UniqueString Stream output */ - template - inline std::ostream & operator<<( std::ostream & str, const UniqueString<_Derived> & obj ) - { return str << obj.str(); } - - ///////////////////////////////////////////////////////////////// - } // namespace base - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp -/////////////////////////////////////////////////////////////////// -#endif // ZYPP_BASE_UNIQUESTRING_H diff --git a/zypp/pool/PoolImpl.h b/zypp/pool/PoolImpl.h index 10e6635a8..bb5d7edac 100644 --- a/zypp/pool/PoolImpl.h +++ b/zypp/pool/PoolImpl.h @@ -13,9 +13,9 @@ #define ZYPP_POOL_POOLIMPL_H #include -#include #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 diff --git a/zypp/pool/PoolTraits.h b/zypp/pool/PoolTraits.h index b399879e1..e44c6f2c3 100644 --- a/zypp/pool/PoolTraits.h +++ b/zypp/pool/PoolTraits.h @@ -14,8 +14,11 @@ #include #include +#include +#include #include +#include "zypp/base/Iterator.h" #include "zypp/base/Iterator.h" #include "zypp/PoolItem.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 ItemContainerT; - typedef MapKVIteratorTraits::Value_const_iterator - const_iterator; -#endif typedef std::vector ItemContainerT; typedef ItemContainerT::const_iterator item_iterator; typedef filter_iterator const_iterator; typedef ItemContainerT::size_type size_type; - typedef std::tr1::unordered_multimap Id2ItemT; + + /** ident index */ + typedef std::tr1::unordered_multimap + Id2ItemT; + typedef std::_Select2nd Id2ItemValueSelector; + typedef transform_iterator + byIdent_iterator; + + + /* list of known Repositories */ + typedef std::list RepoContainerT; + typedef RepoContainerT::const_iterator repository_iterator; + + // internal organization typedef std::list 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 RepoContainerT; - typedef RepoContainerT::const_iterator repository_iterator; typedef PoolImpl Impl; typedef shared_ptr Impl_Ptr; diff --git a/zypp/sat/Pool.cc b/zypp/sat/Pool.cc index f2903ed07..baf8f5b3b 100644 --- a/zypp/sat/Pool.cc +++ b/zypp/sat/Pool.cc @@ -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 & diff --git a/zypp/sat/Pool.h b/zypp/sat/Pool.h index e68eaaa49..eb15f1fdd 100644 --- a/zypp/sat/Pool.h +++ b/zypp/sat/Pool.h @@ -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. */ @@ -102,8 +103,6 @@ namespace zypp Repo systemRepo() { 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. @@ -131,6 +130,43 @@ namespace zypp /** Iterator behind the last \ref Solvable. */ 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; diff --git a/zypp/sat/detail/PoolImpl.cc b/zypp/sat/detail/PoolImpl.cc index c8a470416..7d2ca3def 100644 --- a/zypp/sat/detail/PoolImpl.cc +++ b/zypp/sat/detail/PoolImpl.cc @@ -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 & locale2Solver( reinterpret_cast(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 & locale2Solver ) + { + std::tr1::unordered_set( 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 diff --git a/zypp/sat/detail/PoolImpl.h b/zypp/sat/detail/PoolImpl.h index f870c3c2a..03cd829f1 100644 --- a/zypp/sat/detail/PoolImpl.h +++ b/zypp/sat/detail/PoolImpl.h @@ -20,11 +20,14 @@ extern "C" #include } #include +#include #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 _repoinfos; + + /** */ + LocaleSet _requestedLocales; + mutable LocaleSet _availableLocales; + mutable std::tr1::unordered_set _localeCollector; + mutable std::tr1::unordered_set _locale2Solver; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/sat/detail/PoolMember.h b/zypp/sat/detail/PoolMember.h index ad3aebce0..82f4337fe 100644 --- a/zypp/sat/detail/PoolMember.h +++ b/zypp/sat/detail/PoolMember.h @@ -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 struct hash; \ + template<> struct hash \ + { \ + size_t operator()( const C & __s ) const \ + { return __s.id(); } \ + }; \ +}} + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// diff --git a/zypp/solver/detail/ResolverUpgrade.cc b/zypp/solver/detail/ResolverUpgrade.cc index 36fc5a415..8ddc6fa9f 100644 --- a/zypp/solver/detail/ResolverUpgrade.cc +++ b/zypp/solver/detail/ResolverUpgrade.cc @@ -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 diff --git a/zypp/zypp_detail/ZYppImpl.cc b/zypp/zypp_detail/ZYppImpl.cc index 96afdfdd3..ee1529d7f 100644 --- a/zypp/zypp_detail/ZYppImpl.cc +++ b/zypp/zypp_detail/ZYppImpl.cc @@ -163,113 +163,6 @@ namespace zypp _target->_pimpl->installSrcPackage( srcPackage_r ); } - //------------------------------------------------------------------------ - // 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( mpool, it->code() ) ); - if ( select.installedEmpty() && select.availableEmpty() ) - _pool.insert( Language::availableInstance( *it ) ); - } - - // now adjust status - for ( ResPool::byKind_iterator it = mpool.byKindBegin(); - it != mpool.byKindEnd(); ++it ) - { - NameKindProxy select( nameKindProxy( 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( 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(); - it != mpool.byKindEnd(); ++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(); - it != mpool.byKindEnd(); ++it ) - { - NameKindProxy select( nameKindProxy( 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 @@ -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 { diff --git a/zypp/zypp_detail/ZYppImpl.h b/zypp/zypp_detail/ZYppImpl.h index d749223b4..452d364d1 100644 --- a/zypp/zypp_detail/ZYppImpl.h +++ b/zypp/zypp_detail/ZYppImpl.h @@ -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" @@ -87,18 +86,6 @@ namespace zypp /** Install a source package on the Target. */ void installSrcPackage( const SrcPackage_constPtr & srcPackage_r ); - public: - typedef std::set 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; -- 2.34.1