- Provide iterator based access to SourceManager data.
authorMichael Andres <ma@suse.de>
Wed, 22 Mar 2006 23:18:55 +0000 (23:18 +0000)
committerMichael Andres <ma@suse.de>
Wed, 22 Mar 2006 23:18:55 +0000 (23:18 +0000)
zypp/SourceManager.cc
zypp/SourceManager.h
zypp/base/Debug.h
zypp/base/Iterator.h

index de2c412..219852d 100644 (file)
@@ -135,6 +135,24 @@ namespace zypp
     MIL << "Deleted SourceManager Singleton." << endl;
   }
 
+  SourceManager::const_iterator SourceManager::begin() const
+  { return _sources.begin(); }
+
+  SourceManager::const_iterator SourceManager::end() const
+  { return _sources.end();  }
+
+  SourceManager::SourceId_const_iterator SourceManager::SourceId_begin() const
+  { return make_map_key_begin( _sources ); }
+
+  SourceManager::SourceId_const_iterator SourceManager::SourceId_end() const
+  { return make_map_key_end( _sources ); }
+
+  SourceManager::Source_const_iterator SourceManager::Source_begin() const
+  { return make_map_value_begin( _sources ); }
+
+  SourceManager::Source_const_iterator SourceManager::Source_end() const
+  { return make_map_value_end( _sources ); }
+
   void SourceManager::reset()
   {
     MIL << "SourceManager reset (forget all sources)" << endl;
@@ -387,7 +405,7 @@ namespace zypp
                id = 0;
                ZYPP_CAUGHT(e2);
            }
-       
+
            if( id == 0)
            {
                report.append( it->url + it->product_dir, expt );
@@ -419,7 +437,7 @@ namespace zypp
     dumpSourceTableOn( DBG );
     return true;
   }
