libzypp  17.8.0
ResPoolProxy.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14 
15 #include "zypp/base/Iterator.h"
16 #include "zypp/base/Algorithm.h"
17 #include "zypp/base/Functional.h"
18 
19 #include "zypp/ResPoolProxy.h"
20 #include "zypp/pool/PoolImpl.h"
21 #include "zypp/ui/SelectableImpl.h"
22 
23 using std::endl;
24 
26 namespace zypp
27 {
28 
31  {
32  void saveState( ResPool pool_r )
33  {
34  std::for_each( pool_r.begin(), pool_r.end(),
35  std::mem_fun_ref(&PoolItem::saveState) );
36  }
37 
38  void saveState( ResPool pool_r, const ResKind & kind_r )
39  {
40  std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
41  std::mem_fun_ref(&PoolItem::saveState) );
42  }
43 
44  void restoreState( ResPool pool_r )
45  {
46  std::for_each( pool_r.begin(), pool_r.end(),
47  std::mem_fun_ref(&PoolItem::restoreState) );
48  }
49 
50  void restoreState( ResPool pool_r, const ResKind & kind_r )
51  {
52  std::for_each( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
53  std::mem_fun_ref(&PoolItem::restoreState) );
54  }
55 
56  bool diffState( ResPool pool_r ) const
57  {
58  // return whether some PoolItem::sameState reported \c false.
59  return( invokeOnEach( pool_r.begin(), pool_r.end(),
60  std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
61  }
62 
63  bool diffState( ResPool pool_r, const ResKind & kind_r ) const
64  {
65  // return whether some PoolItem::sameState reported \c false.
66  return( invokeOnEach( pool_r.byKindBegin(kind_r), pool_r.byKindEnd(kind_r),
67  std::mem_fun_ref(&PoolItem::sameState) ) < 0 );
68  }
69  };
70 
71  namespace
72  {
73  ui::Selectable::Ptr makeSelectablePtr( pool::PoolImpl::Id2ItemT::const_iterator begin_r,
74  pool::PoolImpl::Id2ItemT::const_iterator end_r )
75  {
78  sat::Solvable solv( begin->satSolvable() );
79 
80  return new ui::Selectable( ui::Selectable::Impl_Ptr( new ui::Selectable::Impl( solv.kind(), solv.name(), begin, end ) ) );
81  }
82  } // namespace
83 
85  //
86  // CLASS NAME : ResPoolProxy::Impl
87  //
92  {
93  friend std::ostream & operator<<( std::ostream & str, const Impl & obj );
94  friend std::ostream & dumpOn( std::ostream & str, const Impl & obj );
95 
96  typedef std::unordered_map<sat::detail::IdType,ui::Selectable::Ptr> SelectableIndex;
98 
99  public:
101  :_pool( ResPool::instance() )
102  {}
103 
104  Impl( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
105  : _pool( pool_r )
106  {
107  const pool::PoolImpl::Id2ItemT & id2item( poolImpl_r.id2item() );
108  if ( ! id2item.empty() )
109  {
110  // set startpoint
111  pool::PoolImpl::Id2ItemT::const_iterator cbegin = id2item.begin();
112 
113  for_( it, id2item.begin(), id2item.end() )
114  {
115  if ( it->first != cbegin->first )
116  {
117  // starting a new Selectable, create the previous one
118  ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
119  _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
120  _selIndex[cbegin->first] = p;
121  // remember new startpoint
122  cbegin = it;
123  }
124  }
125  // create the final one
126  ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
127  _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
128  _selIndex[cbegin->first] = p;
129  }
130  }
131 
132  public:
133  ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const
134  {
135  SelectableIndex::const_iterator it( _selIndex.find( ident_r.get() ) );
136  if ( it != _selIndex.end() )
137  return it->second;
138  return ui::Selectable::Ptr();
139  }
140 
141  public:
142  bool empty() const
143  { return _selPool.empty(); }
144 
145  size_type size() const
146  { return _selPool.size(); }
147 
149  { return make_map_value_begin( _selPool ); }
150 
152  { return make_map_value_end( _selPool ); }
153 
154  public:
155  bool empty( const ResKind & kind_r ) const
156  { return( _selPool.count( kind_r ) == 0 ); }
157 
158  size_type size( const ResKind & kind_r ) const
159  { return _selPool.count( kind_r ); }
160 
161  const_iterator byKindBegin( const ResKind & kind_r ) const
162  { return make_map_value_lower_bound( _selPool, kind_r ); }
163 
164  const_iterator byKindEnd( const ResKind & kind_r ) const
165  { return make_map_value_upper_bound( _selPool, kind_r ); }
166 
167  public:
169  { return _pool.knownRepositoriesSize(); }
170 
172  { return _pool.knownRepositoriesBegin(); }
173 
175  { return _pool.knownRepositoriesEnd(); }
176 
177  public:
178 
179  void saveState() const
180  { PoolItemSaver().saveState( _pool ); }
181 
182  void saveState( const ResKind & kind_r ) const
183  { PoolItemSaver().saveState( _pool, kind_r ); }
184 
185  void restoreState() const
187 
188  void restoreState( const ResKind & kind_r ) const
189  { PoolItemSaver().restoreState( _pool, kind_r ); }
190 
191  bool diffState() const
192  { return PoolItemSaver().diffState( _pool ); }
193 
194  bool diffState( const ResKind & kind_r ) const
195  { return PoolItemSaver().diffState( _pool, kind_r ); }
196 
197  private:
201 
202  public:
204  static shared_ptr<Impl> nullimpl()
205  {
206  static shared_ptr<Impl> _nullimpl( new Impl );
207  return _nullimpl;
208  }
209  };
211 
213  inline std::ostream & operator<<( std::ostream & str, const ResPoolProxy::Impl & obj )
214  {
215  return str << "ResPoolProxy (" << obj._pool.serial() << ") [" << obj._pool.size()
216  << "solv/" << obj.size()<< "sel]";
217  }
218 
219  namespace detail
220  {
221  struct DumpFilter
222  {
223  bool operator()( const ui::Selectable::Ptr & selp ) const
224  { return selp->toModify(); }
225  };
226  }
227 
229  inline std::ostream & dumpOn( std::ostream & str, const ResPoolProxy::Impl & obj )
230  {
232  return dumpRange( str << obj << " toModify: ",
233  make_filter_begin( f, obj ),
234  make_filter_end( f, obj ) );
235  }
236 
238  //
239  // CLASS NAME : ResPoolProxy
240  //
242 
244  //
245  // METHOD NAME : ResPoolProxy::ResPoolProxy
246  // METHOD TYPE : Ctor
247  //
249  : _pimpl( Impl::nullimpl() )
250  {}
251 
253  //
254  // METHOD NAME : ResPoolProxy::ResPoolProxy
255  // METHOD TYPE : Ctor
256  //
257  ResPoolProxy::ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r )
258  : _pimpl( new Impl( pool_r, poolImpl_r ) )
259  {}
260 
262  //
263  // METHOD NAME : ResPoolProxy::~ResPoolProxy
264  // METHOD TYPE : Dtor
265  //
267  {}
268 
270  //
271  // forward to implementation
272  //
274 
276  { return _pimpl->lookup( ident_r ); }
277 
278  bool ResPoolProxy::empty() const
279  { return _pimpl->empty(); }
280 
282  { return _pimpl->size(); }
283 
285  { return _pimpl->begin(); }
286 
288  { return _pimpl->end(); }
289 
290  bool ResPoolProxy::empty( const ResKind & kind_r ) const
291  { return _pimpl->empty( kind_r ); }
292 
294  { return _pimpl->size( kind_r ); }
295 
297  { return _pimpl->byKindBegin( kind_r ); }
298 
300  { return _pimpl->byKindEnd( kind_r ); }
301 
303  { return _pimpl->knownRepositoriesSize(); }
304 
306  { return _pimpl->knownRepositoriesBegin(); }
307 
309  { return _pimpl->knownRepositoriesEnd(); }
310 
312  { _pimpl->saveState(); }
313 
314  void ResPoolProxy::saveState( const ResKind & kind_r ) const
315  { _pimpl->saveState( kind_r ); }
316 
318  { _pimpl->restoreState(); }
319 
320  void ResPoolProxy::restoreState( const ResKind & kind_r ) const
321  { _pimpl->restoreState( kind_r ); }
322 
324  { return _pimpl->diffState(); }
325 
326  bool ResPoolProxy::diffState( const ResKind & kind_r ) const
327  { return _pimpl->diffState( kind_r ); }
328 
329  std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj )
330  { return str << *obj._pimpl; }
331 
332  std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj )
333  { return dumpOn( str, *obj._pimpl ); }
334 
336 } // namespace zypp
transform_iterator< Id2ItemValueSelector, Id2ItemT::const_iterator > byIdent_iterator
Definition: PoolTraits.h:82
sat::detail::IdType get() const
Definition: ByIdent.h:88
Impl(ResPool pool_r, const pool::PoolImpl &poolImpl_r)
std::ostream & dumpOn(std::ostream &str, const ResPoolProxy::Impl &obj)
void saveState(ResPool pool_r)
Definition: ResPoolProxy.cc:32
bool sameState() const
Definition: PoolItem.cc:216
const_iterator end() const
Definition: ResPool.h:100
size_type size() const
friend std::ostream & operator<<(std::ostream &str, const Impl &obj)
intrusive_ptr< Selectable > Ptr
Definition: Selectable.h:57
repository_iterator knownRepositoriesBegin() const
Definition: ResPool.cc:77
void saveState(const ResKind &kind_r) const
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\ ", const std::string &sep="\ ", const std::string &sfx="\, const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition: LogTools.h:91
byKind_iterator byKindBegin(const ResKind &kind_r) const
Definition: ResPool.h:261
size_type knownRepositoriesSize() const
String related utilities and Regular expression matching.
bool diffState() const
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_begin(const TMap &map_r)
Convenience to create the value iterator from container::begin()
Definition: Iterator.h:238
bool empty(const ResKind &kind_r) const
const_iterator end() const
PoolTraits::Id2ItemT Id2ItemT
Definition: PoolImpl.h:125
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
repository_iterator knownRepositoriesEnd() const
Definition: ResPool.cc:80
const SerialNumber & serial() const
The pools serial number.
Definition: ResPool.cc:60
bool diffState(const ResKind &kind_r) const
void saveState() const
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_end(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::end().
Definition: Iterator.h:117
ResPool::instance().proxy();.
Definition: ResPoolProxy.h:34
const_iterator begin() const
Definition: ResPool.h:97
ResPoolProxy implementation.
Definition: ResPoolProxy.cc:91
repository_iterator knownRepositoriesBegin() const
const_iterator byKindEnd() const
Definition: ResPoolProxy.h:119
SelectableIndex _selIndex
bool empty() const
ResPoolProxy::const_iterator const_iterator
Definition: ResPoolProxy.cc:97
repository_iterator knownRepositoriesEnd() const
bool diffState(ResPool pool_r) const
Definition: ResPoolProxy.cc:56
size_type knownRepositoriesSize() const
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
P_Select2nd< Id2ItemT::value_type > Id2ItemValueSelector
Definition: PoolTraits.h:80
void restoreState(const ResKind &kind_r) const
void restoreState() const
Definition: PoolItem.cc:215
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: ResPoolProxy.h:251
friend std::ostream & dumpOn(std::ostream &str, const Impl &obj)
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_upper_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the value iterator from container::upper_bound()
Definition: Iterator.h:263
const_iterator end() const
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
void restoreState(ResPool pool_r)
Definition: ResPoolProxy.cc:44
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
void saveState(ResPool pool_r, const ResKind &kind_r)
Definition: ResPoolProxy.cc:38
shared_ptr< Impl > Impl_Ptr
Definition: Selectable.h:519
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_end(const TMap &map_r)
Convenience to create the value iterator from container::end()
Definition: Iterator.h:243
byKind_iterator byKindEnd(const ResKind &kind_r) const
Definition: ResPool.h:268
const_iterator begin() const
Global ResObject pool.
Definition: ResPool.h:60
SelectablePool::size_type size_type
Definition: ResPoolProxy.h:45
std::unordered_map< sat::detail::IdType, ui::Selectable::Ptr > SelectableIndex
Definition: ResPoolProxy.cc:96
void restoreState(ResPool pool_r, const ResKind &kind_r)
Definition: ResPoolProxy.cc:50
repository_iterator knownRepositoriesBegin() const
size_type size() const
Definition: ResPool.cc:66
std::multimap< ResKind, ui::Selectable::Ptr > SelectablePool
Definition: ResPoolProxy.h:38
const_iterator begin() const
const_iterator byKindBegin() const
Definition: ResPoolProxy.h:112
size_type knownRepositoriesSize() const
Definition: ResPool.cc:74
MapKVIteratorTraits< TMap >::Value_const_iterator make_map_value_lower_bound(const TMap &map_r, const typename TMap::key_type &key_r)
Convenience to create the value iterator from container::lower_bound()
Definition: Iterator.h:258
ResPoolProxy()
Default ctor: no pool Nonempty proxies are provided by ResPool.
size_type size() const
filter_iterator< TFilter, typename TContainer::const_iterator > make_filter_begin(TFilter f, const TContainer &c)
Convenience to create filter_iterator from container::begin().
Definition: Iterator.h:101
void restoreState() const
const Id2ItemT & id2item() const
Definition: PoolImpl.h:359
static shared_ptr< Impl > nullimpl()
Offer default Impl.
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
Definition: ResPoolProxy.h:42
bool diffState(ResPool pool_r, const ResKind &kind_r) const
Definition: ResPoolProxy.cc:63
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition: Algorithm.h:30
ui::Selectable::Ptr lookup(const pool::ByIdent &ident_r) const
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
const_iterator byKindBegin(const ResKind &kind_r) const
const_iterator byKindEnd(const ResKind &kind_r) const
size_type size(const ResKind &kind_r) const
std::ostream & operator<<(std::ostream &str, const ResPoolProxy::Impl &obj)
Main filter selecting PoolItems by name and kind.
Definition: ByIdent.h:26
bool operator()(const ui::Selectable::Ptr &selp) const
void saveState() const
Definition: PoolItem.cc:214
repository_iterator knownRepositoriesEnd() const