- Add method Product::replacedProducts to identify installed
[platform/upstream/libzypp.git] / zypp / sat / WhatObsoletes.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/WhatObsoletes.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/LogTools.h"
15 #include "zypp/sat/WhatObsoletes.h"
16 #include "zypp/sat/detail/PoolImpl.h"
17 #include "zypp/PoolItem.h"
18
19 using std::endl;
20
21 ///////////////////////////////////////////////////////////////////
22 namespace zypp
23 { /////////////////////////////////////////////////////////////////
24   ///////////////////////////////////////////////////////////////////
25   namespace sat
26   { /////////////////////////////////////////////////////////////////
27
28     ///////////////////////////////////////////////////////////////////
29     namespace
30     { /////////////////////////////////////////////////////////////////
31
32       /** WhatObsoletes ctor helper collecting obsoleted installed items. */
33       shared_ptr<void> allocatedProviders( sat::Solvable item_r, const sat::detail::IdType *& first_r )
34       {
35         WhatProvides obsoleted( item_r.obsoletes() );
36         if ( obsoleted.empty() )
37         {
38           return shared_ptr<void>();
39         }
40
41         // use allocated private data to store the result (incl. trailing NULL)
42         std::vector<sat::detail::IdType> * pdata = 0;
43         shared_ptr<void> ret;
44
45         for_( it, obsoleted.begin(), obsoleted.end() )
46         {
47           if ( it->isSystem() )
48           {
49             if ( ! pdata )
50             {
51               ret.reset( (pdata = new std::vector<sat::detail::IdType>) );
52             }
53             pdata->push_back( it->id() );
54           }
55         }
56
57         if ( pdata )
58         {
59           pdata->push_back( sat::detail::noId );
60           first_r = &pdata->front();
61         }
62         return ret;
63       }
64
65       /////////////////////////////////////////////////////////////////
66     } // namespace
67     ///////////////////////////////////////////////////////////////////
68
69     WhatObsoletes::WhatObsoletes( Solvable item_r )
70     : _begin( 0 )
71     , _private( allocatedProviders( item_r, _begin ) )
72     {}
73
74     WhatObsoletes::WhatObsoletes( const PoolItem & item_r )
75     : _begin( 0 )
76     , _private( allocatedProviders( item_r.satSolvable(), _begin ) )
77     {}
78
79     WhatObsoletes::WhatObsoletes( const ResObject::constPtr item_r )
80     : _begin( 0 )
81     {
82       if ( item_r )
83         _private = allocatedProviders( item_r->satSolvable(), _begin );
84     }
85
86     WhatObsoletes::size_type WhatObsoletes::size() const
87     {
88       if ( ! _begin )
89         return 0;
90
91       Capabilities::size_type ret = 0;
92       for ( const sat::detail::IdType * end = _begin; *end; ++end )
93       {
94         ++ret;
95       }
96       return ret;
97     }
98
99     /******************************************************************
100     **
101     **  FUNCTION NAME : operator<<
102     **  FUNCTION TYPE : std::ostream &
103     */
104     std::ostream & operator<<( std::ostream & str, const WhatObsoletes & obj )
105     {
106       return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
107     }
108
109     /////////////////////////////////////////////////////////////////
110   } // namespace sat
111   ///////////////////////////////////////////////////////////////////
112   /////////////////////////////////////////////////////////////////
113 } // namespace zypp
114 ///////////////////////////////////////////////////////////////////