complete patch classification
[platform/upstream/libzypp.git] / zypp / ui / Selectable.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ui/Selectable.h
10  *
11 */
12 #ifndef ZYPP_UI_SELECTABLE_H
13 #define ZYPP_UI_SELECTABLE_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/ReferenceCounted.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/base/Iterator.h"
21
22 #include "zypp/ui/SelectableTraits.h"
23 #include "zypp/ui/Status.h"
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28   ///////////////////////////////////////////////////////////////////
29   namespace ui
30   { /////////////////////////////////////////////////////////////////
31
32     DEFINE_PTR_TYPE(Selectable);
33
34     ///////////////////////////////////////////////////////////////////
35     //
36     //  CLASS NAME : Selectable
37     //
38     /** Collects PoolItems of same kind and name.
39      *
40      * Selectable is a status wrapper. That's why it offers the
41      * PoolItems ResObjects but hides their individual ResStatus.
42      * The ui::Status is calculated from (and transated to)
43      * PoolItems individual ResStatus values.
44      *
45      * \note There's one Selectable per installed item, in case more
46      * than one item is intalled.
47     */
48     class Selectable : public base::ReferenceCounted, private base::NonCopyable
49     {
50       friend std::ostream & operator<<( std::ostream & str, const Selectable & obj );
51
52     public:
53       typedef intrusive_ptr<Selectable>        Ptr;
54       typedef intrusive_ptr<const Selectable>  constPtr;
55
56       /** Iterates over ResObject::constPtr */
57       typedef SelectableTraits::available_iterator      available_iterator;
58       typedef SelectableTraits::available_size_type     available_size_type;
59
60       typedef SelectableTraits::installed_iterator      installed_iterator;
61       typedef SelectableTraits::installed_size_type     installed_size_type;
62
63     public:
64       /** The identifier.
65        * This is the solvables \ref name, \b except for packages and
66        * source packes, prefixed by it's \ref kind.
67        * \see \ref sat::Solvable.
68        */
69       IdString ident() const;
70
71       /** The ResObjects kind. */
72       ResObject::Kind kind() const;
73
74       /** The ResObjects name.  */
75       const std::string & name() const;
76
77       /**
78        * return the first Installed object
79        * of available
80        */
81       PoolItem installedObj() const;
82
83       /**
84        * \deprecated use installedObj
85        * PoolItem corresponding to the installed object.
86        */
87       ZYPP_DEPRECATED PoolItem installedPoolItem() const
88       { return installedObj(); }
89
90       /** Best among available objects.
91        + The user selected candiate, or a default.
92       */
93       PoolItem candidateObj() const;
94
95       /** PoolItem corresponding to the candidate object. */
96       ZYPP_DEPRECATED PoolItem candidatePoolItem() const
97       { return candidateObj(); }
98
99       /** Set a candidate (out of available objects).
100        * \return The new candidate, or NULL if choice was invalid
101        * (NULL or not among availableObjs). An invalid choice
102        * selects the default candidate.
103        */
104       PoolItem setCandidate( ResObject::constPtr byUser_r );
105
106       /** Best among all objects. */
107       PoolItem theObj() const;
108
109       ////////////////////////////////////////////////////////////////////////
110
111       /**
112        * Are there available objects?
113        */
114       bool availableEmpty() const;
115
116       /**
117        * Number of available objects.
118        */
119       available_size_type availableSize() const;
120
121       /**
122        * Number of available objects.
123        * \deprecated Use availableSize
124        */
125       ZYPP_DEPRECATED available_size_type availableObjs() const
126       { return availableSize(); }
127
128       /** */
129       available_iterator availableBegin() const;
130
131       /** */
132       available_iterator availableEnd() const;
133
134       ////////////////////////////////////////////////////////////////////////
135
136       /**
137        * Installed object iterators
138        */
139
140       /**
141        * Are there installed objects?
142        */
143       bool installedEmpty() const;
144
145       /**
146        * Number of available objects.
147        */
148       installed_size_type installedSize() const;
149
150       /** */
151       installed_iterator installedBegin() const;
152
153       /** */
154       installed_iterator installedEnd() const;
155
156       ////////////////////////////////////////////////////////////////////////
157
158     public:
159       /** \name Query for objects within this Selectable.
160       */
161       //@{
162       /** True if either installed or candidate object is present */
163       bool hasObject() const
164       { return (! installedEmpty()) || candidateObj(); }
165
166       /** True if installed object is present. */
167       bool hasInstalledObj() const
168       { return ! installedEmpty(); }
169
170       /** True if candidate object is present. */
171       bool hasCandidateObj() const
172       { return candidateObj(); }
173
174       /** True if installed and candidate object is present */
175       bool hasBothObjects() const
176       { return (! installedEmpty()) && candidateObj(); }
177
178       /** True if installed object is present but no candidate. */
179       bool hasInstalledObjOnly() const
180       { return (! installedEmpty()) && ! candidateObj(); }
181
182       /** True if candidate object is present but no installed. */
183       bool hasCandidateObjOnly() const
184       { return ( installedEmpty() ) && candidateObj(); }
185       //@}
186
187       /**
188        * True if this package has no replacement from
189        * the available repositories
190        */
191       bool isUnmaintained() const;
192
193       /** \name Classification of available patches (patterns, products).
194        * A patch is either \c not \c relevant, \c satisfied or \c broken.
195       */
196       //@{
197       /** Returns true for packages, because  packages are not
198        * classified by the solver.
199       */
200       bool isUndetermined() const;
201
202       /** Returns true if the patch is relevant which means that at least
203        *  one package of the patch is installed.
204        */
205       bool isRelevant() const;
206
207       /** Whether a relevant patchs requirements are met. */
208       bool isSatisfied() const;
209
210       /** Whether a relevant patchs requirements are broken. */
211       bool isBroken() const;
212
213       /** This includes still broken patches, as well as those already
214        *  selected to be installed.
215        * This is because already selected patches will be classified as
216        * \c satisfied.
217        */
218       bool isNeeded() const;
219       //@}
220
221      public:
222       /** \name Query objects fate in case of commit.
223       */
224       //@{
225       enum Fate {
226         TO_DELETE  = -1,
227         UNMODIFIED = 0,
228         TO_INSTALL = 1
229       };
230       /**  */
231       Fate fate() const;
232
233       /** True if either to delete or to install */
234       bool unmodified() const
235       { return fate() == UNMODIFIED; }
236
237       /** True if either to delete or to install */
238       bool toModify() const
239       { return fate() != UNMODIFIED; }
240
241       /** True if to delete */
242       bool toDelete() const
243       { return fate() == TO_DELETE; }
244
245       /** True if to install */
246       bool toInstall() const
247       { return fate() == TO_INSTALL; }
248       //@}
249
250     public:
251       /**
252        * \name Special inteface for Y2UI.
253        * \note This interface acts on \ref ResStatus::USER level.
254        * The \ref Status enum, and allowed state transitions are
255        * tightly related to the Y2UI. It might be not verry usefull
256        * outside the Y2UI.
257       */
258       //@{
259       /** Return the current Status */
260       Status status() const;
261
262       /**
263        * Try to set a new Status.
264        * Returns \c false if the transitions is not allowed.
265        */
266       bool setStatus( const Status state_r );
267
268       /** Try to set a new Status.
269        * Returns \c false if the transitions is not allowed.
270       */
271       ZYPP_DEPRECATED bool set_status( const Status state_r )
272       { return setStatus( state_r ); }
273
274       /** Return who caused the modification. */
275       ResStatus::TransactByValue modifiedBy() const;
276
277       /** Return value of LicenceConfirmed bit. */
278       bool hasLicenceConfirmed() const;
279
280       /** Set LicenceConfirmed bit. */
281       void setLicenceConfirmed( bool val_r = true );
282       //@}
283
284     public:
285       /** Implementation  */
286       class Impl;
287       typedef shared_ptr<Impl> Impl_Ptr;
288       /** Default ctor */
289       Selectable( Impl_Ptr pimpl_r );
290     private:
291       /** Dtor */
292       ~Selectable();
293     private:
294       /** Pointer to implementation */
295       RW_pointer<Impl> _pimpl;
296     };
297     ///////////////////////////////////////////////////////////////////
298
299     /** \relates Selectable Stream output */
300     std::ostream & operator<<( std::ostream & str, const Selectable & obj );
301
302     /** Solvable to Selectable transform functor.
303      * \relates Selectable
304      * \relates sat::SolvIterMixin
305      */
306     struct asSelectable
307     {
308       typedef Selectable_Ptr result_type;
309
310       Selectable_Ptr operator()( const sat::Solvable & solv_r ) const;
311
312       Selectable_Ptr operator()( const PoolItem & pi_r ) const
313       { return operator()( pi_r.satSolvable() ); }
314     };
315
316     /////////////////////////////////////////////////////////////////
317   } // namespace ui
318   ///////////////////////////////////////////////////////////////////
319   /////////////////////////////////////////////////////////////////
320 } // namespace zypp
321 ///////////////////////////////////////////////////////////////////
322 #endif // ZYPP_UI_SELECTABLE_H