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;
102 /** Return the \ref ResPool the item belongs to. */
103 ResPool pool() const;
105 /** Return the corresponding \ref sat::Solvable. */
106 sat::Solvable satSolvable() const
107 { return resolvable() ? resolvable()->satSolvable() : sat::Solvable::noSolvable; }
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.
112 sat::Solvable buddy() const;
115 /** Returns the ResObject::constPtr.
116 * \see \ref operator->
118 ResObject::constPtr resolvable() const;
120 /** Implicit conversion into ResObject::constPtr to
121 * support query filters operating on ResObject.
123 operator ResObject::constPtr() const
124 { return resolvable(); }
126 /** Forward \c -> access to ResObject. */
127 ResObject::constPtr operator->() const
128 { return resolvable(); }
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(); }
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 );
143 explicit PoolItem( Impl * implptr_r );
144 /** Pointer to implementation */
145 RW_pointer<Impl> _pimpl;
148 /** \name tmp hack for save/restore state. */
149 /** \todo get rid of it. */
151 friend class PoolItemSaver;
152 void saveState() const;
153 void restoreState() const;
154 bool sameState() const;
157 ///////////////////////////////////////////////////////////////////
159 /** \relates PoolItem Stream output */
160 std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
162 /** \relates PoolItem */
163 inline bool operator==( const PoolItem & lhs, const PoolItem & rhs )
164 { return lhs.resolvable() == rhs.resolvable(); }
166 /** \relates PoolItem */
167 inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs )
168 { return lhs.resolvable() == rhs; }
170 /** \relates PoolItem */
171 inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs )
172 { return lhs == rhs.resolvable(); }
175 /** \relates PoolItem */
176 inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs )
177 { return ! (lhs==rhs); }
179 /** \relates PoolItem */
180 inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs )
181 { return ! (lhs==rhs); }
183 /** \relates PoolItem */
184 inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
185 { return ! (lhs==rhs); }
187 /** Solvable to PoolItem transform functor.
189 * \relates sat::SolvIterMixin
193 typedef PoolItem result_type;
195 PoolItem operator()( const sat::Solvable & solv_r ) const
196 { return PoolItem( solv_r ); }
199 /////////////////////////////////////////////////////////////////
201 ///////////////////////////////////////////////////////////////////
202 ///////////////////////////////////////////////////////////////////
204 { /////////////////////////////////////////////////////////////////
206 /** \relates zypp::PoolItem Order in std::container follows ResObject::constPtr.*/
208 inline bool less<zypp::PoolItem>::operator()( const zypp::PoolItem & lhs, const zypp::PoolItem & rhs ) const
209 { return lhs.resolvable() < rhs.resolvable(); }
211 /////////////////////////////////////////////////////////////////
213 ///////////////////////////////////////////////////////////////////
214 #endif // ZYPP_POOLITEM_H