-  
+
   void SourceManager::disableSourcesAt( const Pathname & root_r )
   {
     storage::PersistentStorage store;
@@ -428,7 +446,7 @@ namespace zypp
     std::list<storage::PersistentStorage::SourceData> new_sources = store.storedSources();
 
     MIL << "Disabling all sources in store at " << root_r << endl;
-    
+
     for( std::list<storage::PersistentStorage::SourceData>::iterator it = new_sources.begin();
        it != new_sources.end(); ++it)
     {
index 6605967..5f45a36 100644 (file)
 
 #include <iosfwd>
 #include <list>
+#include <map>
 
 #include "zypp/base/ReferenceCounted.h"
 #include "zypp/base/NonCopyable.h"
-#include "zypp/base/Gettext.h"
+//#include "zypp/base/Iterator.h"
+
+#include "zypp/base/Gettext.h" // move with FailedSourcesRestoreException
 
 #include "zypp/Source.h"
 #include "zypp/Url.h"
@@ -28,7 +31,7 @@ namespace zypp
 { /////////////////////////////////////////////////////////////////
 
   DEFINE_PTR_TYPE(SourceManager)
-
+  /** \todo move to separate header file.*/
   class FailedSourcesRestoreException : public Exception
   {
     public:
@@ -64,7 +67,6 @@ namespace zypp
   {
     friend std::ostream & operator<<( std::ostream & str, const SourceManager & obj );
 
-
   public:
     /** Singleton access */
     static SourceManager_Ptr sourceManager();
@@ -77,6 +79,39 @@ namespace zypp
     /** Runtime unique numeric Source Id. */
     typedef Source_Ref::NumericId SourceId;
 
+  private:
+    /** exposition only */
+    typedef std::map<SourceId, Source_Ref> SourceMap;
+
+    /** \name Iterate over all (SourceId,Source_Ref) pairs. */
+    //@{
+    typedef SourceMap::const_iterator const_iterator;
+
+    const_iterator begin() const;
+
+    const_iterator end() const;
+    //@}
+
+  public:
+    /** \name Iterate over all known SourceIds. */
+    //@{
+    typedef MapKVIteratorTraits<SourceMap>::Key_const_iterator SourceId_const_iterator;
+
+    SourceId_const_iterator SourceId_begin() const;
+
+    SourceId_const_iterator SourceId_end() const;
+    //@}
+
+  public:
+    /** \name Iterate over all known Sources. */
+    //@{
+    typedef MapKVIteratorTraits<SourceMap>::Value_const_iterator Source_const_iterator;
+
+    Source_const_iterator Source_begin() const;
+
+    Source_const_iterator Source_end() const;
+    //@}
+
   public:
 
     /**
@@ -169,7 +204,7 @@ namespace zypp
      * Disable all registered sources
      */
     void disableAllSources();
-    
+
     /**
      * Helper function to disable all sources in the persistent
      * store on the given location. Does not manipulate with
index fb29f21..7cb82f8 100644 (file)
@@ -150,12 +150,12 @@ namespace zypp
           case TraceCADBase::CTOR:
           case TraceCADBase::PING:
           case TraceCADBase::DTOR:
-            std::cerr << what_r << self_r << " (" << self_r._ident << ")" << std::endl;
+            _DBG("DEBUG") << what_r << self_r << " (" << self_r._ident << ")" << std::endl;
             break;
 
           case TraceCADBase::COPYCTOR:
           case TraceCADBase::ASSIGN:
-            std::cerr << what_r << self_r << "( " << rhs_r << ")" << " (" << self_r._ident << ")" << std::endl;
+            _DBG("DEBUG") << what_r << self_r << "( " << rhs_r << ")" << " (" << self_r._ident << ")" << std::endl;
             break;
           }
       }
index 5b5ddd6..9761d0d 100644 (file)
@@ -134,9 +134,9 @@ namespace zypp
    * \see MapKVIteratorTraits
   */
   template<class _Pair>
-    struct GetPairFirst : public std::unary_function<_Pair, typename _Pair::first_type>
+    struct GetPairFirst : public std::unary_function<_Pair, const typename _Pair::first_type &>
     {
-      const typename _Pair::first_type & operator()( const _Pair pair_r ) const
+      const typename _Pair::first_type & operator()( const _Pair pair_r ) const
       { return pair_r.first; }
     };
 
@@ -144,9 +144,9 @@ namespace zypp
    * \see MapKVIteratorTraits
   */
   template<class _Pair>
-    struct GetPairSecond : public std::unary_function<_Pair, typename _Pair::second_type>
+    struct GetPairSecond : public std::unary_function<_Pair, const typename _Pair::second_type &>
     {
-      const typename _Pair::second_type & operator()( const _Pair pair_r ) const
+      const typename _Pair::second_type & operator()( const _Pair pair_r ) const
       { return pair_r.second; }
     };
 
@@ -161,18 +161,18 @@ namespace zypp
    * typedef std::map<K,V> MapType;
    *
    * // transform_iterator<GetPairFirst<MapType::value_type>,  MapType::const_iterator>
-   * typedef MapKVIteratorTraits<MapType>::Key_iterator MapTypeKey_iterator;
+   * typedef MapKVIteratorTraits<MapType>::Key_const_iterator MapTypeKey_iterator;
    * // transform_iterator<GetPairSecond<MapType::value_type>, MapType::const_iterator>
-   * typedef MapKVIteratorTraits<MapType>::Value_iterator  MapTypeValue_iterator;
+   * typedef MapKVIteratorTraits<MapType>::Value_const_iterator  MapTypeValue_iterator;
    *
    * // usage
    * MapType mymap;
    *
-   * MapTypeKey_iterator keyBegin( make_map_key_begin( mymap ) );
-   * MapTypeKey_iterator keyEnd  ( make_map_key_end( mymap ) );
+   * MapTypeKey_const_iterator keyBegin( make_map_key_begin( mymap ) );
+   * MapTypeKey_const_iterator keyEnd  ( make_map_key_end( mymap ) );
    *
-   * MapTypeKey_iterator valBegin( make_map_value_begin( mymap ) );
-   * MapTypeKey_iterator valEnd  ( make_map_value_end( mymap ) );
+   * MapTypeKey_const_iterator valBegin( make_map_value_begin( mymap ) );
+   * MapTypeKey_const_iterator valEnd  ( make_map_value_end( mymap ) );
    *
    * std::for_each( keyBegin, keyEnd, DoSomething() );
    * std::for_each( valBegin, valEnd, DoSomething() );
@@ -197,32 +197,32 @@ namespace zypp
       typedef typename _Map::key_type    KeyType;
       /** The key iterator type */
       typedef transform_iterator<GetPairFirst<typename MapType::value_type>,
-                                 typename MapType::const_iterator> Key_iterator;
+                                 typename MapType::const_iterator> Key_const_iterator;
       /** The maps value (mapped) type */
       typedef typename _Map::mapped_type ValueType;
       /** The value iterator type */
       typedef transform_iterator<GetPairSecond<typename MapType::value_type>,
-                                 typename MapType::const_iterator> Value_iterator;
+                                 typename MapType::const_iterator> Value_const_iterator;
     };
 
   /** Convenience to create the key iterator from container::begin() */
   template<class _Map>
-    inline typename MapKVIteratorTraits<_Map>::Key_iterator make_map_key_begin( const _Map & map_r )
+    inline typename MapKVIteratorTraits<_Map>::Key_const_iterator make_map_key_begin( const _Map & map_r )
     { return make_transform_iterator( map_r.begin(), GetPairFirst<typename _Map::value_type>() ); }
 
   /** Convenience to create the key iterator from container::end() */
   template<class _Map>
-    inline typename MapKVIteratorTraits<_Map>::Key_iterator make_map_key_end( const _Map & map_r )
+    inline typename MapKVIteratorTraits<_Map>::Key_const_iterator make_map_key_end( const _Map & map_r )
     { return make_transform_iterator( map_r.end(), GetPairFirst<typename _Map::value_type>() ); }
 
   /** Convenience to create the value iterator from container::begin() */
   template<class _Map>
-    inline typename MapKVIteratorTraits<_Map>::Value_iterator make_map_value_begin( const _Map & map_r )
+    inline typename MapKVIteratorTraits<_Map>::Value_const_iterator make_map_value_begin( const _Map & map_r )
     { return make_transform_iterator( map_r.begin(), GetPairSecond<typename _Map::value_type>() ); }
 
   /** Convenience to create the value iterator from container::end() */
   template<class _Map>
-    inline typename MapKVIteratorTraits<_Map>::Value_iterator make_map_value_end( const _Map & map_r )
+    inline typename MapKVIteratorTraits<_Map>::Value_const_iterator make_map_value_end( const _Map & map_r )
     { return make_transform_iterator( map_r.end(), GetPairSecond<typename _Map::value_type>() ); }
 
   /** \class function_output_iterator