Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / PoolItemBest.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/PoolItemBest.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/LogTools.h"
14
15 #include "zypp/PoolItemBest.h"
16 #include "zypp/ui/SelectableTraits.h"
17
18 using std::endl;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   ///////////////////////////////////////////////////////////////////
25   //
26   //    CLASS NAME : PoolItemBest::Impl
27   //
28   /** PoolItemBest implementation. */
29   struct PoolItemBest::Impl
30   {
31     Container _container;
32
33     private:
34       friend Impl * rwcowClone<Impl>( const Impl * rhs );
35       /** clone for RWCOW_pointer */
36       Impl * clone() const
37       { return new Impl( *this ); }
38   };
39   ///////////////////////////////////////////////////////////////////
40
41   ///////////////////////////////////////////////////////////////////
42   //
43   //    CLASS NAME : PoolItemBest
44   //
45   ///////////////////////////////////////////////////////////////////
46
47   void PoolItemBest::_ctor_init()
48   { _dont_use_this_use_pimpl.reset( new RWCOW_pointer<Impl>(new Impl) ); }
49
50   const PoolItemBest::Container & PoolItemBest::container() const
51   { return pimpl()->_container; }
52
53   void PoolItemBest::add( const PoolItem & pi_r )
54   {
55     Container & container( pimpl()->_container );
56     PoolItem & ccand( container[pi_r.satSolvable().ident()] );
57     if ( ! ccand || ui::SelectableTraits::AVOrder()( pi_r, ccand ) )
58       ccand = pi_r;
59   }
60
61   PoolItem PoolItemBest::find( IdString ident_r ) const
62   {
63     const Container & container( pimpl()->_container );
64     Container::const_iterator it( container.find( ident_r ) );
65     return it != container.end() ? it->second : PoolItem();
66   }
67
68   /******************************************************************
69   **
70   **    FUNCTION NAME : operator<<
71   **    FUNCTION TYPE : std::ostream &
72   */
73   std::ostream & operator<<( std::ostream & str, const PoolItemBest & obj )
74   {
75     return dumpRange( str << "(" << obj.size() << ") ", obj.begin(), obj.end() );
76   }
77
78   /////////////////////////////////////////////////////////////////
79 } // namespace zypp
80 ///////////////////////////////////////////////////////////////////