1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PoolItem.h
12 #ifndef ZYPP_POOLITEM_H
13 #define ZYPP_POOLITEM_H
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/ResObject.h"
20 #include "zypp/ResStatus.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 // CLASS NAME : PoolItem
37 /** Reference to a PoolItem connecting ResObject and ResStatus.
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).
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.
52 friend std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
59 /** Default ctor for use in std::container. */
62 /** Ctor looking up the \ref sat::Solvable in the \ref ResPool. */
63 explicit PoolItem( const sat::Solvable & solvable_r );
65 /** Ctor looking up the \ref ResObject in the \ref ResPool. */
66 explicit PoolItem( const ResObject::constPtr & resolvable_r );
72 /** \name Status related methods. */
74 /** Returns the current status. */
75 ResStatus & status() const;
78 ResStatus & statusReset() const;
81 /** \name Status validation.
82 * Performed for non-packages.
85 /** No validation is performed for packages. */
86 bool isUndetermined() const;
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.
91 bool isRelevant() const;
93 /** Whether a relevant items requirements are met. */
94 bool isSatisfied() const;
96 /** Whether a relevant items requirements are broken. */
97 bool isBroken() const;
99 /** This includes \c unlocked broken patches, as well as those already
100 * selected to be installed (otherwise classified as \c satisfied).
102 bool isNeeded() const;
104 /** Broken (needed) but locked patches. */
105 bool isUnwanted() const;
110 /** Return the \ref ResPool the item belongs to. */
111 ResPool pool() const;
113 /** Return the corresponding \ref sat::Solvable. */
114 sat::Solvable satSolvable() const
115 { return resolvable() ? resolvable()->satSolvable() : sat::Solvable::noSolvable; }
117 /** Return the buddy we share our status object with.
118 * A \ref Product e.g. may share it's status with an associated reference \ref Package.
120 sat::Solvable buddy() const;
123 /** Returns the ResObject::constPtr.
124 * \see \ref operator->
126 ResObject::constPtr resolvable() const;
128 /** Implicit conversion into ResObject::constPtr to
129 * support query filters operating on ResObject.
131 operator ResObject::constPtr() const
132 { return resolvable(); }
134 /** Forward \c -> access to ResObject. */
135 ResObject::constPtr operator->() const
136 { return resolvable(); }
138 /** Conversion to bool to allow pointer style tests
139 * for nonNULL \ref resolvable. */
140 explicit operator bool() const
141 { return bool(resolvable()); }
145 friend class pool::PoolImpl;
146 /** \ref PoolItem generator for \ref pool::PoolImpl. */
147 static PoolItem makePoolItem( const sat::Solvable & solvable_r );
148 /** Buddies are set by \ref pool::PoolImpl.*/
149 void setBuddy( sat::Solvable solv_r );
151 explicit PoolItem( Impl * implptr_r );
152 /** Pointer to implementation */
153 RW_pointer<Impl> _pimpl;
156 /** \name tmp hack for save/restore state. */
157 /** \todo get rid of it. */
159 friend class PoolItemSaver;
160 void saveState() const;
161 void restoreState() const;
162 bool sameState() const;
165 ///////////////////////////////////////////////////////////////////
167 /** \relates PoolItem Stream output */
168 std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
170 /** \relates PoolItem */
171 inline bool operator==( const PoolItem & lhs, const PoolItem & rhs )
172 { return lhs.resolvable() == rhs.resolvable(); }
174 /** \relates PoolItem */
175 inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs )
176 { return lhs.resolvable() == rhs; }
178 /** \relates PoolItem */
179 inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs )
180 { return lhs == rhs.resolvable(); }
183 /** \relates PoolItem */
184 inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs )
185 { return ! (lhs==rhs); }
187 /** \relates PoolItem */
188 inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs )
189 { return ! (lhs==rhs); }
191 /** \relates PoolItem */
192 inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
193 { return ! (lhs==rhs); }
196 /** \relates PoolItem Test for same content. */
197 inline bool identical( const PoolItem & lhs, const PoolItem & rhs )
198 { return lhs == rhs || lhs.satSolvable().identical( rhs.satSolvable() ); }
200 /** \relates PoolItem Test for same content. */
201 inline bool identical( const PoolItem & lhs, sat::Solvable rhs )
202 { return lhs.satSolvable().identical( rhs ); }
204 /** \relates PoolItem Test for same content. */
205 inline bool identical( sat::Solvable lhs, const PoolItem & rhs )
206 { return lhs.identical( rhs.satSolvable() ); }
209 /** \relates PoolItem Test for same name version release and arch. */
210 inline bool sameNVRA( const PoolItem & lhs, const PoolItem & rhs )
211 { return lhs == rhs || lhs.satSolvable().sameNVRA( rhs.satSolvable() ); }
213 /** \relates PoolItem Test for same name version release and arch. */
214 inline bool sameNVRA( const PoolItem & lhs, sat::Solvable rhs )
215 { return lhs.satSolvable().sameNVRA( rhs ); }
217 /** \relates PoolItem Test for same name version release and arch. */
218 inline bool sameNVRA( sat::Solvable lhs, const PoolItem & rhs )
219 { return lhs.sameNVRA( rhs.satSolvable() ); }
221 /** Solvable to PoolItem transform functor.
223 * \relates sat::SolvIterMixin
227 typedef PoolItem result_type;
229 PoolItem operator()( const sat::Solvable & solv_r ) const
230 { return PoolItem( solv_r ); }
233 /////////////////////////////////////////////////////////////////
235 ///////////////////////////////////////////////////////////////////
236 ///////////////////////////////////////////////////////////////////
238 { /////////////////////////////////////////////////////////////////
240 /** \relates zypp::PoolItem Order in std::container follows ResObject::constPtr.*/
242 inline bool less<zypp::PoolItem>::operator()( const zypp::PoolItem & lhs, const zypp::PoolItem & rhs ) const
243 { return lhs.resolvable() < rhs.resolvable(); }
245 /////////////////////////////////////////////////////////////////
247 ///////////////////////////////////////////////////////////////////
248 #endif // ZYPP_POOLITEM_H