Switch ResPoolProxy to use multimap in order to allow iteration of all Selectables...
authorMichael Andres <ma@suse.de>
Tue, 5 Apr 2011 08:30:50 +0000 (10:30 +0200)
committerMichael Andres <ma@suse.de>
Tue, 5 Apr 2011 08:30:50 +0000 (10:30 +0200)
zypp/ResPoolProxy.cc
zypp/ResPoolProxy.h

index 5753475..d627567 100644 (file)
@@ -117,7 +117,7 @@ namespace zypp
           {
             // starting a new Selectable, create the previous one
             ui::Selectable::Ptr p( makeSelectablePtr( cbegin, it ) );
-            _selPool[p->kind()].push_back( p );
+            _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
             _selIndex[cbegin->first] = p;
             // remember new startpoint
             cbegin = it;
@@ -125,7 +125,7 @@ namespace zypp
         }
         // create the final one
         ui::Selectable::Ptr p( makeSelectablePtr( cbegin, id2item.end() ) );
-        _selPool[p->kind()].push_back( p );
+        _selPool.insert( SelectablePool::value_type( p->kind(), p ) );
         _selIndex[cbegin->first] = p;
       }
     }
@@ -140,17 +140,30 @@ namespace zypp
     }
 
   public:
+    bool empty() const
+    { return _selPool.empty(); }
+
+    size_type size() const
+    { return _selPool.size(); }
+
+    const_iterator begin() const
+    { return make_map_value_begin( _selPool ); }
+
+    const_iterator end() const
+    { return make_map_value_end( _selPool ); }
+
+  public:
     bool empty( const ResKind & kind_r ) const
-    { return _selPool[kind_r].empty(); }
+    { return( _selPool.count( kind_r ) == 0 );  }
 
     size_type size( const ResKind & kind_r ) const
-    { return _selPool[kind_r].size(); }
+    { return _selPool.count( kind_r ); }
 
     const_iterator byKindBegin( const ResKind & kind_r ) const
-    { return _selPool[kind_r].begin(); }
+    { return make_map_value_lower_bound( _selPool, kind_r ); }
 
     const_iterator byKindEnd( const ResKind & kind_r ) const
-    { return _selPool[kind_r].end(); }
+    { return make_map_value_upper_bound( _selPool, kind_r ); }
 
   public:
     size_type knownRepositoriesSize() const
@@ -244,6 +257,18 @@ namespace zypp
   ui::Selectable::Ptr ResPoolProxy::lookup( const pool::ByIdent & ident_r ) const
   { return _pimpl->lookup( ident_r ); }
 
+  bool ResPoolProxy::empty() const
+  { return _pimpl->empty(); }
+
+  ResPoolProxy::size_type ResPoolProxy::size() const
+  { return _pimpl->size(); }
+
+  ResPoolProxy::const_iterator ResPoolProxy::begin() const
+  { return _pimpl->begin(); }
+
+  ResPoolProxy::const_iterator ResPoolProxy::end() const
+  { return _pimpl->end(); }
+
   bool ResPoolProxy::empty( const ResKind & kind_r ) const
   { return _pimpl->empty( kind_r ); }
 
index 24eda50..f5ae8fa 100644 (file)
@@ -34,17 +34,14 @@ namespace zypp
   class ResPoolProxy
   {
     friend std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj );
-
-    typedef std::vector<ui::Selectable::Ptr>  SelectableKinds;
-    typedef std::map<ResKind,SelectableKinds> SelectablePool;
+    typedef std::multimap<ResKind,ui::Selectable::Ptr> SelectablePool;
 
   public:
     /** Implementation  */
     class Impl;
 
-    typedef SelectableKinds::iterator       iterator;
-    typedef SelectableKinds::const_iterator const_iterator;
-    typedef SelectableKinds::size_type      size_type;
+    typedef MapKVIteratorTraits<SelectablePool>::Value_const_iterator const_iterator;
+    typedef SelectablePool::size_type size_type;
 
     typedef ResPool::repository_iterator    repository_iterator;
 
@@ -84,7 +81,16 @@ namespace zypp
     //@}
 
   public:
+    /** \name Iterate through all Selectables of a all kind. */
+    //@{
+    bool empty() const;
+    size_type size() const;
+    const_iterator begin() const;
+    const_iterator end() const;
+    //@}
 
+    /** \name Iterate through all Selectables of a certain kind. */
+    //@{
     /** True if there are items of a certain kind. */
     bool empty( const ResKind & kind_r ) const;
 
@@ -99,8 +105,6 @@ namespace zypp
       size_type size() const
       { return size( ResTraits<_Res>::kind ); }
 
-    /** \name Iterate through all Selectables of a certain kind. */
-    //@{
     const_iterator byKindBegin( const ResKind & kind_r ) const;
 
     template<class _Res>