libzypp  17.14.0
ResPoolProxy.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
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 
24 namespace zypp
25 {
26 
28  //
29  // CLASS NAME : ResPoolProxy
30  //
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:
42  struct Impl;
43 
46 
48 
49  public:
50 
58  ResPoolProxy();
59 
61  ~ResPoolProxy();
62 
63  public:
66  ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const;
67 
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() ); }
83 
84  public:
87  bool empty() const;
88  size_type size() const;
89  const_iterator begin() const;
90  const_iterator end() const;
92 
96  bool empty( const ResKind & kind_r ) const;
97 
98  template<class TRes>
99  bool empty() const
100  { return empty( ResTraits<TRes>::kind ); }
101 
103  size_type size( const ResKind & kind_r ) const;
104 
105  template<class TRes>
106  size_type size() const
107  { return size( ResTraits<TRes>::kind ); }
108 
109  const_iterator byKindBegin( const ResKind & kind_r ) const;
110 
111  template<class TRes>
113  { return byKindBegin( ResTraits<TRes>::kind ); }
114 
115 
116  const_iterator byKindEnd( const ResKind & kind_r ) const;
117 
118  template<class TRes>
120  { return byKindEnd( ResTraits<TRes>::kind ); }
121 
122 
123  Iterable<const_iterator> byKind( const ResKind & kind_r ) const
124  { return makeIterable( byKindBegin( kind_r ), byKindEnd( kind_r ) ); }
125 
126  template<class TRes>
128  { return makeIterable( byKindBegin<TRes>(), byKindEnd<TRes>() ); }
129 
131 
132  public:
137 
139 
141 
143  { return makeIterable( knownRepositoriesBegin(), knownRepositoriesEnd() ); }
145 
146  public:
150  bool hasInstalledObj( const ResKind & kind_r ) const
151  {
152  return( make_begin<ui::selfilter::ByHasInstalledObj>( kind_r )
153  != make_end<ui::selfilter::ByHasInstalledObj>( kind_r ) );
154  }
155 
156  template<class TRes>
157  bool hasInstalledObj() const
159 
160  public:
171  void saveState() const;
172 
173  void saveState( const ResKind & kind_r ) const;
174 
175  template<class TRes>
176  void saveState() const
177  { return saveState( ResTraits<TRes>::kind ); }
178 
179  void restoreState() const;
180 
181  void restoreState( const ResKind & kind_r ) const;
182 
183  template<class TRes>
184  void restoreState() const
185  { return restoreState( ResTraits<TRes>::kind ); }
186 
187  bool diffState() const;
188 
189  bool diffState( const ResKind & kind_r ) const;
190 
191  template<class TRes>
192  bool diffState() const
193  { return diffState( ResTraits<TRes>::kind ); }
194 
202  struct ScopedSaveState;
203 
204  ScopedSaveState scopedSaveState() const;
205 
206  ScopedSaveState scopedSaveState( const ResKind & kind_r ) const;
207 
208  template<class TRes>
211 
213 
214  private:
215  template<class TFilter>
216  filter_iterator<TFilter,const_iterator>
217  make_begin( TFilter filter_r, const ResKind & kind_r ) const
218  {
219  return make_filter_iterator( filter_r,
220  byKindBegin(kind_r),
221  byKindEnd(kind_r) );
222  }
223  template<class TFilter>
224  filter_iterator<TFilter,const_iterator>
225  make_begin( const ResKind & kind_r ) const
226  {
227  return make_begin( TFilter(), kind_r );
228  }
229 
230 
231  template<class TFilter>
232  filter_iterator<TFilter,const_iterator>
233  make_end( TFilter filter_r, const ResKind & kind_r ) const
234  {
235  return make_filter_iterator( filter_r,
236  byKindEnd(kind_r),
237  byKindEnd(kind_r) );
238  }
239  template<class TFilter>
240  filter_iterator<TFilter,const_iterator>
241  make_end( const ResKind & kind_r ) const
242  {
243  return make_end( TFilter(), kind_r );
244  }
245 
246  private:
247  friend class pool::PoolImpl;
249  ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r );
252  };
254 
256  std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj );
257 
259  std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj );
260 
262 
264  {
266 
267  ScopedSaveState( const ResPoolProxy & pool_r )
268  : _pimpl( new Impl( pool_r ) )
269  { _pimpl->saveState(); }
270 
271  ScopedSaveState( const ResPoolProxy & pool_r, const ResKind & kind_r )
272  : _pimpl( new Impl( pool_r, kind_r ) )
273  { _pimpl->saveState(); }
274 
276  { if ( _pimpl ) _pimpl->restoreState(); }
277 
278  void acceptState()
279  { _pimpl.reset(); }
280 
281  private:
282  struct Impl
283  {
284  Impl( const ResPoolProxy & pool_r )
285  : _pool( pool_r )
286  {}
287  Impl( const ResPoolProxy & pool_r, const ResKind & kind_r )
288  : _pool( pool_r ), _kind( new ResKind( kind_r ) )
289  {}
290  void saveState()
291  { if ( _kind ) _pool.saveState( *_kind ); else _pool.saveState(); }
293  { if ( _kind ) _pool.restoreState( *_kind ); else _pool.restoreState(); }
295  scoped_ptr<ResKind> _kind;
296 
297  };
298  std::unique_ptr<Impl> _pimpl;
299  };
300 
302  { return ScopedSaveState( *this ); }
303 
305  { return ScopedSaveState( *this, kind_r ); }
306 
308 } // namespace zypp
310 #endif // ZYPP_RESPOOLPROXY_H