Fix Werrors with GCC-14.1.0
[platform/upstream/libzypp.git] / zypp / ui / Selectable.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ui/Selectable.cc
10  *
11 */
12 #include <iostream>
13 //#include <zypp/base/Logger.h>
14
15 #include <zypp/ui/Selectable.h>
16 #include <zypp/ui/SelectableImpl.h>
17 #include <zypp/ResPool.h>
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22   ///////////////////////////////////////////////////////////////////
23   namespace ui
24   { /////////////////////////////////////////////////////////////////
25
26     IMPL_PTR_TYPE(Selectable);
27
28     Selectable::Ptr Selectable::get( const pool::ByIdent & ident_r )
29     { return ResPool::instance().proxy().lookup( ident_r ); }
30
31     ///////////////////////////////////////////////////////////////////
32     //
33     //  METHOD NAME : Selectable::Selectable
34     //  METHOD TYPE : Ctor
35     //
36     Selectable::Selectable( Impl_Ptr pimpl_r )
37     : _pimpl( pimpl_r )
38     {}
39
40     ///////////////////////////////////////////////////////////////////
41     //
42     //  METHOD NAME : Selectable::~Selectable
43     //  METHOD TYPE : Dtor
44     //
45     Selectable::~Selectable()
46     {}
47
48     ///////////////////////////////////////////////////////////////////
49     //
50     // Forward to implementation.
51     // Restrict PoolItems to ResObject::constPtr!
52     //
53     ///////////////////////////////////////////////////////////////////
54
55     IdString Selectable::ident() const
56     { return _pimpl->ident(); }
57
58     ResKind Selectable::kind() const
59     { return _pimpl->kind(); }
60
61     const std::string & Selectable::name() const
62     { return _pimpl->name(); }
63
64     Status Selectable::status() const
65     { return _pimpl->status(); }
66
67     bool Selectable::setStatus( Status state_r, ResStatus::TransactByValue causer_r )
68     { return _pimpl->setStatus( state_r, causer_r ); }
69
70     PoolItem Selectable::installedObj() const
71     { return _pimpl->installedObj(); }
72
73     PoolItem Selectable::candidateObj() const
74     { return _pimpl->candidateObj(); }
75
76     PoolItem Selectable::candidateObjFrom( Repository repo_r ) const
77     { return _pimpl->candidateObjFrom( repo_r ); }
78
79     PoolItem Selectable::updateCandidateObj() const
80     { return _pimpl->updateCandidateObj(); }
81
82     PoolItem Selectable::highestAvailableVersionObj() const
83     { return _pimpl->highestAvailableVersionObj(); }
84
85     bool Selectable::identIsAutoInstalled() const
86     { return _pimpl->identIsAutoInstalled(); }
87
88     bool Selectable::identicalAvailable( const PoolItem & rhs ) const
89     { return _pimpl->identicalAvailable( rhs ); }
90
91     bool Selectable::identicalInstalled( const PoolItem & rhs ) const
92     { return _pimpl->identicalInstalled( rhs ); }
93
94     PoolItem Selectable::identicalAvailableObj( const PoolItem & rhs ) const
95     { return _pimpl->identicalAvailableObj( rhs ); }
96
97     PoolItem Selectable::identicalInstalledObj( const PoolItem & rhs ) const
98     { return _pimpl->identicalInstalledObj( rhs ); }
99
100     PoolItem Selectable::setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
101     { return _pimpl->setCandidate( newCandidate_r, causer_r ); }
102
103     PoolItem Selectable::setCandidate( ResObject::constPtr newCandidate_r, ResStatus::TransactByValue causer_r )
104     { return _pimpl->setCandidate( PoolItem( newCandidate_r ), causer_r ); }
105
106     bool Selectable::setOnSystem( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r )
107     {
108       if ( identicalInstalled( newCandidate_r ) )
109         return setFate( UNMODIFIED, causer_r );
110       return setCandidate( newCandidate_r, causer_r ) && setFate( TO_INSTALL, causer_r );
111     }
112
113     PoolItem Selectable::theObj() const
114     { return _pimpl->theObj(); }
115
116     ////////////////////////////////////////////////////////////////////////
117
118     bool Selectable::availableEmpty() const
119     { return _pimpl->availableEmpty(); }
120
121     Selectable::available_size_type Selectable::availableSize() const
122     { return _pimpl->availableSize(); }
123
124     Selectable::available_iterator Selectable::availableBegin() const
125     { return _pimpl->availableBegin(); }
126
127     Selectable::available_iterator Selectable::availableEnd() const
128     { return _pimpl->availableEnd(); }
129
130     ////////////////////////////////////////////////////////////////////////
131
132     bool Selectable::installedEmpty() const
133     { return _pimpl->installedEmpty(); }
134
135     Selectable::installed_size_type Selectable::installedSize() const
136     { return _pimpl->installedSize(); }
137
138     Selectable::installed_iterator Selectable::installedBegin() const
139     { return _pimpl->installedBegin(); }
140
141     Selectable::installed_iterator Selectable::installedEnd() const
142     { return _pimpl->installedEnd(); }
143
144     ////////////////////////////////////////////////////////////////////////
145
146     bool Selectable::picklistEmpty() const
147     { return _pimpl->picklistEmpty();  }
148
149     Selectable::picklist_size_type Selectable::picklistSize() const
150     { return _pimpl->picklistSize(); }
151
152     Selectable::picklist_iterator Selectable::picklistBegin() const
153     { return _pimpl->picklistBegin(); }
154
155     Selectable::picklist_iterator Selectable::picklistEnd() const
156     { return _pimpl->picklistEnd(); }
157
158     Selectable::picklist_size_type Selectable::picklistPos( const PoolItem & pi_r ) const
159     { return picklistPos( pi_r.satSolvable() ); }
160
161     Selectable::picklist_size_type Selectable::picklistPos( const sat::Solvable & solv_r ) const
162     {
163       picklist_size_type idx = picklist_size_type(0);
164       for ( const auto & pi : picklist() )
165       {
166         if ( pi == solv_r )
167           return idx;
168         ++idx;
169       }
170       return picklistNoPos;
171     }
172
173     ////////////////////////////////////////////////////////////////////////
174
175     bool Selectable::hasRetracted() const
176     { return _pimpl->hasRetracted(); }
177
178     bool Selectable::hasRetractedInstalled() const
179     { return _pimpl->hasRetractedInstalled(); }
180
181     bool Selectable::isUnmaintained() const
182     { return _pimpl->isUnmaintained(); }
183
184     bool Selectable::multiversionInstall() const
185     { return _pimpl->multiversionInstall(); }
186
187     bool Selectable::pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r )
188     { return _pimpl->pickInstall( pi_r, causer_r, yesno_r ); }
189
190     bool Selectable::pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r )
191     { return _pimpl->pickDelete( pi_r, causer_r, yesno_r ); }
192
193     Status Selectable::pickStatus( const PoolItem & pi_r ) const
194     { return _pimpl->pickStatus( pi_r ); }
195
196     bool Selectable::setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r )
197     { return _pimpl->setPickStatus( pi_r, state_r, causer_r ); }
198
199     ////////////////////////////////////////////////////////////////////////
200
201     bool Selectable::isUndetermined() const
202     { return _pimpl->isUndetermined(); }
203
204     bool Selectable::isRelevant() const
205     { return _pimpl->isRelevant(); }
206
207     bool Selectable::isSatisfied() const
208     { return _pimpl->isSatisfied(); }
209
210     bool Selectable::isBroken() const
211     { return _pimpl->isBroken(); }
212
213     bool Selectable::isNeeded() const
214     {
215       return fate() == TO_INSTALL || ( ! locked() && isBroken() );
216     }
217
218     bool Selectable::isUnwanted() const
219     {
220       return locked() && isBroken() ;
221     }
222
223     ResStatus::TransactByValue Selectable::modifiedBy() const
224     { return _pimpl->modifiedBy(); }
225
226     bool Selectable::hasLicenceConfirmed() const
227     { return _pimpl->hasLicenceConfirmed(); }
228
229     void Selectable::setLicenceConfirmed( bool val_r )
230     { _pimpl->setLicenceConfirmed( val_r ); }
231
232     bool Selectable::hasLocks() const
233     { return  _pimpl->hasLocks(); }
234
235     Selectable::Fate Selectable::fate() const
236     {
237       switch ( status() ) {
238       case S_Update:
239       case S_Install:
240       case S_AutoUpdate:
241       case S_AutoInstall:
242         return TO_INSTALL;
243         break;
244
245       case S_Del:
246       case S_AutoDel:
247         return TO_DELETE;
248         break;
249
250       case S_Protected:
251       case S_Taboo:
252       case S_KeepInstalled:
253       case S_NoInst:
254         break;
255       }
256       return UNMODIFIED;
257     };
258
259     bool Selectable::setFate( Fate fate_r, ResStatus::TransactByValue causer_r )
260     {
261       switch ( fate_r )
262       {
263         case TO_INSTALL:
264           return setStatus( hasInstalledObj() ? S_Update : S_Install, causer_r );
265           break;
266
267         case TO_DELETE:
268           return setStatus( S_Del, causer_r );
269           break;
270
271         case UNMODIFIED:
272           switch ( status() ) {
273             case S_Protected:
274             case S_Taboo:
275               return true;
276               break;
277             default:
278               return setStatus( hasInstalledObj() ? S_KeepInstalled : S_NoInst, causer_r );
279               break;
280           }
281           break;
282       }
283       return false;
284     }
285
286     bool Selectable::setInstalled( ResStatus::TransactByValue causer_r )
287     {
288       return( hasInstalledObj() || setStatus( S_Install, causer_r ) );
289     }
290
291     bool Selectable::setUpToDate( ResStatus::TransactByValue causer_r )
292     {
293       if ( ! hasInstalledObj() )
294         return setStatus( S_Install, causer_r );
295
296       PoolItem cand( candidateObj() );
297       if ( ! cand )
298         return true;
299
300       return( installedObj()->edition() >= cand->edition()
301               || setStatus( S_Update, causer_r ) );
302     }
303
304     bool Selectable::setDeleted( ResStatus::TransactByValue causer_r )
305     {
306       return( ! hasInstalledObj() || setStatus( S_Del, causer_r ) );
307     }
308
309     /******************************************************************
310     **
311     **  FUNCTION NAME : operator<<
312     **  FUNCTION TYPE : std::ostream &
313     */
314     std::ostream & operator<<( std::ostream & str, const Selectable & obj )
315     { return str << *(obj._pimpl); }
316
317     std::ostream & dumpOn( std::ostream & str, const Selectable & obj )
318     { return dumpOn( str, *(obj._pimpl) ); }
319
320     /////////////////////////////////////////////////////////////////
321   } // namespace ui
322   ///////////////////////////////////////////////////////////////////
323   /////////////////////////////////////////////////////////////////
324 } // namespace zypp
325 ///////////////////////////////////////////////////////////////////