ignore
[platform/upstream/libzypp.git] / zypp / SourceFeed.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/SourceFeed.h
10  *
11 */
12 #ifndef ZYPP_SOURCEFEED_H
13 #define ZYPP_SOURCEFEED_H
14
15 #include <iosfwd>
16 #include <set>
17
18 #include "zypp/base/PtrTypes.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   class ResPoolManager;
25   class Source_Ref;
26
27   ///////////////////////////////////////////////////////////////////
28   //
29   //    CLASS NAME : SourceFeed_Ref
30   //
31   /** Feed Sources into a ResPool.
32    * \todo Clean up implementation.
33   */
34   class SourceFeed_Ref
35   {
36     friend std::ostream & operator<<( std::ostream & str, const SourceFeed_Ref & obj );
37     typedef std::set<Source_Ref> ContainerT;
38
39   public:
40     /** Implementation  */
41     class Impl;
42
43     typedef ContainerT::size_type      size_type;
44     typedef ContainerT::iterator       iterator;
45     typedef ContainerT::const_iterator const_iterator;
46
47   public:
48     /** Default ctor */
49     SourceFeed_Ref( ResPoolManager pool_r );
50     /** Dtor */
51     ~SourceFeed_Ref();
52
53   public:
54
55     /**  Add one Source. */
56     void addSource( Source_Ref src_r )
57     {
58       ContainerT sources;
59       sources.insert( src_r );
60       insert( sources );
61     }
62
63     /** Add Sources from some container.  */
64     template <class _InputIterator>
65       void addSource( _InputIterator first_r, _InputIterator last_r )
66       {
67         ContainerT sources( first_r, last_r );
68         insert( sources );
69       }
70
71     // Add defaults from sourcemanager
72
73     // Set sources
74
75   public:
76
77     /** Remove a Source. */
78     void removeSource( Source_Ref src_r )
79     {
80       ContainerT sources;
81       sources.insert( src_r );
82       erase( sources );
83     }
84
85     /** Remove all Sources mentioned in container. */
86     template <class _InputIterator>
87       void removeSource( _InputIterator first_r, _InputIterator last_r )
88       {
89         ContainerT sources( first_r, last_r );
90         erase( sources );
91       }
92
93     /** Remove all Sources. */
94     void removeAllSources()
95     {
96       removeSource( sourceBegin(), sourceEnd() );
97     }
98
99   public:
100
101     /** Iterate and query */
102     const_iterator sourceBegin() const;
103     const_iterator sourceEnd() const;
104
105   private:
106
107     void insert( ContainerT & sources_r );
108
109     void erase( ContainerT & sources_r );
110
111   private:
112     /** Pointer to implementation: _Ref */
113     shared_ptr<Impl> _pimpl;
114   };
115   ///////////////////////////////////////////////////////////////////
116
117   /** \relates SourceFeed Stream output */
118   std::ostream & operator<<( std::ostream & str, const SourceFeed_Ref & obj );
119
120   /////////////////////////////////////////////////////////////////
121 } // namespace zypp
122 ///////////////////////////////////////////////////////////////////
123 #endif // ZYPP_SOURCEFEED_H