1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/pool/PoolTraits.h
12 #ifndef ZYPP_POOL_POOLTRAITS_H
13 #define ZYPP_POOL_POOLTRAITS_H
19 #include <tr1/unordered_map>
21 #include "zypp/base/Iterator.h"
22 #include "zypp/base/Iterator.h"
24 #include "zypp/PoolItem.h"
25 #include "zypp/sat/Pool.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////
33 { /////////////////////////////////////////////////////////////////
37 /** Pool internal filter skiping invalid/unwanted PoolItems. */
40 bool operator()( const PoolItem & pi ) const
44 /** Main filter selecting PoolItems by \c name and \c kind.
54 explicit ByIdent( sat::Solvable slv_r )
55 : _id( makeIdent( slv_r ) )
58 explicit ByIdent( IdString ident_r )
62 ByIdent( ResKind kind_r, IdString name_r )
63 : _id( makeIdent( kind_r, name_r ) )
66 ByIdent( ResKind kind_r, const C_Str & name_r )
67 : _id( makeIdent( kind_r, name_r ) )
71 bool operator()( sat::Solvable slv_r ) const
73 return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
74 : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
77 bool operator()( const PoolItem & pi_r ) const
78 { return operator()( pi_r.satSolvable() ); }
80 bool operator()( ResObject::constPtr p_r ) const
81 { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
84 sat::detail::IdType makeIdent( sat::Solvable slv_r )
86 return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
90 sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
92 if ( kind_r == ResKind::package )
94 else if ( kind_r == ResKind::srcpackage )
96 return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
99 sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
101 if ( kind_r == ResKind::package )
102 return IdString( name_r ).id();
103 else if ( kind_r == ResKind::srcpackage )
104 return -(IdString( name_r ).id());
105 return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
109 sat::detail::IdType get() const { return _id; }
112 /** negative \c _id for \c srcpackage, as they use the same \c ident
115 sat::detail::IdType _id;
118 ///////////////////////////////////////////////////////////////////
120 // CLASS NAME : PoolTraits
126 typedef sat::detail::SolvableIdType SolvableIdType;
129 typedef std::vector<PoolItem> ItemContainerT;
130 typedef ItemContainerT::const_iterator item_iterator;
131 typedef filter_iterator<ByPoolItem,ItemContainerT::const_iterator>
133 typedef ItemContainerT::size_type size_type;
136 typedef std::tr1::unordered_multimap<sat::detail::IdType, PoolItem>
138 typedef std::_Select2nd<Id2ItemT::value_type> Id2ItemValueSelector;
139 typedef transform_iterator<Id2ItemValueSelector, Id2ItemT::const_iterator>
142 /* list of known Repositories */
143 typedef std::list<Repository> RepoContainerT;
144 typedef RepoContainerT::const_iterator repository_iterator;
146 typedef PoolImpl Impl;
147 typedef shared_ptr<PoolImpl> Impl_Ptr;
148 typedef shared_ptr<const PoolImpl> Impl_constPtr;
150 /** Map of Capabilities and "who" has set it*/
151 typedef std::map<ResStatus::TransactByValue,Capabilities> AdditionalCapabilities;
154 ///////////////////////////////////////////////////////////////////
156 /////////////////////////////////////////////////////////////////
158 ///////////////////////////////////////////////////////////////////
159 /////////////////////////////////////////////////////////////////
161 ///////////////////////////////////////////////////////////////////
162 #endif // ZYPP_POOL_POOLTRAITS_H