ignore
[platform/upstream/libzypp.git] / zypp / ResPool.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResPool.h
10  *
11 */
12 #ifndef ZYPP_RESPOOL_H
13 #define ZYPP_RESPOOL_H
14
15 #include <iosfwd>
16
17 #include "zypp/pool/PoolTraits.h"
18 #include "zypp/base/Iterator.h"
19 #include "zypp/ResFilters.h"
20
21 ///////////////////////////////////////////////////////////////////
22 namespace zypp
23 { /////////////////////////////////////////////////////////////////
24
25   ///////////////////////////////////////////////////////////////////
26   //
27   //    CLASS NAME : ResPool
28   //
29   /** Access to ResObject pool.
30    *
31    * \note Filter iterators provided by ResPool are intended to
32    * operate on internal index tables for faster access. If the
33    * the index is not yet implemented, they are realized as
34    * an ordinary filter iterator. Do not provide filter iterators
35    * here, if there is no index table for it.
36   */
37   class ResPool
38   {
39     friend std::ostream & operator<<( std::ostream & str, const ResPool & obj );
40
41   public:
42     /** \ref zypp::pool::PoolItem */
43     typedef pool::PoolTraits::Item                       Item;
44     typedef pool::PoolTraits::size_type                  size_type;
45     typedef pool::PoolTraits::const_iterator             const_iterator;
46     typedef pool::PoolTraits::byName_iterator            byName_iterator;
47     typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
48     typedef pool::PoolTraits::AdditionalCapSet           AdditionalCapSet;
49
50   public:
51     /** Default ctor: empty pool */
52     ResPool();
53     /** Dtor */
54     ~ResPool();
55
56   public:
57     /**  */
58     bool empty() const;
59     /**  */
60     size_type size() const;
61
62   public:
63
64     /** \name Iterate through all ResObjects (all kinds). */
65     //@{
66     /** */
67     const_iterator begin() const;
68     /** */
69     const_iterator end() const;
70     //@}
71
72   public:
73     /** \name Iterate through all ResObjects of a certain kind. */
74     //@{
75     typedef resfilter::ByKind ByKind;
76     typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
77
78     byKind_iterator byKindBegin( const ResObject::Kind & kind_r ) const
79     { return make_filter_begin( ByKind(kind_r), *this ); }
80
81     template<class _Res>
82       byKind_iterator byKindBegin() const
83       { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
84
85
86     byKind_iterator byKindEnd( const ResObject::Kind & kind_r ) const
87     { return make_filter_end( ByKind(kind_r), *this ); }
88
89     template<class _Res>
90       byKind_iterator byKindEnd() const
91       { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
92     //@}
93
94   public:
95     /** \name Iterate through all ResObjects with a certain name (all kinds). */
96     //@{
97     byName_iterator byNameBegin( const std::string & name_r ) const;
98
99     byName_iterator byNameEnd( const std::string & name_r ) const;
100     //@}
101
102  public:
103    /** \name Iterate through all ResObjects which have at least
104     *  one Capability with index \a index_r in dependency \a depType_r.
105    */
106    //@{
107    byCapabilityIndex_iterator byCapabilityIndexBegin( const std::string & index_r, Dep depType_r ) const;
108
109    byCapabilityIndex_iterator byCapabilityIndexEnd( const std::string & index_r, Dep depType_r ) const;
110    //@}
111
112  public:
113    /** \name Handling addition capabilities in the pool in order for solving it in
114     *  a solver run. This is used for tasks like needing a package with the name "foo".
115     *  The solver has to evaluate a proper package by his own.
116     *
117     *  CAUTION: This has another semantic in the solver. The required resolvable has
118     *  been set for installation (in the pool) only AFTER a solver run.
119    */
120
121    /**
122     *  Handling additional requirement. E.G. need package "foo" and package 
123     *  "foo1" which has a greater version than 1.0:
124     *
125     *  \code
126     *  CapSet capset;
127     *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));    
128     *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
129     *
130     *  // The user is setting this capablility
131     *  ResPool::AdditionalCapSet aCapSet;
132     *  aCapSet[ResStatus::USER] = capset;
133     *
134     *  setAdditionalRequire( aCapSet );
135     *  \endcode
136     */
137    void setAdditionalRequire( const AdditionalCapSet & capset ) const;
138    AdditionalCapSet & additionalRequire() const;
139
140    /**
141     *  Handling additional conflicts. E.G. do not install anything which provides "foo":
142     *
143     *  \code
144     *  CapSet capset;    
145     *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
146     *
147     *  // The user is setting this capablility
148     *  ResPool::AdditionalCapSet aCapSet;
149     *  aCapSet[ResStatus::USER] = capset;
150     *
151     *  setAdditionalConflict( aCapSet );    
152     *  \endcode
153     */      
154    void setAdditionalConflict( const AdditionalCapSet & capset ) const;
155    AdditionalCapSet & additionaConflict() const;
156       
157    /**
158     *  Handling additional provides. This is used for ignoring a requirement.
159     *  e.G. Do ignore the requirement "foo":
160     *
161     *  \code
162     *  CapSet capset;    
163     *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
164     *
165     *  // The user is setting this capablility
166     *  ResPool::AdditionalCapSet aCapSet;
167     *  aCapSet[ResStatus::USER] = capset;
168     *
169     *  setAdditionalProvide( aCapSet );    
170     *  \endcode
171     */      
172    void setAdditionalProvide( const AdditionalCapSet & capset ) const;
173    AdditionalCapSet & additionaProvide() const;                  
174
175   private:
176     /** */
177     friend class ResPoolManager;
178     /** Ctor */
179     ResPool( pool::PoolTraits::Impl_constPtr impl_r );
180   private:
181     /** Const access to implementation. */
182     pool::PoolTraits::Impl_constPtr _pimpl;
183   };
184   ///////////////////////////////////////////////////////////////////
185
186   /** \todo rename class and eliminate typedef. */
187   typedef ResPool ResPool_Ref;
188
189   ///////////////////////////////////////////////////////////////////
190
191   /** \relates ResPool Stream output */
192   std::ostream & operator<<( std::ostream & str, const ResPool & obj );
193
194   /////////////////////////////////////////////////////////////////
195 } // namespace zypp
196 ///////////////////////////////////////////////////////////////////
197 #endif // ZYPP_RESPOOL_H