also hash names, requires, and conflicts
[platform/upstream/libzypp.git] / zypp / pool / PoolImpl.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/pool/PoolImpl.cc
10  *
11 */
12 #include <iostream>
13 //#include "zypp/base/Logger.h"
14
15 #include "zypp/pool/PoolImpl.h"
16 #include "zypp/CapSet.h"
17
18 using std::endl;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24   namespace pool
25   { /////////////////////////////////////////////////////////////////
26
27     ///////////////////////////////////////////////////////////////////
28     //
29     //  METHOD NAME : PoolImpl::PoolImpl
30     //  METHOD TYPE : Ctor
31     //
32     PoolImpl::PoolImpl()
33     {}
34
35     ///////////////////////////////////////////////////////////////////
36     //
37     //  METHOD NAME : PoolImpl::~PoolImpl
38     //  METHOD TYPE : Dtor
39     //
40     PoolImpl::~PoolImpl()
41     {}
42
43     /******************************************************************
44     **
45     **  FUNCTION NAME : operator<<
46     **  FUNCTION TYPE : std::ostream &
47     */
48     std::ostream & operator<<( std::ostream & str, const PoolImpl & obj )
49     {
50       return str << "PoolImpl " << obj.size();
51     }
52
53     void PoolImplInserter::operator()( ResObject::constPtr ptr_r, bool installed )
54     {
55       PoolImpl::Item item ( ptr_r, ResStatus (installed) );
56       _poolImpl.store().insert( item );
57       _poolImpl.namestore().insert( PoolImpl::NameContainerT::value_type (item->name(), item ) );
58       CapSet provides = item->dep( Dep::PROVIDES );
59       for (CapSet::iterator ic = provides.begin(); ic != provides.end(); ++ic) {
60         _poolImpl.providesstore().insert( PoolImpl::IndexContainerT::value_type (ic->index(), std::make_pair( *ic, item ) ) );
61       }
62       CapSet requires = item->dep( Dep::REQUIRES );
63       for (CapSet::iterator ic = requires.begin(); ic != requires.end(); ++ic) {
64         _poolImpl.requiresstore().insert( PoolImpl::IndexContainerT::value_type (ic->index(), std::make_pair( *ic, item ) ) );
65       }
66       CapSet conflicts = item->dep( Dep::CONFLICTS );
67       for (CapSet::iterator ic = conflicts.begin(); ic != conflicts.end(); ++ic) {
68         _poolImpl.conflictsstore().insert( PoolImpl::IndexContainerT::value_type (ic->index(), std::make_pair( *ic, item ) ) );
69       }
70     }
71
72     void PoolImplDeleter::operator()( ResObject::constPtr ptr_r )
73     {
74       PoolImpl::Item item( ptr_r );
75       _poolImpl.store().erase( item );
76       for (PoolImpl::nameiterator nit = _poolImpl.namestore().lower_bound (item->name());
77                                   nit != _poolImpl.namestore().upper_bound (item->name()); ++nit)
78       {
79         if (nit->second == item)
80             _poolImpl.namestore().erase( nit );
81       }
82       CapSet provides = ptr_r->dep( Dep::PROVIDES );
83       for (CapSet::iterator ic = provides.begin(); ic != provides.end(); ++ic) {
84         for (PoolImpl::indexiterator iit = _poolImpl.providesstore().lower_bound (ic->index());
85                            iit != _poolImpl.providesstore().upper_bound (ic->index()); ++iit)
86         {
87             if (iit->second.second == item)
88                 _poolImpl.providesstore().erase( iit );
89         }
90       }
91       CapSet requires = ptr_r->dep( Dep::REQUIRES );
92       for (CapSet::iterator ic = requires.begin(); ic != requires.end(); ++ic) {
93         for (PoolImpl::indexiterator iit = _poolImpl.requiresstore().lower_bound (ic->index());
94                            iit != _poolImpl.requiresstore().upper_bound (ic->index()); ++iit)
95         {
96             if (iit->second.second == item)
97                 _poolImpl.requiresstore().erase( iit );
98         }
99       }
100       CapSet conflicts = ptr_r->dep( Dep::CONFLICTS );
101       for (CapSet::iterator ic = conflicts.begin(); ic != conflicts.end(); ++ic) {
102         for (PoolImpl::indexiterator iit = _poolImpl.conflictsstore().lower_bound (ic->index());
103                            iit != _poolImpl.conflictsstore().upper_bound (ic->index()); ++iit)
104         {
105             if (iit->second.second == item)
106                 _poolImpl.conflictsstore().erase( iit );
107         }
108       }
109     }
110
111     /////////////////////////////////////////////////////////////////
112   } // namespace pool
113   ///////////////////////////////////////////////////////////////////
114   /////////////////////////////////////////////////////////////////
115 } // namespace zypp
116 ///////////////////////////////////////////////////////////////////