add basic locale interface to ResPool, remove deprecated _gxx hashes
[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   class CapAndItem;
32   class Repository;
33
34   ///////////////////////////////////////////////////////////////////
35   namespace pool
36   { /////////////////////////////////////////////////////////////////
37
38     class PoolImpl;
39
40     /** Pool internal filter skiping invalid/unwanted PoolItems. */
41     struct ByPoolItem
42     {
43       bool operator()( const PoolItem & pi ) const
44       { return pi; }
45     };
46
47     /** Main filter selecting PoolItems by \c name and \c kind.
48      *
49     */
50     class ByIdent
51     {
52       public:
53         ByIdent()
54         : _id( 0 )
55         {}
56
57         explicit ByIdent( sat::Solvable slv_r )
58         : _id( makeIdent( slv_r ) )
59         {}
60
61         explicit ByIdent( IdString ident_r )
62         : _id( ident_r.id() )
63         {}
64
65         ByIdent( ResKind kind_r, IdString name_r )
66         : _id( makeIdent( kind_r, name_r ) )
67         {}
68
69         ByIdent( ResKind kind_r, const C_Str & name_r )
70         : _id( makeIdent( kind_r, name_r ) )
71         {}
72
73       public:
74         bool operator()( sat::Solvable slv_r ) const
75         {
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 ) );
78         }
79
80         bool operator()( const PoolItem & pi_r ) const
81         { return operator()( pi_r.satSolvable() ); }
82
83         bool operator()( ResObject::constPtr p_r ) const
84         { return p_r ? operator()( p_r->satSolvable() ) : !_id; }
85
86       private:
87         sat::detail::IdType makeIdent( sat::Solvable slv_r )
88         {
89           return slv_r.isKind( ResKind::srcpackage ) ? -slv_r.ident().id()
90                                                      : slv_r.ident().id();
91         }
92
93         sat::detail::IdType makeIdent( ResKind kind_r, IdString name_r )
94         {
95           if ( kind_r == ResKind::package )
96             return name_r.id();
97           else if ( kind_r == ResKind::srcpackage )
98             return -name_r.id();
99           return IdString( str::form( "%s:%s", kind_r.c_str(), name_r.c_str() ) ).id();
100         }
101
102         sat::detail::IdType makeIdent( ResKind kind_r, const C_Str & name_r )
103         {
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();
109         }
110
111       public:
112         sat::detail::IdType get() const { return _id; }
113
114       private:
115         /** negative \c _id for \c srcpackage, as they use the same \c ident
116          * as \c package.
117          */
118         sat::detail::IdType _id;
119     };
120
121     ///////////////////////////////////////////////////////////////////
122     //
123     //  CLASS NAME : PoolTraits
124     //
125     /** */
126     struct PoolTraits
127     {
128     public:
129       typedef sat::detail::SolvableIdType               SolvableIdType;
130
131       /** pure items  */
132       typedef std::vector<PoolItem>                     ItemContainerT;
133       typedef ItemContainerT::const_iterator            item_iterator;
134       typedef filter_iterator<ByPoolItem,ItemContainerT::const_iterator>
135                                                         const_iterator;
136       typedef ItemContainerT::size_type                 size_type;
137
138       /** ident index */
139       typedef std::tr1::unordered_multimap<sat::detail::IdType, PoolItem>
140                                                         Id2ItemT;
141       typedef std::_Select2nd<Id2ItemT::value_type>     Id2ItemValueSelector;
142       typedef transform_iterator<Id2ItemValueSelector, Id2ItemT::const_iterator>
143                                                         byIdent_iterator;
144
145
146       /* list of known Repositories */
147       typedef std::list<Repository>                     RepoContainerT;
148       typedef RepoContainerT::const_iterator            repository_iterator;
149
150
151
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)
156
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;
162
163
164       typedef PoolImpl                   Impl;
165       typedef shared_ptr<PoolImpl>       Impl_Ptr;
166       typedef shared_ptr<const PoolImpl> Impl_constPtr;
167
168       /** Map of Capabilities and "who" has set it*/
169       typedef std::map<ResStatus::TransactByValue,Capabilities>         AdditionalCapabilities;
170
171     };
172     ///////////////////////////////////////////////////////////////////
173
174     /////////////////////////////////////////////////////////////////
175   } // namespace pool
176   ///////////////////////////////////////////////////////////////////
177   /////////////////////////////////////////////////////////////////
178 } // namespace zypp
179 ///////////////////////////////////////////////////////////////////
180 #endif // ZYPP_POOL_POOLTRAITS_H