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