*
*/
#include <iostream>
-//#include "zypp/base/Logger.h"
+#include "zypp/base/Easy.h"
#include "zypp/NameKindProxy.h"
using std::endl;
// METHOD NAME : NameKindProxy::NameKindProxy
// METHOD TYPE : Ctor
//
- NameKindProxy::NameKindProxy( ResPool pool_r, const std::string & name_r, Resolvable::Kind kind_r )
+ NameKindProxy::NameKindProxy( ResPool pool_r, const C_Str & name_r, Resolvable::Kind kind_r )
: _kind( kind_r )
, _name( name_r )
{
- for ( ResPool::byName_iterator it = pool_r.byNameBegin( _name );
- it != pool_r.byNameEnd( _name ); ++it )
- {
- if ( (*it)->kind() == _kind )
- {
- if ( it->status().isInstalled() )
- _installed.insert( *it ) ;
- else
- _available.insert( *it );
- }
- }
+ for_( it, pool_r.byIdentBegin( kind_r, _name ), pool_r.byIdentEnd( kind_r, _name ) )
+ {
+ if ( it->status().isInstalled() )
+ _installed.insert( *it ) ;
+ else
+ _available.insert( *it );
+ }
+ }
+
+ NameKindProxy::NameKindProxy( ResPool pool_r, IdString name_r, Resolvable::Kind kind_r )
+ : _kind( kind_r )
+ , _name( name_r )
+ {
+ for_( it, pool_r.byIdentBegin( kind_r, _name ), pool_r.byIdentEnd( kind_r, _name ) )
+ {
+ if ( it->status().isInstalled() )
+ _installed.insert( *it ) ;
+ else
+ _available.insert( *it );
+ }
}
/******************************************************************
typedef AvailableSet::size_type Available_size_type;
public:
- NameKindProxy( ResPool pool_r,
- const std::string & name_r, Resolvable::Kind kind_r );
+ NameKindProxy( ResPool pool_r, IdString name_r, ResKind kind_r );
+ NameKindProxy( ResPool pool_r, const C_Str & name_r, ResKind kind_r );
public:
- ResObject::Kind kind() const
+ ResKind kind() const
{ return _kind; }
- const std::string & name() const
+ IdString name() const
{ return _name; }
public:
// status query and manip stuff...
private:
- ResObject::Kind _kind;
- std::string _name;
- InstalledSet _installed;
- AvailableSet _available;
+ ResKind _kind;
+ IdString _name;
+ InstalledSet _installed;
+ AvailableSet _available;
};
///////////////////////////////////////////////////////////////////
/** \relates NameKindProxy Convenience construction. */
template<class _Res>
- inline NameKindProxy nameKindProxy( ResPool pool_r, const std::string & name_r )
+ inline NameKindProxy nameKindProxy( ResPool pool_r, IdString name_r )
+ { return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
+ template<class _Res>
+ inline NameKindProxy nameKindProxy( ResPool pool_r, const C_Str & name_r )
{ return NameKindProxy( pool_r, name_r, ResTraits<_Res>::kind ); }
/////////////////////////////////////////////////////////////////
*/
std::ostream & operator<<( std::ostream & str, const ResPool & obj )
{
- dumpPoolStats( str << "ResPool " << sat::Pool::instance() << endl << " ",
- obj.begin(), obj.end() );
+ return dumpPoolStats( str << "ResPool " << sat::Pool::instance() << endl << " ",
+ obj.begin(), obj.end() );
}
/////////////////////////////////////////////////////////////////
byIdent_iterator byIdentBegin( const C_Str & name_r ) const
{ return make_filter_begin( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
+ /** Derive name and kind from \ref PoolItem. */
+ byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
+ { return make_filter_begin( ByIdent(pi_r.satSolvable()), *this ); }
+ /** Derive name and kind from \ref sat::Solvable. */
+ byIdent_iterator byIdentBegin( sat::Solvable slv_r ) const
+ { return make_filter_begin( ByIdent(slv_r), *this ); }
+
byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
{ return make_filter_end( ByIdent(kind_r,name_r), *this ); }
template<class _Res>
byIdent_iterator byIdentEnd( const C_Str & name_r ) const
{ return make_filter_end( ByIdent(ResTraits<_Res>::kind,name_r), *this ); }
- //@}
+
+ /** Derive name and kind from \ref PoolItem. */
+ byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
+ { return make_filter_begin( ByIdent(pi_r.satSolvable()), *this ); }
+ /** Derive name and kind from \ref sat::Solvable. */
+ byIdent_iterator byIdentEnd( sat::Solvable slv_r ) const
+ { return make_filter_begin( ByIdent(slv_r), *this ); }
+ //@}
public:
/** \name Iterate through all ResObjects of a certain kind. */
//@}
public:
- /** \name Iterate through all ResObjects with a certain name (all kinds). */
+ /** \name Iterate through all ResObjects with a certain name (all kinds).
+ * \deprecated Instead of iterating byName and filter byKind use ByIdent iterator.
+ */
//@{
typedef zypp::resfilter::ByName ByName;
typedef filter_iterator<ByName,const_iterator> byName_iterator;
- byName_iterator byNameBegin( const std::string & name_r ) const
+ byName_iterator ZYPP_DEPRECATED byNameBegin( const std::string & name_r ) const
{ return make_filter_begin( ByName(name_r), *this ); }
- byName_iterator byNameEnd( const std::string & name_r ) const
+ byName_iterator ZYPP_DEPRECATED byNameEnd( const std::string & name_r ) const
{ return make_filter_end( ByName(name_r), *this ); }
//@}
* }
* \endcode
*/
-#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
+#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG, _ZZ = END; IT != _ZZ; ++IT )
///////////////////////////////////////////////////////////////////
namespace zypp
class ByIdent //: public ResObjectFilterFunctor
{
public:
+ ByIdent( sat::Solvable slv_r )
+ : _id( makeIdent( slv_r ) )
+ {}
+
ByIdent( ResKind kind_r, IdString name_r )
: _id( makeIdent( kind_r, name_r ) )
{}
{ return p_r ? operator()( p_r->satSolvable() ) : !_id; }
private:
+ sat::detail::IdType makeIdent( sat::Solvable slv_r )
+ {
+ return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
+ : slv_r.ident().id();
+ }
+
sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
{
if ( kind_r == ResKind::package )
{
LookFor info;
- invokeOnEach( pool.byNameBegin( name ),
- pool.byNameEnd( name ),
- functor::chain (resfilter::ByInstalled (), // ByInstalled
- resfilter::ByKind( kind ) ), // equal kind
+ invokeOnEach( pool.byIdentBegin( kind, name ),
+ pool.byIdentEnd( kind, name ),
+ resfilter::ByInstalled (), // ByInstalled
functor::functorRef<bool,PoolItem> (info) );
_XDEBUG("Helper::findInstalledByNameAndKind (" << name << ", " << kind << ") => " << info.item);
{
LookFor info;
- invokeOnEach( pool.byNameBegin( name ),
- pool.byNameEnd( name ),
- functor::chain (resfilter::ByUninstalled (), // ByUninstalled
- resfilter::ByKind( kind ) ), // equal kind
+ invokeOnEach( pool.byIdentBegin( kind, name ),
+ pool.byIdentEnd( kind, name ),
+ resfilter::ByUninstalled(), // ByUninstalled
functor::functorRef<bool,PoolItem> (info) );
_XDEBUG("Helper::findUninstalledByNameAndKind (" << name << ", " << kind << ") => " << info.item);
return true;
}
}
-
+
if ((!uninstalled // none yet
|| (uninstalled->edition().compare( provider->edition() ) < 0) // or a better edition
|| (uninstalled->arch().compare( provider->arch() ) < 0) ) // or a better architecture
&& !provider.status().isLocked() ) // is not locked
{
- uninstalled = provider; // store
+ uninstalled = provider; // store
}
return true;
}
LookForUpdate info;
info.installed = item;
- invokeOnEach( pool.byNameBegin( item->name() ),
- pool.byNameEnd( item->name() ),
- functor::chain (functor::chain (resfilter::ByUninstalled (), // ByUninstalled
- resfilter::ByKind( item->kind() ) ), // equal kind
+ invokeOnEach( pool.byIdentBegin( item ),
+ pool.byIdentEnd( item ),
+ functor::chain (resfilter::ByUninstalled (), // ByUninstalled
resfilter::byEdition<CompareByGT<Edition> >( item->edition() )), // only look at better editions
functor::functorRef<bool,PoolItem> (info) );
{
LookForReinstall info;
- invokeOnEach( pool.byNameBegin( item->name() ),
- pool.byNameEnd( item->name() ),
- functor::chain (functor::chain (resfilter::ByUninstalled (), // ByUninstalled
- resfilter::ByKind( item->kind() ) ), // equal kind
+ invokeOnEach( pool.byIdentBegin( item ),
+ pool.byIdentEnd( item ),
+ functor::chain (resfilter::ByUninstalled (), // ByUninstalled
resfilter::byEdition<CompareByEQ<Edition> >( item->edition() )),
functor::functorRef<bool,PoolItem> (info) );
{
CheckIfBest info( item );
- invokeOnEach( pool.byNameBegin( item->name() ),
- pool.byNameEnd( item->name() ),
- functor::chain( resfilter::ByUninstalled(), // ByUninstalled
- resfilter::ByKind( item->kind() ) ), // equal kind
+ invokeOnEach( pool.byIdentBegin( item ),
+ pool.byIdentEnd( item ),
+ resfilter::ByUninstalled(), // ByUninstalled
functor::functorRef<bool,PoolItem>( info ) );
_XDEBUG("Helper::isBestUninstalledItem(" << item << ") => " << info.is_best);