1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PoolItemBest.cc
13 #include "zypp/base/LogTools.h"
15 #include "zypp/PoolItemBest.h"
16 #include "zypp/ui/SelectableTraits.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 // CLASS NAME : PoolItemBest::Impl
28 /** PoolItemBest implementation. */
29 struct PoolItemBest::Impl
31 Impl( bool preferNotLocked_r )
32 : _preferNotLocked { preferNotLocked_r }
36 bool _preferNotLocked;
39 friend Impl * rwcowClone<Impl>( const Impl * rhs );
40 /** clone for RWCOW_pointer */
42 { return new Impl( *this ); }
44 ///////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////
48 // CLASS NAME : PoolItemBest
50 ///////////////////////////////////////////////////////////////////
52 void PoolItemBest::_ctor_init( bool preferNotLocked_r )
53 { _dont_use_this_use_pimpl.reset( new RWCOW_pointer<Impl>(new Impl( preferNotLocked_r )) ); }
55 void PoolItemBest::_ctor_init()
56 { _ctor_init( /*preferNotLocked*/false ); }
58 const PoolItemBest::Container & PoolItemBest::container() const
59 { return pimpl()->_container; }
61 void PoolItemBest::add( const PoolItem & pi_r )
63 Container & container( pimpl()->_container );
65 PoolItem & ccand( container[pi_r.satSolvable().ident()] );
68 else if ( pimpl()->_preferNotLocked )
70 if ( ! pi_r.status().isLocked() )
72 if ( ccand.status().isLocked() || ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
75 else if ( ccand.status().isLocked() )
77 if ( ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
81 else if ( ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
85 PoolItem PoolItemBest::find( IdString ident_r ) const
87 const Container & container( pimpl()->_container );
88 Container::const_iterator it( container.find( ident_r ) );
89 return it != container.end() ? it->second : PoolItem();
92 /******************************************************************
94 ** FUNCTION NAME : operator<<
95 ** FUNCTION TYPE : std::ostream &
97 std::ostream & operator<<( std::ostream & str, const PoolItemBest & obj )
99 return dumpRange( str << "(" << obj.size() << ") ", obj.begin(), obj.end() );
102 /////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////