Deprecate MediaAccess::downloads (accidentally deleted)
[platform/upstream/libzypp.git] / zypp / PoolItem.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/PoolItem.h
10  *
11 */
12 #ifndef ZYPP_POOLITEM_H
13 #define ZYPP_POOLITEM_H
14
15 #include <iosfwd>
16 #include <functional>
17
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/ResObject.h"
20 #include "zypp/ResStatus.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   class ResPool;
27
28   namespace pool
29   {
30     class PoolImpl;
31   }
32
33   ///////////////////////////////////////////////////////////////////
34   //
35   //    CLASS NAME : PoolItem
36   //
37   /** Reference to a PoolItem connecting ResObject and ResStatus.
38    *
39    * The "real" PoolItem is usg. somewhere in the ResPool. This is
40    * a reference to it. All copies made will reference (and modify)
41    * the same PoolItem. All changes via a PoolItem are immediately
42    * visible in all copies (now COW).
43    *
44    * \note Constness: Like pointer types, a <tt>const PoolItem</tt>
45    * does \b not refer to a <tt>const PoolItem</tt>. The reference is
46    * \c const, i.e. you can't change the refered PoolItem. The PoolItem
47    * (i.e. the status) is always mutable.
48    *
49   */
50   class PoolItem
51   {
52     friend std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
53
54     public:
55       /** Implementation */
56       class Impl;
57
58     public:
59       /** Default ctor for use in std::container. */
60       PoolItem();
61
62       /** Ctor looking up the \ref sat::Solvable in the \ref ResPool. */
63       explicit PoolItem( const sat::Solvable & solvable_r );
64
65       /** Ctor looking up the \ref ResObject in the \ref ResPool. */
66       explicit PoolItem( const ResObject::constPtr & resolvable_r );
67
68       /** Dtor */
69       ~PoolItem();
70
71     public:
72       /** \name Status related methods. */
73       //@{
74       /** Returns the current status. */
75       ResStatus & status() const;
76
77       /** Reset status. */
78       ResStatus & statusReset() const;
79
80
81       /** \name Status validation.
82        * Performed for non-packages.
83       */
84       //@{
85       /** No validation is performed for packages. */
86       bool isUndetermined() const;
87
88       /** Returns true if the solvable is relevant which means e.g. for patches
89        *  that at least one package of the patch is installed.
90        */
91       bool isRelevant() const;
92
93       /** Whether a relevant items requirements are met. */
94       bool isSatisfied() const;
95
96       /** Whether a relevant items requirements are broken. */
97       bool isBroken() const;
98       //@}
99
100       //@}
101     public:
102       /** Return the \ref ResPool the item belongs to. */
103       ResPool pool() const;
104
105       /** Return the corresponding \ref sat::Solvable. */
106       sat::Solvable satSolvable() const
107       { return resolvable() ? resolvable()->satSolvable() : sat::Solvable::noSolvable; }
108
109       /** Return the buddy we share our status object with.
110        * A \ref Product e.g. may share it's status with an associated reference \ref Package.
111       */
112       sat::Solvable buddy() const;
113
114     public:
115       /** Returns the ResObject::constPtr.
116        * \see \ref operator->
117        */
118       ResObject::constPtr resolvable() const;
119
120       /** Implicit conversion into ResObject::constPtr to
121        *  support query filters operating on ResObject.
122        */
123       operator ResObject::constPtr() const
124       { return resolvable(); }
125
126       /** Forward \c -> access to ResObject. */
127       ResObject::constPtr operator->() const
128       { return resolvable(); }
129
130       /** Conversion to bool to allow pointer style tests
131        *  for nonNULL \ref resolvable. */
132       operator ResObject::constPtr::unspecified_bool_type() const
133       { return resolvable(); }
134
135     private:
136       friend class Impl;
137       friend class pool::PoolImpl;
138       /** \ref PoolItem generator for \ref pool::PoolImpl. */
139       static PoolItem makePoolItem( const sat::Solvable & solvable_r );
140       /** Buddies are set by \ref pool::PoolImpl.*/
141       void setBuddy( sat::Solvable solv_r );
142       /** internal ctor */
143       explicit PoolItem( Impl * implptr_r );
144       /** Pointer to implementation */
145       RW_pointer<Impl> _pimpl;
146
147     private:
148       /** \name tmp hack for save/restore state. */
149       /** \todo get rid of it. */
150       //@{
151       friend class PoolItemSaver;
152       void saveState() const;
153       void restoreState() const;
154       bool sameState() const;
155       //@}
156   };
157   ///////////////////////////////////////////////////////////////////
158
159   /** \relates PoolItem Stream output */
160   std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
161
162   /** \relates PoolItem */
163   inline bool operator==( const PoolItem & lhs, const PoolItem & rhs )
164   { return lhs.resolvable() == rhs.resolvable(); }
165
166   /** \relates PoolItem */
167   inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs )
168   { return lhs.resolvable() == rhs; }
169
170   /** \relates PoolItem */
171   inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs )
172   { return lhs == rhs.resolvable(); }
173
174
175   /** \relates PoolItem */
176   inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs )
177   { return ! (lhs==rhs); }
178
179   /** \relates PoolItem */
180   inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs )
181   { return ! (lhs==rhs); }
182
183   /** \relates PoolItem */
184   inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
185   { return ! (lhs==rhs); }
186
187   /** Solvable to PoolItem transform functor.
188    * \relates PoolItem
189    * \relates sat::SolvIterMixin
190    */
191   struct asPoolItem
192   {
193     typedef PoolItem result_type;
194
195     PoolItem operator()( const sat::Solvable & solv_r ) const
196     { return PoolItem( solv_r ); }
197   };
198
199   /////////////////////////////////////////////////////////////////
200 } // namespace zypp
201 ///////////////////////////////////////////////////////////////////
202 ///////////////////////////////////////////////////////////////////
203 namespace std
204 { /////////////////////////////////////////////////////////////////
205
206   /** \relates zypp::PoolItem Order in std::container follows ResObject::constPtr.*/
207   template<>
208     inline bool less<zypp::PoolItem>::operator()( const zypp::PoolItem & lhs, const zypp::PoolItem & rhs ) const
209     { return lhs.resolvable() < rhs.resolvable(); }
210
211   /////////////////////////////////////////////////////////////////
212 } // namespace zypp
213 ///////////////////////////////////////////////////////////////////
214 #endif // ZYPP_POOLITEM_H