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"
21 #include "zypp/sat/SolvableType.h"
22 #include "zypp/ResStatus.h"
24 ///////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 /// \brief Combining \ref sat::Solvable and \ref ResStatus.
36 /// The "real" PoolItem is usually somewhere in the ResPool. This is
37 /// a reference to it. All copies made will reference (and modify)
38 /// the same PoolItem. All changes via a PoolItem are immediately
39 /// visible in all copies (now COW).
41 /// \note PoolItem is a SolvableType, which provides direct access to
42 /// many of the underlying sat::Solvables properties.
43 /// \see \ref sat::SolvableType
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.
49 ///////////////////////////////////////////////////////////////////
50 class PoolItem : public sat::SolvableType<PoolItem>
52 friend std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
54 /** Default ctor for use in std::container. */
57 /** Ctor looking up the \ref sat::Solvable in the \ref ResPool. */
58 explicit PoolItem( const sat::Solvable & solvable_r );
60 /** Ctor looking up the \ref sat::Solvable in the \ref ResPool. */
61 template <class Derived>
62 explicit PoolItem( const SolvableType<Derived> & solvable_r )
63 : PoolItem( solvable_r.satSolvable() )
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 /** This is a \ref sat::SolvableType. */
115 explicit operator sat::Solvable() 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(); }
140 friend class pool::PoolImpl;
141 /** \ref PoolItem generator for \ref pool::PoolImpl. */
142 static PoolItem makePoolItem( const sat::Solvable & solvable_r );
143 /** Buddies are set by \ref pool::PoolImpl.*/
144 void setBuddy( const sat::Solvable & solv_r );
147 struct Impl; ///< Expose type only
149 explicit PoolItem( Impl * implptr_r );
150 /** Pointer to implementation */
151 RW_pointer<Impl> _pimpl;
154 /** \name tmp hack for save/restore state. */
155 /** \todo get rid of it. */
157 friend struct PoolItemSaver;
158 void saveState() const;
159 void restoreState() const;
160 bool sameState() const;
163 ///////////////////////////////////////////////////////////////////
165 /** \relates PoolItem Stream output */
166 std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
169 /** \relates PoolItem Required to disambiguate vs. (PoolItem,ResObject::constPtr) due to implicit PoolItem::operator ResObject::constPtr */
170 inline bool operator==( const PoolItem & lhs, const PoolItem & rhs )
171 { return lhs.resolvable() == rhs.resolvable(); }
173 /** \relates PoolItem Convenience compare */
174 inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs )
175 { return lhs.resolvable() == rhs; }
177 /** \relates PoolItem Convenience compare */
178 inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs )
179 { return lhs == rhs.resolvable(); }
182 /** \relates PoolItem Required to disambiguate vs. (PoolItem,ResObject::constPtr) due to implicit PoolItem::operator ResObject::constPtr */
183 inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs )
184 { return ! (lhs==rhs); }
186 /** \relates PoolItem Convenience compare */
187 inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs )
188 { return ! (lhs==rhs); }
190 /** \relates PoolItem Convenience compare */
191 inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
192 { return ! (lhs==rhs); }
194 /** Solvable to PoolItem transform functor.
196 * \relates sat::SolvIterMixin
200 typedef PoolItem result_type;
202 PoolItem operator()( const sat::Solvable & solv_r ) const
203 { return PoolItem( solv_r ); }
207 ///////////////////////////////////////////////////////////////////
208 #endif // ZYPP_POOLITEM_H