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 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : PoolItem_Ref
30 /** Reference to a PoolItem conecting ResObject and ResStatus.
32 * The "real" PoolItem is usg. somwhere in the ResPool. This is
33 * a reference to it. All copies made will reference (and modify)
34 * the same PoolItem. All changes via a PoolItem_Ref are immediately
35 * visible in all copies (now COW).
37 * \note Constnes: Like pointer types, a <tt>const PoolItem_Ref</tt>
38 * does \b not refer to a <tt>const PoolItem</tt>. The reference is
39 * \c const, i.e. you can't change the refered PoolItem. The PoolItem
40 * (i.e. the status) is always mutable.
45 friend std::ostream & operator<<( std::ostream & str, const PoolItem_Ref & obj );
52 /** Default ctor for use in std::container. */
57 PoolItem_Ref( ResObject::constPtr res_r );
60 PoolItem_Ref( ResObject::constPtr res_r, const ResStatus & status_r );
66 /** Returns the current status. */
67 ResStatus & status() const;
69 /** Reset status (applies autoprotection). */
70 ResStatus & statusReset() const;
72 /** Returns the ResObject::constPtr.
73 * \see \ref operator->
75 ResObject::constPtr resolvable() const;
78 /** Implicit conversion into ResObject::constPtr to
79 * support query filters operating on ResObject.
81 operator ResObject::constPtr() const
82 { return resolvable(); }
84 /** Forward \c -> access to ResObject. */
85 ResObject::constPtr operator->() const
86 { return resolvable(); }
88 /** Conversion to bool to allow pointer style tests
89 * for nonNULL \ref resolvable. */
90 operator ResObject::constPtr::unspecified_bool_type() const
91 { return resolvable(); }
94 /** Pointer to implementation */
95 RW_pointer<Impl> _pimpl;
98 /** \name tmp hack for save/restore state. */
99 /** \todo get rid of it. */
101 friend class PoolItemSaver;
102 void saveState() const;
103 void restoreState() const;
104 bool sameState() const;
107 ///////////////////////////////////////////////////////////////////
109 typedef PoolItem_Ref PoolItem;
111 /** \relates PoolItem_Ref Stream output */
112 std::ostream & operator<<( std::ostream & str, const PoolItem_Ref & obj );
114 /** \relates PoolItem_Ref */
115 inline bool operator==( const PoolItem_Ref & lhs, const PoolItem_Ref & rhs )
116 { return lhs.resolvable() == rhs.resolvable(); }
118 /** \relates PoolItem_Ref */
119 inline bool operator==( const PoolItem_Ref & lhs, const ResObject::constPtr & rhs )
120 { return lhs.resolvable() == rhs; }
122 /** \relates PoolItem_Ref */
123 inline bool operator==( const ResObject::constPtr & lhs, const PoolItem_Ref & rhs )
124 { return lhs == rhs.resolvable(); }
127 /** \relates PoolItem_Ref */
128 inline bool operator!=( const PoolItem_Ref & lhs, const PoolItem_Ref & rhs )
129 { return ! (lhs==rhs); }
131 /** \relates PoolItem_Ref */
132 inline bool operator!=( const PoolItem_Ref & lhs, const ResObject::constPtr & rhs )
133 { return ! (lhs==rhs); }
135 /** \relates PoolItem_Ref */
136 inline bool operator!=( const ResObject::constPtr & lhs, const PoolItem_Ref & rhs )
137 { return ! (lhs==rhs); }
139 /////////////////////////////////////////////////////////////////
141 ///////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////
144 { /////////////////////////////////////////////////////////////////
146 /** \relates zypp::PoolItem_Ref Order in std::container follows ResObject::constPtr.*/
148 inline bool less<zypp::PoolItem_Ref>::operator()( const zypp::PoolItem_Ref & lhs, const zypp::PoolItem_Ref & rhs ) const
149 { return lhs.resolvable() < rhs.resolvable(); }
151 /////////////////////////////////////////////////////////////////
153 ///////////////////////////////////////////////////////////////////
154 #endif // ZYPP_POOLITEM_H