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 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////
40 /** Pool internal filter skiping invalid/unwanted PoolItems. */
43 bool operator()( const PoolItem & pi ) const
47 /** Main filter selecting PoolItems by \c name and \c kind.
57 explicit ByIdent( sat::Solvable slv_r )
58 : _id( makeIdent( slv_r ) )
61 explicit ByIdent( IdString ident_r )
65 ByIdent( ResKind kind_r, IdString name_r )
66 : _id( makeIdent( kind_r, name_r ) )
69 ByIdent( ResKind kind_r, const C_Str & name_r )
70 : _id( makeIdent( kind_r, name_r ) )
74 bool operator()( sat::Solvable slv_r ) const
76 return _id >= 0 ? ( slv_r.ident().id() == _id && ! slv_r.isKind( ResKind::srcpackage ) )
77 : ( slv_r.ident().id() == -_id && slv_r.isKind( ResKind::srcpackage ) );
80 bool operator()( const PoolItem & pi_r ) const
81 { return operator()( pi_r.satSolvable() ); }
83 bool operator()( ResObject::constPtr p_r ) const
84 { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
87 sat::detail::IdType makeIdent( sat::Solvable slv_r )
89 return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
93 sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
95 if ( kind_r == ResKind::package )
97 else if ( kind_r == ResKind::srcpackage )
99 return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
102 sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
104 if ( kind_r == ResKind::package )
105 return IdString( name_r ).id();
106 else if ( kind_r == ResKind::srcpackage )
107 return -(IdString( name_r ).id());
108 return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
112 sat::detail::IdType get() const { return _id; }
115 /** negative \c _id for \c srcpackage, as they use the same \c ident
118 sat::detail::IdType _id;
121 ///////////////////////////////////////////////////////////////////
123 // CLASS NAME : PoolTraits
129 typedef sat::detail::SolvableIdType SolvableIdType;
132 typedef std::vector<PoolItem> ItemContainerT;
133 typedef ItemContainerT::const_iterator item_iterator;
134 typedef filter_iterator<ByPoolItem,ItemContainerT::const_iterator>
136 typedef ItemContainerT::size_type size_type;
139 typedef std::tr1::unordered_multimap<sat::detail::IdType, PoolItem>
141 typedef std::_Select2nd<Id2ItemT::value_type> Id2ItemValueSelector;
142 typedef transform_iterator<Id2ItemValueSelector, Id2ItemT::const_iterator>
146 /* list of known Repositories */
147 typedef std::list<Repository> RepoContainerT;
148 typedef RepoContainerT::const_iterator repository_iterator;
152 // internal organization
153 typedef std::list<zypp::CapAndItem> CapItemContainerT; // (why,who) pairs
154 typedef std::map<std::string,CapItemContainerT> CapItemStoreT; // capability.index -> (why,who) pairs
155 typedef std::map<Dep,CapItemStoreT> DepCapItemContainerT; // Dep -> (capability.index -> (why,who) pairs)
157 typedef CapItemContainerT::iterator capitemiterator;
158 typedef CapItemContainerT::const_iterator const_capitemiterator;
159 typedef CapItemContainerT::size_type capitemsize_type;
160 /** hashed by capability index */
161 typedef const_capitemiterator byCapabilityIndex_iterator;
164 typedef PoolImpl Impl;
165 typedef shared_ptr<PoolImpl> Impl_Ptr;
166 typedef shared_ptr<const PoolImpl> Impl_constPtr;
168 /** Map of Capabilities and "who" has set it*/
169 typedef std::map<ResStatus::TransactByValue,Capabilities> AdditionalCapabilities;
172 ///////////////////////////////////////////////////////////////////
174 /////////////////////////////////////////////////////////////////
176 ///////////////////////////////////////////////////////////////////
177 /////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////////////////
180 #endif // ZYPP_POOL_POOLTRAITS_H