Imported Upstream version 17.23.0
[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     struct 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     std::string validateValueAsString() const
229     { return validateValueAsString( validate() ); }
230
231     /** ValidateValue to string used in the history file. */
232     static std::string validateValueAsString( ValidateValue val_r );
233
234     /** ValidateValue from string used in the history file. */
235     static ValidateValue stringToValidateValue( const std::string & str_r );
236
237   public:
238     // These two are IMMUTABLE!
239
240     bool isInstalled() const
241     { return fieldValueIs<StateField>( INSTALLED ); }
242
243     bool isUninstalled() const
244     { return fieldValueIs<StateField>( UNINSTALLED ); }
245
246   public:
247
248     bool staysInstalled() const
249     { return isInstalled() && !transacts(); }
250
251     bool wasInstalled() const { return staysInstalled(); }      //for old status
252
253     bool isToBeInstalled() const
254     { return isUninstalled() && transacts(); }
255
256     bool staysUninstalled() const
257     { return isUninstalled() && !transacts(); }
258
259     bool wasUninstalled() const { return staysUninstalled(); }  // for old status
260
261     bool isToBeUninstalled() const
262     { return isInstalled() && transacts(); }
263
264     bool isLocked() const
265     { return fieldValueIs<TransactField>( LOCKED ); }
266
267     bool isUserLocked() const
268     { return isLocked() && isByUser(); }
269
270     bool isSoftLocked() const
271     { return isKept() && ( isByApplLow() || isByUser() ); }
272
273     bool isKept() const
274     { return fieldValueIs<TransactField>( KEEP_STATE ); }
275
276     bool transacts() const
277     { return fieldValueIs<TransactField>( TRANSACT ); }
278
279     TransactValue getTransactValue() const
280     { return (TransactValue)_bitfield.value<TransactField>(); }
281
282     /** True if would be on system after commit. */
283     bool onSystem() const
284     { return( isInstalled() != transacts() ); }
285
286     /** True if would be off system after commit. */
287     bool offSystem() const
288     { return ! onSystem(); }
289
290     bool isBySolver() const
291     { return fieldValueIs<TransactByField>( SOLVER ); }
292
293     bool isByApplLow() const
294     { return fieldValueIs<TransactByField>( APPL_LOW ); }
295
296     bool isByApplHigh() const
297     { return fieldValueIs<TransactByField>( APPL_HIGH ); }
298
299     bool isByUser() const
300     { return fieldValueIs<TransactByField>( USER ); }
301
302     TransactByValue getTransactByValue() const
303     { return (TransactByValue)_bitfield.value<TransactByField>(); }
304
305     bool setTransactByValue(TransactByValue causer)
306     {
307         if ( isLessThan<TransactByField>( causer ) ) {
308             fieldValueAssign<TransactByField>( causer );
309             return true;
310         } else {
311             return false;
312         }
313     }
314
315     bool isToBeUninstalledDueToObsolete () const
316     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( DUE_TO_OBSOLETE ); }
317
318     bool isToBeUninstalledDueToUpgrade() const
319     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( DUE_TO_UPGRADE ); }
320
321     bool isToBeInstalledSoft () const
322     { return isToBeInstalled() && fieldValueIs<TransactDetailField>( SOFT_INSTALL ); }
323
324     bool isToBeInstalledNotSoft () const
325     { return isToBeInstalled() && !fieldValueIs<TransactDetailField>( SOFT_INSTALL ); }
326
327     bool isToBeUninstalledSoft () const
328     { return isToBeUninstalled() && fieldValueIs<TransactDetailField>( SOFT_REMOVE ); }
329
330   private:
331
332     /** \name Internal hard lock maintainance */
333     //@{
334     friend struct resstatus::UserLockQueryManip;
335
336     bool isUserLockQueryMatch() const
337     { return fieldValueIs<UserLockQueryField>( USERLOCK_MATCH ); }
338
339     void setUserLockQueryMatch( bool match_r )
340     { fieldValueAssign<UserLockQueryField>( match_r ? USERLOCK_MATCH : USERLOCK_NOMATCH ); }
341     //@}
342
343   public:
344
345     //------------------------------------------------------------------------
346     // get/set functions, returnig \c true if requested status change
347     // was successfull (i.e. leading to the desired transaction).
348     // If a lower level (e.g.SOLVER) wants to transact, but it's
349     // already set by a higher level, \c true should be returned.
350     // Removing a higher levels transaction bit should fail.
351     //
352     // The may functions checks only, if the action would return true
353     // if it is called.
354
355     /** Set TransactValue.
356      * Convenience to set TransactValue from enum.
357      */
358     bool setTransactValue( TransactValue newVal_r, TransactByValue causer_r )
359     {
360       switch ( newVal_r )
361         {
362         case KEEP_STATE:
363           return setTransact( false, causer_r );
364           break;
365         case LOCKED:
366           return setLock( true, causer_r );
367           break;
368         case TRANSACT:
369           return setTransact( true, causer_r );
370           break;
371         }
372       return false;
373     }
374
375     bool maySetTransactValue( TransactValue newVal_r, TransactByValue causer_r )
376     {
377         bit::BitField<FieldType> savBitfield = _bitfield;
378         bool ret = setTransactValue( newVal_r, causer_r );
379         _bitfield = savBitfield;
380         return ret;
381     }
382
383     /** Apply a lock (prevent transaction).
384      * Currently by USER or APPL_HIGH only, but who knows...
385      * Set LOCKED from KEEP_STATE to be shure all transaction
386      * details were reset properly.
387     */
388     bool setLock( bool toLock_r, TransactByValue causer_r )
389     {
390       if ( toLock_r == isLocked() )
391         {
392           // we're already in the desired state, but in case of
393           // LOCKED, remember a superior causer.
394           if ( isLocked() && isLessThan<TransactByField>( causer_r ) )
395             fieldValueAssign<TransactByField>( causer_r );
396            return true;
397         }
398       // Here: Lock status is to be changed:
399       if ( causer_r != USER && causer_r != APPL_HIGH )
400         return false;
401       if ( toLock_r ) {
402         // We're in unlocked state, which includes TRANSACT.
403         // Causer must be allowed to reset this. But from
404         // KEEP_STATE every causer is allowed to set the lock.
405         if ( ! setTransact( false, causer_r ) )
406           return false;
407         fieldValueAssign<TransactField>( LOCKED );
408         fieldValueAssign<TransactByField>( causer_r );
409       } else {
410         // To leave Locked state it needs a superior causer.
411         if ( isGreaterThan<TransactByField>( causer_r ) )
412           return false;
413         fieldValueAssign<TransactField>( KEEP_STATE );
414         fieldValueAssign<TransactByField>( SOLVER ); // reset to lowest causer
415                                                      // in order to distinguish from keep_state_by_user
416       }
417       return true;
418     }
419
420     bool maySetLock( bool to_r, TransactByValue causer_r )
421     {
422         bit::BitField<FieldType> savBitfield = _bitfield;
423         bool ret = setLock( to_r, causer_r );
424         _bitfield = savBitfield;
425         return ret;
426     }
427
428     /** Toggle between TRANSACT and KEEP_STATE.
429      * LOCKED state means KEEP_STATE. But in contrary to KEEP_STATE,
430      * LOCKED state is immutable for \a causer_r less than TransactByValue.
431      * KEEP_STATE may be canged by any \a causer_r.
432     */
433     bool setTransact( bool toTansact_r, TransactByValue causer_r )
434     {
435       if ( toTansact_r == transacts() )
436         {
437           // we're already in the desired state, but in case of
438           // TRANSACT, remember a superior causer.
439           if ( transacts() && isLessThan<TransactByField>( causer_r ) )
440               fieldValueAssign<TransactByField>( causer_r );
441
442           fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
443           return true;
444         }
445       // Here: transact status is to be changed:
446       if (    ! fieldValueIs<TransactField>( KEEP_STATE )
447               && isGreaterThan<TransactByField>( causer_r ) ) {
448         return false;
449       }
450
451       if ( toTansact_r )
452       {
453           fieldValueAssign<TransactField>( TRANSACT );
454       }
455       else
456       {
457           fieldValueAssign<TransactField>( KEEP_STATE );
458       }
459       fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
460       fieldValueAssign<TransactByField>( causer_r );
461       return true;
462     }
463
464     bool maySetTransact( bool val_r, TransactByValue causer )
465     {
466         bit::BitField<FieldType> savBitfield = _bitfield;
467         bool ret = setTransact (val_r, causer);
468         _bitfield = savBitfield;
469         return ret;
470     }
471
472     /** */
473     bool setSoftLock( TransactByValue causer_r )
474     {
475       if ( ! setTransact( false, causer_r ) )
476         return false;
477       if ( fieldValueIs<TransactField>( KEEP_STATE )
478            && isLessThan<TransactByField>( causer_r ) )
479         fieldValueAssign<TransactByField>( causer_r );
480       return true;
481     }
482
483     /** Not the same as setTransact( false ).
484      */
485     bool resetTransact( TransactByValue causer_r )
486     {
487       if ( ! setTransact( false, causer_r ) )
488         return false;
489       if ( fieldValueIs<TransactField>( KEEP_STATE ) )
490         fieldValueAssign<TransactByField>( SOLVER );
491       return true;
492     }
493
494     /** Soft toggle between TRANSACT and KEEP_STATE.
495      * Similar to setTransact, but leaving KEEP_STATE also requires
496      * a superior \a causerLimit_r. So this is a kind of soft lock.
497      * \code
498      * // SOLVER wants to set TRANSACT, iff KEEP_STATE is
499      * // not superior to APPL_LOW.
500      * setSoftTransact( true, SOLVER, APPL_LOW );
501      * \endcode
502     */
503     bool setSoftTransact( bool toTansact_r, TransactByValue causer_r,
504                           TransactByValue causerLimit_r )
505     {
506       if ( fieldValueIs<TransactField>( KEEP_STATE )
507            && toTansact_r != transacts()
508            && isGreaterThan<TransactByField>( causerLimit_r ) )
509         {
510           // any transact status change requires a superior causer.
511           return false;
512         }
513       return setTransact( toTansact_r, causer_r );
514     }
515
516     bool setSoftTransact( bool toTansact_r, TransactByValue causer_r )
517     { return setSoftTransact( toTansact_r, causer_r, causer_r ); }
518
519     bool maySetSoftTransact( bool val_r, TransactByValue causer,
520                              TransactByValue causerLimit_r )
521     {
522         bit::BitField<FieldType> savBitfield = _bitfield;
523         bool ret = setSoftTransact( val_r, causer, causerLimit_r );
524         _bitfield = savBitfield;
525         return ret;
526     }
527
528     bool maySetSoftTransact( bool val_r, TransactByValue causer )
529     { return maySetSoftTransact( val_r, causer, causer ); }
530
531     bool setToBeInstalled (TransactByValue causer)
532     {
533       if (isInstalled()) return false;
534       return setTransact (true, causer);
535     }
536
537     bool maySetToBeInstalled (TransactByValue causer)
538     {
539         bit::BitField<FieldType> savBitfield = _bitfield;
540         bool ret = setToBeInstalled (causer);
541         _bitfield = savBitfield;
542         return ret;
543     }
544
545     bool setToBeUninstalled (TransactByValue causer)
546     {
547       if (!isInstalled()) return false;
548       return setTransact (true, causer);
549     }
550
551     bool maySetToBeUninstalled (TransactByValue causer)
552     {
553         bit::BitField<FieldType> savBitfield = _bitfield;
554         bool ret = setToBeUninstalled (causer);
555         _bitfield = savBitfield;
556         return ret;
557     }
558
559     //------------------------------------------------------------------------
560     // *** These are only for the Resolver ***
561
562     bool setToBeUninstalledDueToObsolete ( )
563     {
564       if (!setToBeUninstalled (SOLVER)) return false;
565       fieldValueAssign<TransactDetailField>(DUE_TO_OBSOLETE);
566       return true;
567     }
568
569     bool setToBeUninstalledDueToUpgrade ( TransactByValue causer )
570     {
571       if (!setToBeUninstalled (causer)) return false;
572       fieldValueAssign<TransactDetailField>(DUE_TO_UPGRADE);
573       return true;
574     }
575
576     bool setToBeInstalledSoft ( )
577     {
578       if (isInstalled()
579           || !setSoftTransact (true, SOLVER))
580           return false;
581
582       fieldValueAssign<TransactDetailField>(SOFT_INSTALL);
583       return true;
584     }
585
586     bool setToBeUninstalledSoft ( )
587     {
588       if (!isInstalled()
589           || !setSoftTransact (true, SOLVER))
590           return false;
591
592       fieldValueAssign<TransactDetailField>(SOFT_REMOVE);
593       return true;
594     }
595
596     bool maySetToBeUninstalledSoft ()
597     {
598         bit::BitField<FieldType> savBitfield = _bitfield;
599         bool ret = setToBeUninstalledSoft ();
600         _bitfield = savBitfield;
601         return ret;
602     }
603
604     bool isSoftInstall () {
605         return fieldValueIs<TransactDetailField> (SOFT_INSTALL);
606     }
607
608     bool isSoftUninstall () {
609         return fieldValueIs<TransactDetailField> (SOFT_REMOVE);
610     }
611
612     bool setSoftInstall (bool flag) {
613         fieldValueAssign<TransactDetailField>(flag?SOFT_INSTALL:0);
614         return true;
615     }
616
617     bool setSoftUninstall (bool flag) {
618         fieldValueAssign<TransactDetailField>(flag?SOFT_REMOVE:0);
619         return true;
620     }
621
622     bool setUndetermined ()
623     {
624       fieldValueAssign<ValidateField>(UNDETERMINED);
625       return true;
626     }
627
628     bool setSatisfied ()
629     {
630       fieldValueAssign<ValidateField>(SATISFIED);
631       return true;
632     }
633
634     bool setBroken ()
635     {
636       fieldValueAssign<ValidateField>(BROKEN);
637       return true;
638     }
639
640     bool setNonRelevant ()
641     {
642       fieldValueAssign<ValidateField>(NONRELEVANT);
643       return true;
644     }
645
646     bool setStatus( ResStatus newStatus_r )
647     {
648       // State field is immutable!
649       if ( _bitfield.value<StateField>() != newStatus_r._bitfield.value<StateField>() )
650         return false;
651       // Transaction state change allowed?
652       if ( ! setTransactValue( newStatus_r.getTransactValue(), newStatus_r.getTransactByValue() ) )
653         return false;
654
655       // Ok, we take it all..
656       _bitfield = newStatus_r._bitfield;
657       return true;
658     }
659
660     /** \name Builtin ResStatus constants. */
661     //@{
662     static const ResStatus toBeInstalled;
663     static const ResStatus toBeUninstalled;
664     static const ResStatus toBeUninstalledDueToUpgrade;
665     static const ResStatus toBeUninstalledDueToObsolete;
666     //@}
667
668   private:
669     /** Ctor for intialization of builtin constants. */
670     ResStatus( StateValue s,
671                ValidateValue v      = UNDETERMINED,
672                TransactValue t      = KEEP_STATE,
673                InstallDetailValue i = EXPLICIT_INSTALL,
674                RemoveDetailValue r  = EXPLICIT_REMOVE );
675
676     /** Return whether the corresponding Field has value \a val_r.
677     */
678     template<class TField>
679       bool fieldValueIs( FieldType val_r ) const
680     { return _bitfield.isEqual<TField>( val_r ); }
681
682     /** Set the corresponding Field to value \a val_r.
683     */
684     template<class TField>
685       void fieldValueAssign( FieldType val_r )
686     { _bitfield.assign<TField>( val_r ); }
687
688     /** compare two values.
689     */
690     template<class TField>
691       bool isGreaterThan( FieldType val_r )
692     { return _bitfield.value<TField>() > val_r; }
693
694     template<class TField>
695       bool isLessThan( FieldType val_r )
696     { return _bitfield.value<TField>() < val_r; }
697
698   private:
699     friend class resstatus::StatusBackup;
700     BitFieldType _bitfield;
701   };
702   ///////////////////////////////////////////////////////////////////
703
704   /** \relates ResStatus Stream output */
705   std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
706
707   /** \relates ResStatus Stream output */
708   std::ostream & operator<<( std::ostream & str, ResStatus::TransactValue obj );
709
710   /** \relates ResStatus Stream output */
711   std::ostream & operator<<( std::ostream & str, ResStatus::TransactByValue obj );
712
713   /** \relates ResStatus */
714   inline bool operator==( const ResStatus & lhs, const ResStatus & rhs )
715   { return lhs._bitfield == rhs._bitfield; }
716
717   /** \relates ResStatus */
718   inline bool operator!=( const ResStatus & lhs, const ResStatus & rhs )
719   { return ! (lhs == rhs); }
720
721   ///////////////////////////////////////////////////////////////////
722
723   namespace resstatus
724   {
725     class StatusBackup
726     {
727       public:
728         StatusBackup()
729         : _status( 0 )
730         {}
731
732         StatusBackup( ResStatus & status_r )
733         : _status( &status_r )
734         , _bitfield( _status->_bitfield )
735         {}
736
737         void replay()
738         { if ( _status ) _status->_bitfield = _bitfield; }
739
740       private:
741         ResStatus *             _status;
742         ResStatus::BitFieldType _bitfield;
743     };
744   }
745
746  /////////////////////////////////////////////////////////////////
747 } // namespace zypp
748 ///////////////////////////////////////////////////////////////////
749 #endif // ZYPP_RESSTATUS_H