1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PoolItem.cc
13 #include "zypp/base/Logger.h"
15 #include "zypp/PoolItem.h"
16 #include "zypp/ResPool.h"
17 #include "zypp/Package.h"
18 #include "zypp/VendorAttr.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : PoolItem::Impl
30 /** PoolItem implementation. */
36 Impl( ResObject::constPtr res_r,
37 const ResStatus & status_r )
39 , _resolvable( res_r )
42 ResStatus & status() const
45 ResObject::constPtr resolvable() const
46 { return _resolvable; }
48 ResStatus & statusReset() const
50 _status.setLock( false, zypp::ResStatus::USER );
51 _status.resetTransact( zypp::ResStatus::USER );
57 bool isSatisfied() const
59 return _resolvable->isSatisfied();
62 bool isRelevant() const
64 return _resolvable->isRelevant();
69 return _resolvable->validate();
73 mutable ResStatus _status;
74 ResObject::constPtr _resolvable;
76 /** \name Poor man's save/restore state.
77 * \todo There may be better save/restore state strategies.
81 void saveState() const
82 { _savedStatus = _status; }
83 void restoreState() const
84 { _status = _savedStatus; }
85 bool sameState() const
87 if ( _status.getTransactValue() != _savedStatus.getTransactValue()
88 && !_status.isBySolver() )
90 if ( _status.isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
95 mutable ResStatus _savedStatus;
99 /** Offer default Impl. */
100 static shared_ptr<Impl> nullimpl()
102 static shared_ptr<Impl> _nullimpl( new Impl );
106 ///////////////////////////////////////////////////////////////////
108 /** \relates PoolItem::Impl Stream output */
109 inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
112 if (obj.resolvable())
113 str << *obj.resolvable();
119 ///////////////////////////////////////////////////////////////////
121 // CLASS NAME : PoolItem
123 ///////////////////////////////////////////////////////////////////
125 ///////////////////////////////////////////////////////////////////
127 // METHOD NAME : PoolItem::PoolItem
128 // METHOD TYPE : Ctor
131 : _pimpl( Impl::nullimpl() )
134 ///////////////////////////////////////////////////////////////////
136 // METHOD NAME : PoolItem::PoolItem
137 // METHOD TYPE : Ctor
139 PoolItem::PoolItem( const sat::Solvable & solvable_r )
140 : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
143 ///////////////////////////////////////////////////////////////////
145 // METHOD NAME : PoolItem::PoolItem
146 // METHOD TYPE : Ctor
148 PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
149 : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
152 ///////////////////////////////////////////////////////////////////
154 // METHOD NAME : PoolItem::PoolItem
155 // METHOD TYPE : Ctor
157 PoolItem::PoolItem( Impl * implptr_r )
158 : _pimpl( implptr_r )
161 ///////////////////////////////////////////////////////////////////
163 // METHOD NAME : PoolItem::makePoolItem
164 // METHOD TYPE : PoolItem
166 PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
167 { return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) ); }
169 ///////////////////////////////////////////////////////////////////
171 // METHOD NAME : PoolItem::~PoolItem
172 // METHOD TYPE : Dtor
174 PoolItem::~PoolItem()
177 ///////////////////////////////////////////////////////////////////
179 // METHOD NAME : PoolItem::pool
180 // METHOD TYPE : ResPool
182 ResPool PoolItem::pool() const
183 { return ResPool::instance(); }
185 ///////////////////////////////////////////////////////////////////
189 ///////////////////////////////////////////////////////////////////
191 ResStatus & PoolItem::status() const
192 { return _pimpl->status(); }
194 ResStatus & PoolItem::statusReset() const
195 { return _pimpl->statusReset(); }
197 bool PoolItem::isSatisfied() const
198 { return _pimpl->isSatisfied(); }
200 ResObject::constPtr PoolItem::resolvable() const
201 { return _pimpl->resolvable(); }
203 void PoolItem::saveState() const
204 { _pimpl->saveState(); }
206 void PoolItem::restoreState() const
207 { _pimpl->restoreState(); }
209 bool PoolItem::sameState() const
210 { return _pimpl->sameState(); }
212 /******************************************************************
214 ** FUNCTION NAME : operator<<
215 ** FUNCTION TYPE : std::ostream &
217 std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
219 return str << *obj._pimpl;
222 /////////////////////////////////////////////////////////////////
224 ///////////////////////////////////////////////////////////////////