Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / ResStatus.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResStatus.h
10  *
11 */
12 #ifndef ZYPP_RESSTATUS_H
13 #define ZYPP_RESSTATUS_H
14
15 #include <inttypes.h>
16 #include <iosfwd>
17 #include "zypp/Bit.h"
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   namespace resstatus
24   {
25     class UserLockQueryManip;
26     class StatusBackup;
27   }
28
29   ///////////////////////////////////////////////////////////////////
30   //
31   //    CLASS NAME : ResStatus
32   //
33   /** Status bitfield.
34    *
35    * \li \c StateField Whether the resolvable is or uninstalled (available).
36    * \li \c ValidateField Validate status computed by the solver as
37    *        nonrelevant: it is unimportant for the user
38    *        satisfied: it important nothing has to be done
39    *        broken: it is incomplete. So e.g. an update is needed
40    * \li \c TransactField Whether to transact this resolvable
41    *        (delete if installed install if uninstalled).
42    *        In case the resolvable is locked, only USER may modify the
43    *        transact bit.
44    * \li \c TransactByField Who triggered the transaction. Transaction
45    *        bit may be reset by higer levels only.
46    * \li \c TransactDetailField Reason why the Resolvable transacts.
47    *        Splitted into \c InstallDetailValue and \c RemoveDetailValue
48    *        dependent on the kind of transaction.
49    * \li \c WeakField The solvable will be recommended/suggested by
50    *        a to be installed/deleted solvable.
51    *
52   */
53   class ResStatus
54   {
55     friend std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
56     friend bool operator==( const ResStatus & lhs, const ResStatus & rhs );
57
58   public:
59     /** \name BitField range definitions.
60      *
61      * \note Enlarge FieldType if more bit's needed. It's not yet
62      * checked by the compiler.
63      */
64     //@{
65     typedef uint16_t FieldType;
66     typedef bit::BitField<FieldType> BitFieldType;
67     // Bit Ranges within FieldType defined by 1st bit and size:
68     typedef bit::Range<FieldType,0,                          1> StateField;
69     typedef bit::Range<FieldType,StateField::end,            2> ValidateField;
70     typedef bit::Range<FieldType,ValidateField::end,         2> TransactField;
71     typedef bit::Range<FieldType,TransactField::end,         2> TransactByField;
72     typedef bit::Range<FieldType,TransactByField::end,       2> TransactDetailField;
73     typedef bit::Range<FieldType,TransactDetailField::end,   1> LicenceConfirmedField;
74     typedef bit::Range<FieldType,LicenceConfirmedField::end, 4> WeakField;
75     typedef bit::Range<FieldType,WeakField::end,             1> UserLockQueryField; // internal
76     // enlarge FieldType if more bit's needed. It's not yet
77     // checked by the compiler.
78     //@}
79   public:
80
81     /** \name Status values.
82      *
83      * Each enum corresponds to a BitField range.
84      * \note Take care that enumerator values actually fit into
85      * the corresponding field. It's not yet checked by the compiler.
86      */
87     //@{
88     enum StateValue
89       {
90         UNINSTALLED = bit::RangeValue<StateField,0>::value,
91         INSTALLED   = bit::RangeValue<StateField,1>::value
92       };
93     enum ValidateValue
94       {
95         UNDETERMINED = bit::RangeValue<ValidateField,0>::value,
96         BROKEN       = bit::RangeValue<ValidateField,1>::value,
97         SATISFIED    = bit::RangeValue<ValidateField,2>::value,
98         NONRELEVANT  = bit::RangeValue<ValidateField,3>::value
99       };
100     enum TransactValue
101       {
102         KEEP_STATE = bit::RangeValue<TransactField,0>::value,
103         LOCKED     = bit::RangeValue<TransactField,1>::value, // locked, must not transact
104         TRANSACT   = bit::RangeValue<TransactField,2>::value  // transact according to state
105       };
106     enum TransactByValue
107       {
108         SOLVER    = bit::RangeValue<TransactByField,0>::value,
109         APPL_LOW  = bit::RangeValue<TransactByField,1>::value,
110         APPL_HIGH = bit::RangeValue<TransactByField,2>::value,
111         USER      = bit::RangeValue<TransactByField,3>::value
112       };
113
114     enum DetailValue
115       {
116         /** Detail for no transact, i.e. reset any Install/RemoveDetailValue. */
117         NO_DETAIL = bit::RangeValue<TransactDetailField,0>::value,
118       };
119     enum InstallDetailValue
120       {
121         EXPLICIT_INSTALL = bit::RangeValue<TransactDetailField,0>::value,
122         SOFT_INSTALL     = bit::RangeValue<TransactDetailField,1>::value
123       };
124     enum RemoveDetailValue
125       {
126         EXPLICIT_REMOVE = bit::RangeValue<TransactDetailField,0>::value,
127         SOFT_REMOVE     = bit::RangeValue<TransactDetailField,1>::value,
128         DUE_TO_OBSOLETE = bit::RangeValue<TransactDetailField,2>::value,
129         DUE_TO_UPGRADE  = bit::RangeValue<TransactDetailField,3>::value
130       };
131
132     enum LicenceConfirmedValue
133       {
134         LICENCE_UNCONFIRMED = bit::RangeValue<LicenceConfirmedField,0>::value,
135         LICENCE_CONFIRMED   = bit::RangeValue<LicenceConfirmedField,1>::value
136       };
137
138     enum WeakValue      // Unlike the other fields those are BITS that may be or'ed!
139       {
140         NO_WEAK                 = bit::RangeValue<WeakField,0>::value,
141         SUGGESTED               = bit::RangeValue<WeakField,1<<0>::value,
142         RECOMMENDED             = bit::RangeValue<WeakField,1<<1>::value,
143         ORPHANED                = bit::RangeValue<WeakField,1<<2>::value,
144         UNNEEDED                = bit::RangeValue<WeakField,1<<3>::value
145       };
146
147     enum UserLockQuery // internal
148       {
149         USERLOCK_NOMATCH        = bit::RangeValue<UserLockQueryField,0>::value,
150         USERLOCK_MATCH          = bit::RangeValue<UserLockQueryField,1>::value
151       };
152     //@}
153
154   public:
155
156     /** Default ctor. */
157     ResStatus();
158
159     /** Ctor setting the initial . */
160     ResStatus( bool isInstalled_r );
161
162     /** Dtor. */
163     ~ResStatus();
164
165     /** Debug helper returning the bitfield.
166      * It's save to expose the bitfield, as it can't be used to
167      * recreate a ResStatus. So it is not possible to bypass
168      * transition rules.
169     */
170     BitFieldType bitfield() const
171     { return _bitfield; }
172
173   public:
174
175     bool isLicenceConfirmed() const
176     { return fieldValueIs<LicenceConfirmedField>( LICENCE_CONFIRMED ); }
177
178     void setLicenceConfirmed( bool toVal_r = true )
179     { fieldValueAssign<LicenceConfirmedField>( toVal_r ? LICENCE_CONFIRMED : LICENCE_UNCONFIRMED ); }
180
181   public:
182     bool isRecommended() const
183     { return _bitfield.test( RECOMMENDED ); }
184
185     bool isSuggested() const
186     { return _bitfield.test( SUGGESTED ); }
187
188     bool isOrphaned() const
189     { return _bitfield.test( ORPHANED ); }
190
191     bool isUnneeded() const
192     { return _bitfield.test( UNNEEDED ); }
193
194     bool hasWeak() const
195     { return ! fieldValueIs<WeakField>( NO_WEAK ); }
196
197     void resetWeak()
198     { return fieldValueAssign<WeakField>( NO_WEAK ); }
199
200     void setRecommended( bool toVal_r = true )
201     { _bitfield.set( RECOMMENDED, toVal_r ); }
202
203     void setSuggested( bool toVal_r = true )
204     { _bitfield.set( SUGGESTED, toVal_r ); }
205
206     void setOrphaned( bool toVal_r = true )
207     { _bitfield.set( ORPHANED, toVal_r ); }
208
209     void setUnneeded( bool toVal_r = true )
210     { _bitfield.set( UNNEEDED, toVal_r ); }
211
212   public:
213     ValidateValue validate() const
214     { return (ValidateValue)_bitfield.value<ValidateField>(); }
215
216     bool isUndetermined() const
217     { return fieldValueIs<ValidateField>( UNDETERMINED ); }
218
219     bool isSatisfied() const
220     { return fieldValueIs<ValidateField>( SATISFIED ); }
221
222     bool isBroken() const
223     { return fieldValueIs<ValidateField>( BROKEN ); }
224
225     bool isNonRelevant() const
226     { return fieldValueIs<ValidateField>( NONRELEVANT ); }
227
228   public:
229     // These two are IMMUTABLE!
230
231     bool isInstalled() const
232     { return fieldValueIs<StateField>( INSTALLED ); }
233
234     bool isUninstalled() const
235     { return fieldValueIs<StateField>( UNINSTALLED ); }
236
237   public:
238
239     bool staysInstalled() const
240     { return isInstalled() && !transacts(); }
241
242     bool wasInstalled() const { return staysInstalled(); }      //for old status
243
244     bool isToBeInstalled() const
245     { return isUninstalled() && transacts(); }
246
247     bool staysUninstalled() const
248     { return isUninstalled() && !transacts(); }
249
250     bool wasUninstalled() const { return staysUninstalled(); }  // for old status
251
252     bool isToBeUninstalled() const
253     { return isInstalled() && transacts(); }
254
255     bool isLocked() const
256     { return fieldValueIs<TransactField>( LOCKED ); }
257
258     bool isUserLocked() const
259     { return isLocked() && isByUser(); }
260
261     bool isSoftLocked() const
262     { return isKept() && ( isByApplLow() || isByUser() ); }
263
264     bool isKept() const
265     { return fieldValueIs<TransactField>( KEEP_STATE ); }
266
267     bool transacts() const
268     { return fieldValueIs<TransactField>( TRANSACT ); }
269
270     TransactValue getTransactValue() const
271     { return (TransactValue)_bitfield.value<TransactField>(); }
272
273     /** True if would be on system after commit. */
274     bool onSystem() const
275     { return( isInstalled() != transacts() ); }
276
277     /** True if would be off system after commit. */
278     bool offSystem() const
279     { return ! onSystem(); }
280
281     bool isBySolver() const
282     { return fieldValueIs<TransactByField>( SOLVER ); }
283
284     bool isByApplLow() const
285     { return fieldValueIs<TransactByField>( APPL_LOW ); }
286
287     bool isByApplHigh() const
288     { return fieldValueIs<TransactByField>( APPL_HIGH ); }
289
290     bool isByUser() const
291     { return fieldValueIs<TransactByField>( USER ); }
292
293     TransactByValue getTransactByValue() const
294     { return (TransactByValue)_bitfield.value<TransactByField>(); }
295
296     bool setTransactByValue(TransactByValue causer)
297     {
298         if ( isLessThan<TransactByField>( causer ) ) {
299             fieldValueAssign<TransactByField>( causer );
300             return true;
301         } else {
302             return false;
303         }
304     }
305
306     bool isToBeUninstalledDueToObsolete () const
307     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( DUE_TO_OBSOLETE ); }
308
309     bool isToBeUninstalledDueToUpgrade() const
310     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( DUE_TO_UPGRADE ); }
311
312     bool isToBeInstalledSoft () const
313     { return isToBeInstalled() && fieldValueIs<TransactDetailField>( SOFT_INSTALL ); }
314
315     bool isToBeInstalledNotSoft () const
316     { return isToBeInstalled() && !fieldValueIs<TransactDetailField>( SOFT_INSTALL ); }
317
318     bool isToBeUninstalledSoft () const
319     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( SOFT_REMOVE ); }
320
321   private:
322
323     /** \name Internal hard lock maintainance */
324     //@{
325     friend class resstatus::UserLockQueryManip;
326
327     bool isUserLockQueryMatch() const
328     { return fieldValueIs<UserLockQueryField>( USERLOCK_MATCH ); }
329
330     void setUserLockQueryMatch( bool match_r )
331     { fieldValueAssign<UserLockQueryField>( match_r ? USERLOCK_MATCH : USERLOCK_NOMATCH ); }
332     //@}
333
334   public:
335
336     //------------------------------------------------------------------------
337     // get/set functions, returnig \c true if requested status change
338     // was successfull (i.e. leading to the desired transaction).
339     // If a lower level (e.g.SOLVER) wants to transact, but it's
340     // already set by a higher level, \c true should be returned.
341     // Removing a higher levels transaction bit should fail.
342     //
343     // The may functions checks only, if the action would return true
344     // if it is called.
345
346     /** Set TransactValue.
347      * Convenience to set TransactValue from enum.
348      */
349     bool setTransactValue( TransactValue newVal_r, TransactByValue causer_r )
350     {
351       switch ( newVal_r )
352         {
353         case KEEP_STATE:
354           return setTransact( false, causer_r );
355           break;
356         case LOCKED:
357           return setLock( true, causer_r );
358           break;
359         case TRANSACT:
360           return setTransact( true, causer_r );
361           break;
362         }
363       return false;
364     }
365
366     bool maySetTransactValue( TransactValue newVal_r, TransactByValue causer_r )
367     {
368         bit::BitField<FieldType> savBitfield = _bitfield;
369         bool ret = setTransactValue( newVal_r, causer_r );
370         _bitfield = savBitfield;
371         return ret;
372     }
373
374     /** Apply a lock (prevent transaction).
375      * Currently by USER or APPL_HIGH only, but who knows...
376      * Set LOCKED from KEEP_STATE to be shure all transaction
377      * details were reset properly.
378     */
379     bool setLock( bool toLock_r, TransactByValue causer_r )
380     {
381       if ( toLock_r == isLocked() )
382         {
383           // we're already in the desired state, but in case of
384           // LOCKED, remember a superior causer.
385           if ( isLocked() && isLessThan<TransactByField>( causer_r ) )
386             fieldValueAssign<TransactByField>( causer_r );
387            return true;
388         }
389       // Here: Lock status is to be changed:
390       if ( causer_r != USER && causer_r != APPL_HIGH )
391         return false;
392       if ( toLock_r ) {
393         // We're in unlocked state, which includes TRANSACT.
394         // Causer must be allowed to reset this. But from
395         // KEEP_STATE every causer is allowed to set the lock.
396         if ( ! setTransact( false, causer_r ) )
397           return false;
398         fieldValueAssign<TransactField>( LOCKED );
399         fieldValueAssign<TransactByField>( causer_r );
400       } else {
401         // To leave Locked state it needs a superior causer.
402         if ( isGreaterThan<TransactByField>( causer_r ) )
403           return false;
404         fieldValueAssign<TransactField>( KEEP_STATE );
405         fieldValueAssign<TransactByField>( SOLVER ); // reset to lowest causer
406                                                      // in order to distinguish from keep_state_by_user
407       }
408       return true;
409     }
410
411     bool maySetLock( bool to_r, TransactByValue causer_r )
412     {
413         bit::BitField<FieldType> savBitfield = _bitfield;
414         bool ret = setLock( to_r, causer_r );
415         _bitfield = savBitfield;
416         return ret;
417     }
418
419     /** Toggle between TRANSACT and KEEP_STATE.
420      * LOCKED state means KEEP_STATE. But in contrary to KEEP_STATE,
421      * LOCKED state is immutable for \a causer_r less than TransactByValue.
422      * KEEP_STATE may be canged by any \a causer_r.
423     */
424     bool setTransact( bool toTansact_r, TransactByValue causer_r )
425     {
426       if ( toTansact_r == transacts() )
427         {
428           // we're already in the desired state, but in case of
429           // TRANSACT, remember a superior causer.
430           if ( transacts() && isLessThan<TransactByField>( causer_r ) )
431               fieldValueAssign<TransactByField>( causer_r );
432
433           fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
434           return true;
435         }
436       // Here: transact status is to be changed:
437       if (    ! fieldValueIs<TransactField>( KEEP_STATE )
438               && isGreaterThan<TransactByField>( causer_r ) ) {
439         return false;
440       }
441
442       if ( toTansact_r )
443       {
444           fieldValueAssign<TransactField>( TRANSACT );
445       }
446       else
447       {
448           fieldValueAssign<TransactField>( KEEP_STATE );
449       }
450       fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
451       fieldValueAssign<TransactByField>( causer_r );
452       return true;
453     }
454
455     bool maySetTransact( bool val_r, TransactByValue causer )
456     {
457         bit::BitField<FieldType> savBitfield = _bitfield;
458         bool ret = setTransact (val_r, causer);
459         _bitfield = savBitfield;
460         return ret;
461     }
462
463     /** */
464     bool setSoftLock( TransactByValue causer_r )
465     {
466       if ( ! setTransact( false, causer_r ) )
467         return false;
468       if ( fieldValueIs<TransactField>( KEEP_STATE )
469            && isLessThan<TransactByField>( causer_r ) )
470         fieldValueAssign<TransactByField>( causer_r );
471       return true;
472     }
473
474     /** Not the same as setTransact( false ).
475      */
476     bool resetTransact( TransactByValue causer_r )
477     {
478       if ( ! setTransact( false, causer_r ) )
479         return false;
480       if ( fieldValueIs<TransactField>( KEEP_STATE ) )
481         fieldValueAssign<TransactByField>( SOLVER );
482       return true;
483     }
484
485     /** Soft toggle between TRANSACT and KEEP_STATE.
486      * Similar to setTransact, but leaving KEEP_STATE also requires
487      * a superior \a causerLimit_r. So this is a kind of soft lock.
488      * \code
489      * // SOLVER wants to set TRANSACT, iff KEEP_STATE is
490      * // not superior to APPL_LOW.
491      * setSoftTransact( true, SOLVER, APPL_LOW );
492      * \endcode
493     */
494     bool setSoftTransact( bool toTansact_r, TransactByValue causer_r,
495                           TransactByValue causerLimit_r )
496     {
497       if ( fieldValueIs<TransactField>( KEEP_STATE )
498            && toTansact_r != transacts()
499            && isGreaterThan<TransactByField>( causerLimit_r ) )
500         {
501           // any transact status change requires a superior causer.
502           return false;
503         }
504       return setTransact( toTansact_r, causer_r );
505     }
506
507     bool setSoftTransact( bool toTansact_r, TransactByValue causer_r )
508     { return setSoftTransact( toTansact_r, causer_r, causer_r ); }
509
510     bool maySetSoftTransact( bool val_r, TransactByValue causer,
511                              TransactByValue causerLimit_r )
512     {
513         bit::BitField<FieldType> savBitfield = _bitfield;
514         bool ret = setSoftTransact( val_r, causer, causerLimit_r );
515         _bitfield = savBitfield;
516         return ret;
517     }
518
519     bool maySetSoftTransact( bool val_r, TransactByValue causer )
520     { return maySetSoftTransact( val_r, causer, causer ); }
521
522     bool setToBeInstalled (TransactByValue causer)
523     {
524       if (isInstalled()) return false;
525       return setTransact (true, causer);
526     }
527
528     bool maySetToBeInstalled (TransactByValue causer)
529     {
530         bit::BitField<FieldType> savBitfield = _bitfield;
531         bool ret = setToBeInstalled (causer);
532         _bitfield = savBitfield;
533         return ret;
534     }
535
536     bool setToBeUninstalled (TransactByValue causer)
537     {
538       if (!isInstalled()) return false;
539       return setTransact (true, causer);
540     }
541
542     bool maySetToBeUninstalled (TransactByValue causer)
543     {
544         bit::BitField<FieldType> savBitfield = _bitfield;
545         bool ret = setToBeUninstalled (causer);
546         _bitfield = savBitfield;
547         return ret;
548     }
549
550     //------------------------------------------------------------------------
551     // *** These are only for the Resolver ***
552
553     bool setToBeUninstalledDueToObsolete ( )
554     {
555       if (!setToBeUninstalled (SOLVER)) return false;
556       fieldValueAssign<TransactDetailField>(DUE_TO_OBSOLETE);
557       return true;
558     }
559
560     bool setToBeUninstalledDueToUpgrade ( TransactByValue causer )
561     {
562       if (!setToBeUninstalled (causer)) return false;
563       fieldValueAssign<TransactDetailField>(DUE_TO_UPGRADE);
564       return true;
565     }
566
567     bool setToBeInstalledSoft ( )
568     {
569       if (isInstalled()
570           || !setSoftTransact (true, SOLVER))
571           return false;
572
573       fieldValueAssign<TransactDetailField>(SOFT_INSTALL);
574       return true;
575     }
576
577     bool setToBeUninstalledSoft ( )
578     {
579       if (!isInstalled()
580           || !setSoftTransact (true, SOLVER))
581           return false;
582
583       fieldValueAssign<TransactDetailField>(SOFT_REMOVE);
584       return true;
585     }
586
587     bool maySetToBeUninstalledSoft ()
588     {
589         bit::BitField<FieldType> savBitfield = _bitfield;
590         bool ret = setToBeUninstalledSoft ();
591         _bitfield = savBitfield;
592         return ret;
593     }
594
595     bool isSoftInstall () {
596         return fieldValueIs<TransactDetailField> (SOFT_INSTALL);
597     }
598
599     bool isSoftUninstall () {
600         return fieldValueIs<TransactDetailField> (SOFT_REMOVE);
601     }
602
603     bool setSoftInstall (bool flag) {
604         fieldValueAssign<TransactDetailField>(flag?SOFT_INSTALL:0);
605         return true;
606     }
607
608     bool setSoftUninstall (bool flag) {
609         fieldValueAssign<TransactDetailField>(flag?SOFT_REMOVE:0);
610         return true;
611     }
612
613     bool setUndetermined ()
614     {
615       fieldValueAssign<ValidateField>(UNDETERMINED);
616       return true;
617     }
618
619     bool setSatisfied ()
620     {
621       fieldValueAssign<ValidateField>(SATISFIED);
622       return true;
623     }
624
625     bool setBroken ()
626     {
627       fieldValueAssign<ValidateField>(BROKEN);
628       return true;
629     }
630
631     bool setNonRelevant ()
632     {
633       fieldValueAssign<ValidateField>(NONRELEVANT);
634       return true;
635     }
636
637     bool setStatus( ResStatus newStatus_r )
638     {
639       // State field is immutable!
640       if ( _bitfield.value<StateField>() != newStatus_r._bitfield.value<StateField>() )
641         return false;
642       // Transaction state change allowed?
643       if ( ! setTransactValue( newStatus_r.getTransactValue(), newStatus_r.getTransactByValue() ) )
644         return false;
645
646       // Ok, we take it all..
647       _bitfield = newStatus_r._bitfield;
648       return true;
649     }
650
651     /** \name Builtin ResStatus constants. */
652     //@{
653     static const ResStatus toBeInstalled;
654     static const ResStatus toBeUninstalled;
655     static const ResStatus toBeUninstalledDueToUpgrade;
656     static const ResStatus toBeUninstalledDueToObsolete;
657     //@}
658
659   private:
660     /** Ctor for intialization of builtin constants. */
661     ResStatus( StateValue s,
662                ValidateValue v      = UNDETERMINED,
663                TransactValue t      = KEEP_STATE,
664                InstallDetailValue i = EXPLICIT_INSTALL,
665                RemoveDetailValue r  = EXPLICIT_REMOVE );
666
667     /** Return whether the corresponding Field has value \a val_r.
668     */
669     template<class TField>
670       bool fieldValueIs( FieldType val_r ) const
671     { return _bitfield.isEqual<TField>( val_r ); }
672
673     /** Set the corresponding Field to value \a val_r.
674     */
675     template<class TField>
676       void fieldValueAssign( FieldType val_r )
677     { _bitfield.assign<TField>( val_r ); }
678
679     /** compare two values.
680     */
681     template<class TField>
682       bool isGreaterThan( FieldType val_r )
683     { return _bitfield.value<TField>() > val_r; }
684
685     template<class TField>
686       bool isLessThan( FieldType val_r )
687     { return _bitfield.value<TField>() < val_r; }
688
689   private:
690     friend class resstatus::StatusBackup;
691     BitFieldType _bitfield;
692   };
693   ///////////////////////////////////////////////////////////////////
694
695   /** \relates ResStatus Stream output */
696   std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
697
698   /** \relates ResStatus Stream output */
699   std::ostream & operator<<( std::ostream & str, ResStatus::TransactValue obj );
700
701   /** \relates ResStatus Stream output */
702   std::ostream & operator<<( std::ostream & str, ResStatus::TransactByValue obj );
703
704   /** \relates ResStatus */
705   inline bool operator==( const ResStatus & lhs, const ResStatus & rhs )
706   { return lhs._bitfield == rhs._bitfield; }
707
708   /** \relates ResStatus */
709   inline bool operator!=( const ResStatus & lhs, const ResStatus & rhs )
710   { return ! (lhs == rhs); }
711
712   ///////////////////////////////////////////////////////////////////
713
714   namespace resstatus
715   {
716     class StatusBackup
717     {
718       public:
719         StatusBackup()
720         : _status( 0 )
721         {}
722
723         StatusBackup( ResStatus & status_r )
724         : _status( &status_r )
725         , _bitfield( _status->_bitfield )
726         {}
727
728         void replay()
729         { if ( _status ) _status->_bitfield = _bitfield; }
730
731       private:
732         ResStatus *             _status;
733         ResStatus::BitFieldType _bitfield;
734     };
735   }
736
737  /////////////////////////////////////////////////////////////////
738 } // namespace zypp
739 ///////////////////////////////////////////////////////////////////
740 #endif // ZYPP_RESSTATUS_H