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/base/SafeBool.h"
20 #include "zypp/ResObject.h"
21 #include "zypp/ResStatus.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
36 // CLASS NAME : PoolItem
38 /** Reference to a PoolItem connecting ResObject and ResStatus.
40 * The "real" PoolItem is usg. somewhere in the ResPool. This is
41 * a reference to it. All copies made will reference (and modify)
42 * the same PoolItem. All changes via a PoolItem are immediately
43 * visible in all copies (now COW).
45 * \note Constness: Like pointer types, a <tt>const PoolItem</tt>
46 * does \b not refer to a <tt>const PoolItem</tt>. The reference is
47 * \c const, i.e. you can't change the refered PoolItem. The PoolItem
48 * (i.e. the status) is always mutable.
51 class PoolItem : protected base::SafeBool<PoolItem>
53 friend std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
60 /** Default ctor for use in std::container. */
63 /** Ctor looking up the \ref sat::Solvable in the \ref ResPool. */
64 explicit PoolItem( const sat::Solvable & solvable_r );
66 /** Ctor looking up the \ref ResObject in the \ref ResPool. */
67 explicit PoolItem( const ResObject::constPtr & resolvable_r );
73 /** \name Status related methods. */
75 /** Returns the current status. */
76 ResStatus & status() const;
79 ResStatus & statusReset() const;
82 /** \name Status validation.
83 * Performed for non-packages.
86 /** No validation is performed for packages. */
87 bool isUndetermined() const;
89 /** Returns true if the solvable is relevant which means e.g. for patches
90 * that at least one package of the patch is installed.
92 bool isRelevant() const;
94 /** Whether a relevant items requirements are met. */
95 bool isSatisfied() const;
97 /** Whether a relevant items requirements are broken. */
98 bool isBroken() const;
100 /** This includes \c unlocked broken patches, as well as those already
101 * selected to be installed (otherwise classified as \c satisfied).
103 bool isNeeded() const;
105 /** Broken (needed) but locked patches. */
106 bool isUnwanted() const;
111 /** Return the \ref ResPool the item belongs to. */
112 ResPool pool() const;
114 /** Return the corresponding \ref sat::Solvable. */
115 sat::Solvable satSolvable() const
116 { return resolvable() ? resolvable()->satSolvable() : sat::Solvable::noSolvable; }
118 /** Return the buddy we share our status object with.
119 * A \ref Product e.g. may share it's status with an associated reference \ref Package.
121 sat::Solvable buddy() const;
124 /** Returns the ResObject::constPtr.
125 * \see \ref operator->
127 ResObject::constPtr resolvable() const;
129 /** Implicit conversion into ResObject::constPtr to
130 * support query filters operating on ResObject.
132 operator ResObject::constPtr() const
133 { return resolvable(); }
135 /** Forward \c -> access to ResObject. */
136 ResObject::constPtr operator->() const
137 { return resolvable(); }
139 /** Conversion to bool to allow pointer style tests
140 * for nonNULL \ref resolvable. */
141 using base::SafeBool<PoolItem>::operator bool_type;
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 friend SafeBool<PoolItem>::operator bool_type() const;
157 bool boolTest() const
158 { return !!resolvable(); }
161 /** \name tmp hack for save/restore state. */
162 /** \todo get rid of it. */
164 friend class PoolItemSaver;
165 void saveState() const;
166 void restoreState() const;
167 bool sameState() const;
170 ///////////////////////////////////////////////////////////////////
172 /** \relates PoolItem Stream output */
173 std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
175 /** \relates PoolItem */
176 inline bool operator==( const PoolItem & lhs, const PoolItem & rhs )
177 { return lhs.resolvable() == rhs.resolvable(); }
179 /** \relates PoolItem */
180 inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs )
181 { return lhs.resolvable() == rhs; }
183 /** \relates PoolItem */
184 inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs )
185 { return lhs == rhs.resolvable(); }
188 /** \relates PoolItem */
189 inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs )
190 { return ! (lhs==rhs); }
192 /** \relates PoolItem */
193 inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs )
194 { return ! (lhs==rhs); }
196 /** \relates PoolItem */
197 inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
198 { return ! (lhs==rhs); }
201 /** \relates PoolItem Test for same content. */
202 inline bool identical( const PoolItem & lhs, const PoolItem & rhs )
203 { return lhs == rhs || lhs.satSolvable().identical( rhs.satSolvable() ); }
205 /** \relates PoolItem Test for same content. */
206 inline bool identical( const PoolItem & lhs, sat::Solvable rhs )
207 { return lhs.satSolvable().identical( rhs ); }
209 /** \relates PoolItem Test for same content. */
210 inline bool identical( sat::Solvable lhs, const PoolItem & rhs )
211 { return lhs.identical( rhs.satSolvable() ); }
214 /** \relates PoolItem Test for same name version release and arch. */
215 inline bool sameNVRA( const PoolItem & lhs, const PoolItem & rhs )
216 { return lhs == rhs || lhs.satSolvable().sameNVRA( rhs.satSolvable() ); }
218 /** \relates PoolItem Test for same name version release and arch. */
219 inline bool sameNVRA( const PoolItem & lhs, sat::Solvable rhs )
220 { return lhs.satSolvable().sameNVRA( rhs ); }
222 /** \relates PoolItem Test for same name version release and arch. */
223 inline bool sameNVRA( sat::Solvable lhs, const PoolItem & rhs )
224 { return lhs.sameNVRA( rhs.satSolvable() ); }
226 /** Solvable to PoolItem transform functor.
228 * \relates sat::SolvIterMixin
232 typedef PoolItem result_type;
234 PoolItem operator()( const sat::Solvable & solv_r ) const
235 { return PoolItem( solv_r ); }
238 /////////////////////////////////////////////////////////////////
240 ///////////////////////////////////////////////////////////////////
241 ///////////////////////////////////////////////////////////////////
243 { /////////////////////////////////////////////////////////////////
245 /** \relates zypp::PoolItem Order in std::container follows ResObject::constPtr.*/
247 inline bool less<zypp::PoolItem>::operator()( const zypp::PoolItem & lhs, const zypp::PoolItem & rhs ) const
248 { return lhs.resolvable() < rhs.resolvable(); }
250 /////////////////////////////////////////////////////////////////
252 ///////////////////////////////////////////////////////////////////
253 #endif // ZYPP_POOLITEM_H