remove obsolete capability handling stuff
[platform/upstream/libzypp.git] / zypp / pool / PoolTraits.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/pool/PoolTraits.h
10  *
11 */
12 #ifndef ZYPP_POOL_POOLTRAITS_H
13 #define ZYPP_POOL_POOLTRAITS_H
14
15 #include <set>
16 #include <map>
17 #include <list>
18 #include <vector>
19 #include <tr1/unordered_map>
20
21 #include "zypp/base/Iterator.h"
22 #include "zypp/base/Iterator.h"
23
24 #include "zypp/PoolItem.h"
25 #include "zypp/sat/Pool.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31   ///////////////////////////////////////////////////////////////////
32   namespace pool
33   { /////////////////////////////////////////////////////////////////
34
35     class PoolImpl;
36
37     /** Pool internal filter skiping invalid/unwanted PoolItems. */
38     struct ByPoolItem
39     {
40       bool operator()( const PoolItem & pi ) const
41       { return pi; }
42     };
43
44     /** Main filter selecting PoolItems by \c name and \c kind.
45      *
46     */
47     class ByIdent
48     {
49       public:
50         ByIdent()
51         : _id( 0 )
52         {}
53
54         explicit ByIdent( sat::Solvable slv_r )
55         : _id( makeIdent( slv_r ) )
56         {}
57
58         explicit ByIdent( IdString ident_r )
59         : _id( ident_r.id() )
60         {}
61
62         ByIdent( ResKind kind_r, IdString name_r )
63         : _id( makeIdent( kind_r, name_r ) )
64         {}
65
66         ByIdent( ResKind kind_r, const C_Str & name_r )
67         : _id( makeIdent( kind_r, name_r ) )
68         {}
69
70       public:
71         bool operator()( sat::Solvable slv_r ) const
72         {
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 ) );
75         }
76
77         bool operator()( const PoolItem & pi_r ) const
78         { return operator()( pi_r.satSolvable() ); }
79
80         bool operator()( ResObject::constPtr p_r ) const
81         { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
82
83       private:
84         sat::detail::IdType makeIdent( sat::Solvable slv_r )
85         {
86           return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
87                                                      : slv_r.ident().id();
88         }
89
90         sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
91         {
92           if ( kind_r == ResKind::package )
93             return name_r.id();
94           else if ( kind_r == ResKind::srcpackage )
95             return -name_r.id();
96           return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
97         }
98
99         sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
100         {
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();
106         }
107
108       public:
109         sat::detail::IdType get() const { return _id; }
110
111       private:
112         /** negative \c _id for \c srcpackage, as they use the same \c ident
113          * as \c package.
114          */
115         sat::detail::IdType _id;
116     };
117
118     ///////////////////////////////////////////////////////////////////
119     //
120     //  CLASS NAME : PoolTraits
121     //
122     /** */
123     struct PoolTraits
124     {
125     public:
126       typedef sat::detail::SolvableIdType               SolvableIdType;
127
128       /** pure items  */
129       typedef std::vector<PoolItem>                     ItemContainerT;
130       typedef ItemContainerT::const_iterator            item_iterator;
131       typedef filter_iterator<ByPoolItem,ItemContainerT::const_iterator>
132                                                         const_iterator;
133       typedef ItemContainerT::size_type                 size_type;
134
135       /** ident index */
136       typedef std::tr1::unordered_multimap<sat::detail::IdType, PoolItem>
137                                                         Id2ItemT;
138       typedef std::_Select2nd<Id2ItemT::value_type>     Id2ItemValueSelector;
139       typedef transform_iterator<Id2ItemValueSelector, Id2ItemT::const_iterator>
140                                                         byIdent_iterator;
141
142       /* list of known Repositories */
143       typedef std::list<Repository>                     RepoContainerT;
144       typedef RepoContainerT::const_iterator            repository_iterator;
145
146       typedef PoolImpl                   Impl;
147       typedef shared_ptr<PoolImpl>       Impl_Ptr;
148       typedef shared_ptr<const PoolImpl> Impl_constPtr;
149
150       /** Map of Capabilities and "who" has set it*/
151       typedef std::map<ResStatus::TransactByValue,Capabilities>         AdditionalCapabilities;
152
153     };
154     ///////////////////////////////////////////////////////////////////
155
156     /////////////////////////////////////////////////////////////////
157   } // namespace pool
158   ///////////////////////////////////////////////////////////////////
159   /////////////////////////////////////////////////////////////////
160 } // namespace zypp
161 ///////////////////////////////////////////////////////////////////
162 #endif // ZYPP_POOL_POOLTRAITS_H