Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / ResPoolProxy.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResPoolProxy.h
10  *
11 */
12 #ifndef ZYPP_RESPOOLPROXY_H
13 #define ZYPP_RESPOOLPROXY_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/PtrTypes.h"
18
19 #include "zypp/ResPool.h"
20 #include "zypp/ui/Selectable.h"
21 #include "zypp/ui/SelFilters.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26
27   ///////////////////////////////////////////////////////////////////
28   //
29   //    CLASS NAME : ResPoolProxy
30   //
31   /** ResPool::instance().proxy();
32    * \todo integrate it into ResPool
33   */
34   class ResPoolProxy
35   {
36     friend std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj );
37     friend std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj );
38     typedef std::multimap<ResKind,ui::Selectable::Ptr> SelectablePool;
39
40   public:
41     /** Implementation  */
42     class Impl;
43
44     typedef MapKVIteratorTraits<SelectablePool>::Value_const_iterator const_iterator;
45     typedef SelectablePool::size_type size_type;
46
47     typedef ResPool::repository_iterator    repository_iterator;
48
49   public:
50
51     /** Default ctor: no pool
52      * Nonempty proxies are provided by \ref ResPool.
53      * \see \ref ResPool::proxy
54      * \code
55      * ResPoolProxy p( ResPool::instance().proxy() );
56      * \endcode
57      */
58     ResPoolProxy();
59
60     /** Dtor */
61     ~ResPoolProxy();
62
63   public:
64     /** \name Lookup individual Selectables. */
65     //@{
66     ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const;
67
68     ui::Selectable::Ptr lookup( IdString ident_r ) const
69     { return lookup( pool::ByIdent( ident_r ) ); }
70
71     ui::Selectable::Ptr lookup( ResKind kind_r, const std::string & name_r ) const
72     { return lookup( pool::ByIdent( kind_r, name_r ) ); }
73
74     ui::Selectable::Ptr lookup( const sat::Solvable & solv_r ) const
75     { return lookup( pool::ByIdent( solv_r ) ); }
76
77     ui::Selectable::Ptr lookup( const ResObject::constPtr & resolvable_r ) const
78     { return resolvable_r ? lookup( resolvable_r->satSolvable() ) : ui::Selectable::Ptr(); }
79
80     ui::Selectable::Ptr lookup( const PoolItem & pi_r ) const
81     { return lookup( pi_r.satSolvable() ); }
82     //@}
83
84   public:
85     /** \name Iterate through all Selectables of a all kind. */
86     //@{
87     bool empty() const;
88     size_type size() const;
89     const_iterator begin() const;
90     const_iterator end() const;
91     //@}
92
93     /** \name Iterate through all Selectables of a certain kind. */
94     //@{
95     /** True if there are items of a certain kind. */
96     bool empty( const ResKind & kind_r ) const;
97
98     template<class _Res>
99       bool empty() const
100       { return empty( ResTraits<_Res>::kind ); }
101
102     /** Number of Items of a certain kind.  */
103     size_type size( const ResKind & kind_r ) const;
104
105     template<class _Res>
106       size_type size() const
107       { return size( ResTraits<_Res>::kind ); }
108
109     const_iterator byKindBegin( const ResKind & kind_r ) const;
110
111     template<class _Res>
112       const_iterator byKindBegin() const
113       { return byKindBegin( ResTraits<_Res>::kind ); }
114
115
116     const_iterator byKindEnd( const ResKind & kind_r ) const;
117
118     template<class _Res>
119       const_iterator byKindEnd() const
120       { return byKindEnd( ResTraits<_Res>::kind ); }
121     //@}
122
123  public:
124    /** \name Iterate through all Repositories that contribute ResObjects.
125    */
126    //@{
127    size_type knownRepositoriesSize() const;
128
129    repository_iterator knownRepositoriesBegin() const;
130
131    repository_iterator knownRepositoriesEnd() const;
132    //@}
133
134   public:
135     /** Test whether there is at least one ui::Selectable with
136      * an installed object.
137     */
138     bool hasInstalledObj( const ResKind & kind_r ) const
139     {
140       return(    make_begin<ui::selfilter::ByHasInstalledObj>( kind_r )
141               != make_end<ui::selfilter::ByHasInstalledObj>( kind_r ) );
142     }
143
144     template<class _Res>
145       bool hasInstalledObj() const
146       { return hasInstalledObj( ResTraits<_Res>::kind ); }
147
148   public:
149     /** \name Save and restore state per kind of resolvable.
150      * Simple version, no savety net. So don't restore or diff,
151      * if you didn't save before.
152      *
153      * Diff returns true, if current stat differs from the saved
154      * state.
155     */
156     //@{
157     void saveState() const;
158
159     void saveState( const ResKind & kind_r ) const;
160
161     template<class _Res>
162       void saveState() const
163       { return saveState( ResTraits<_Res>::kind ); }
164
165     void restoreState() const;
166
167     void restoreState( const ResKind & kind_r ) const;
168
169     template<class _Res>
170       void restoreState() const
171       { return restoreState( ResTraits<_Res>::kind ); }
172
173     bool diffState() const;
174
175     bool diffState( const ResKind & kind_r ) const;
176
177     template<class _Res>
178       bool diffState() const
179       { return diffState( ResTraits<_Res>::kind ); }
180     //@}
181
182   private:
183     template<class _Filter>
184       filter_iterator<_Filter,const_iterator>
185       make_begin( _Filter filter_r, const ResKind & kind_r ) const
186       {
187         return make_filter_iterator( filter_r,
188                                      byKindBegin(kind_r),
189                                      byKindEnd(kind_r) );
190       }
191     template<class _Filter>
192       filter_iterator<_Filter,const_iterator>
193       make_begin( const ResKind & kind_r ) const
194       {
195         return make_begin( _Filter(), kind_r );
196       }
197
198
199     template<class _Filter>
200       filter_iterator<_Filter,const_iterator>
201       make_end( _Filter filter_r, const ResKind & kind_r ) const
202       {
203         return make_filter_iterator( filter_r,
204                                      byKindEnd(kind_r),
205                                      byKindEnd(kind_r) );
206       }
207     template<class _Filter>
208       filter_iterator<_Filter,const_iterator>
209       make_end( const ResKind & kind_r ) const
210       {
211         return make_end( _Filter(), kind_r );
212       }
213
214   private:
215     friend class pool::PoolImpl;
216     /** Ctor */
217     ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r );
218     /** Pointer to implementation */
219     RW_pointer<Impl> _pimpl;
220   };
221   ///////////////////////////////////////////////////////////////////
222
223   /** \relates ResPoolProxy Stream output */
224   std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj );
225
226   /** \relates ResPoolProxy Verbose stream output */
227   std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj );
228
229   /////////////////////////////////////////////////////////////////
230 } // namespace zypp
231 ///////////////////////////////////////////////////////////////////
232 #endif // ZYPP_RESPOOLPROXY_H