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();
68 mutable ResStatus _status;
69 ResObject::constPtr _resolvable;
71 /** \name Poor man's save/restore state.
72 * \todo There may be better save/restore state strategies.
76 void saveState() const
77 { _savedStatus = _status; }
78 void restoreState() const
79 { _status = _savedStatus; }
80 bool sameState() const
82 if ( _status.getTransactValue() != _savedStatus.getTransactValue()
83 && !_status.isBySolver() )
85 if ( _status.isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
90 mutable ResStatus _savedStatus;
94 /** Offer default Impl. */
95 static shared_ptr<Impl> nullimpl()
97 static shared_ptr<Impl> _nullimpl( new Impl );
101 ///////////////////////////////////////////////////////////////////
103 /** \relates PoolItem::Impl Stream output */
104 inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
107 if (obj.resolvable())
108 str << *obj.resolvable();
114 ///////////////////////////////////////////////////////////////////
116 // CLASS NAME : PoolItem
118 ///////////////////////////////////////////////////////////////////
120 ///////////////////////////////////////////////////////////////////
122 // METHOD NAME : PoolItem::PoolItem
123 // METHOD TYPE : Ctor
126 : _pimpl( Impl::nullimpl() )
129 ///////////////////////////////////////////////////////////////////
131 // METHOD NAME : PoolItem::PoolItem
132 // METHOD TYPE : Ctor
134 PoolItem::PoolItem( const sat::Solvable & solvable_r )
135 : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
138 ///////////////////////////////////////////////////////////////////
140 // METHOD NAME : PoolItem::PoolItem
141 // METHOD TYPE : Ctor
143 PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
144 : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
147 ///////////////////////////////////////////////////////////////////
149 // METHOD NAME : PoolItem::PoolItem
150 // METHOD TYPE : Ctor
152 PoolItem::PoolItem( Impl * implptr_r )
153 : _pimpl( implptr_r )
156 ///////////////////////////////////////////////////////////////////
158 // METHOD NAME : PoolItem::makePoolItem
159 // METHOD TYPE : PoolItem
161 PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
162 { return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) ); }
164 ///////////////////////////////////////////////////////////////////
166 // METHOD NAME : PoolItem::~PoolItem
167 // METHOD TYPE : Dtor
169 PoolItem::~PoolItem()
172 ///////////////////////////////////////////////////////////////////
174 // METHOD NAME : PoolItem::pool
175 // METHOD TYPE : ResPool
177 ResPool PoolItem::pool() const
178 { return ResPool::instance(); }
180 ///////////////////////////////////////////////////////////////////
184 ///////////////////////////////////////////////////////////////////
186 ResStatus & PoolItem::status() const
187 { return _pimpl->status(); }
189 ResStatus & PoolItem::statusReset() const
190 { return _pimpl->statusReset(); }
192 bool PoolItem::isSatisfied() const
193 { return _pimpl->isSatisfied(); }
195 ResObject::constPtr PoolItem::resolvable() const
196 { return _pimpl->resolvable(); }
198 void PoolItem::saveState() const
199 { _pimpl->saveState(); }
201 void PoolItem::restoreState() const
202 { _pimpl->restoreState(); }
204 bool PoolItem::sameState() const
205 { return _pimpl->sameState(); }
207 /******************************************************************
209 ** FUNCTION NAME : operator<<
210 ** FUNCTION TYPE : std::ostream &
212 std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
214 return str << *obj._pimpl;
217 /////////////////////////////////////////////////////////////////
219 ///////////////////////////////////////////////////////////////////