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 /** Returns the current status. */
73 ResStatus & status() const;
76 ResStatus & statusReset() const;
78 /** Whether the items requirements are met. */
79 bool isSatisfied() const;
81 /** Whether the items requirements are broken. */
83 { return ! isSatisfied(); }
85 /** Returns true if the solvable is relevant which means e.G. for patches
86 * that at least one package of the patch is installed.
88 bool isRelevant() const;
91 /** Return the \ref ResPool the item belongs to. */
94 /** Return the corresponding \ref sat::Solvable. */
95 sat::Solvable satSolvable() const
96 { return resolvable() ? resolvable()->satSolvable() : sat::Solvable::noSolvable; }
99 /** Returns the ResObject::constPtr.
100 * \see \ref operator->
102 ResObject::constPtr resolvable() const;
104 /** Implicit conversion into ResObject::constPtr to
105 * support query filters operating on ResObject.
107 operator ResObject::constPtr() const
108 { return resolvable(); }
110 /** Forward \c -> access to ResObject. */
111 ResObject::constPtr operator->() const
112 { return resolvable(); }
114 /** Conversion to bool to allow pointer style tests
115 * for nonNULL \ref resolvable. */
116 operator ResObject::constPtr::unspecified_bool_type() const
117 { return resolvable(); }
120 friend class pool::PoolImpl;
121 /** \ref PoolItem generator for \ref pool::PoolImpl. */
122 static PoolItem makePoolItem( const sat::Solvable & solvable_r );
124 explicit PoolItem( Impl * implptr_r );
125 /** Pointer to implementation */
126 RW_pointer<Impl> _pimpl;
129 /** \name tmp hack for save/restore state. */
130 /** \todo get rid of it. */
132 friend class PoolItemSaver;
133 void saveState() const;
134 void restoreState() const;
135 bool sameState() const;
138 ///////////////////////////////////////////////////////////////////
140 /** \relates PoolItem Stream output */
141 std::ostream & operator<<( std::ostream & str, const PoolItem & obj );
143 /** \relates PoolItem */
144 inline bool operator==( const PoolItem & lhs, const PoolItem & rhs )
145 { return lhs.resolvable() == rhs.resolvable(); }
147 /** \relates PoolItem */
148 inline bool operator==( const PoolItem & lhs, const ResObject::constPtr & rhs )
149 { return lhs.resolvable() == rhs; }
151 /** \relates PoolItem */
152 inline bool operator==( const ResObject::constPtr & lhs, const PoolItem & rhs )
153 { return lhs == rhs.resolvable(); }
156 /** \relates PoolItem */
157 inline bool operator!=( const PoolItem & lhs, const PoolItem & rhs )
158 { return ! (lhs==rhs); }
160 /** \relates PoolItem */
161 inline bool operator!=( const PoolItem & lhs, const ResObject::constPtr & rhs )
162 { return ! (lhs==rhs); }
164 /** \relates PoolItem */
165 inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem & rhs )
166 { return ! (lhs==rhs); }
168 /** Solvable to PoolItem transform functor.
170 * \relates sat::SolvIterMixin
174 typedef PoolItem result_type;
176 PoolItem operator()( const sat::Solvable & solv_r ) const
177 { return PoolItem( solv_r ); }
180 /////////////////////////////////////////////////////////////////
182 ///////////////////////////////////////////////////////////////////
183 ///////////////////////////////////////////////////////////////////
185 { /////////////////////////////////////////////////////////////////
187 /** \relates zypp::PoolItem Order in std::container follows ResObject::constPtr.*/
189 inline bool less<zypp::PoolItem>::operator()( const zypp::PoolItem & lhs, const zypp::PoolItem & rhs ) const
190 { return lhs.resolvable() < rhs.resolvable(); }
192 /////////////////////////////////////////////////////////////////
194 ///////////////////////////////////////////////////////////////////
195 #endif // ZYPP_POOLITEM_H