1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/SerialNumber.h
12 #ifndef ZYPP_BASE_SERIALNUMBER_H
13 #define ZYPP_BASE_SERIALNUMBER_H
17 #include "zypp/base/PtrTypes.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////
25 // CLASS NAME : SerialNumber
27 /** Simple serial number provider.
29 * \ref serial returns a serial number. The number returned stays
30 * the same unless \ref setDirty was called to bring the object
31 * into \c dirty state. The next call to \ref serial will increment
32 * the serial number and bring the object into \c clean state.
36 * sno.serial(); // SERIAL(0); () = clean
37 * sno.setDirty(); // SERIAL*0*; ** = dirty
38 * sno.serial(); // SERIAL(1)
39 * sno.setDirty(); // SERIAL*1*
40 * sno.setDirty(); // SERIAL*1*
41 * sno.serial(); // SERIAL(2)
46 friend std::ostream & operator<<( std::ostream & str, const SerialNumber & obj );
49 /** Ctor taking initial \c dirty value. */
50 SerialNumber( bool dirty_r = false );
52 virtual ~SerialNumber();
65 unsigned serial() const
77 mutable unsigned _serial;
79 ///////////////////////////////////////////////////////////////////
81 /** \relates SerialNumber Stream output */
82 std::ostream & operator<<( std::ostream & str, const SerialNumber & obj );
84 ///////////////////////////////////////////////////////////////////
86 // CLASS NAME : SerialNumberWatcher
88 /** Simple serial number watcher.
90 * \ref SerialNumberWatcher remembers a serial number
91 * and tells whenever new numbers you feed change.
93 * All methods are overloaded to take an \unsigned or a
94 * <tt>const SerialNumber &</tt> as argument.
101 * static SerialNumberWatcher watcher( sno );
103 * if ( watcher.remember( sno ) )
105 * cout << "Serial number changed." << endl;
111 * check(); // This call would trigger, if check used a
112 * // default constructed SerialNumberWatcher.
116 * check(); // "Serial number changed."
119 * check(); // "Serial number changed."
122 class SerialNumberWatcher
124 friend std::ostream & operator<<( std::ostream & str, const SerialNumberWatcher & obj );
127 /** Ctor taking an initial \c serial value.
129 * A default constructed SerialNumberWatcher remembers the serial
130 * number <tt>(unsigned)-1</tt>. So it is most likely the the 1st
131 * call to \ref remember returns \ref isDirty.
133 * Vice versa, initializing the SerialNumberWatcher with the current
134 * SerialNumber, most likely prevents the 1st to \ref remember to
135 * return \ref isDirty.
137 SerialNumberWatcher( unsigned serial_r = (unsigned)-1 );
138 /** Ctor taking an initial \c serial value. */
139 SerialNumberWatcher( const SerialNumber & serial_r );
141 virtual ~SerialNumberWatcher();
144 /** Return whether \c serial_r differs. */
145 bool isDirty( unsigned serial_r ) const
146 { return( _serial != serial_r ); }
148 bool isDirty( const SerialNumber & serial_r ) const
149 { return( _serial != serial_r.serial() ); }
151 /** Return whether \c serial_r is still unchanged. */
152 bool isClean( unsigned serial_r ) const
153 { return( _serial == serial_r ); }
155 bool isClean( const SerialNumber & serial_r ) const
156 { return( _serial == serial_r.serial() ); }
159 /** Return \ref isDirty, storing \c serial_r as new value. */
160 bool remember( unsigned serial_r ) const
162 if ( isDirty( serial_r ) )
170 bool remember( const SerialNumber & serial_r ) const
171 { return remember( serial_r.serial() ); }
174 mutable unsigned _serial;
176 ///////////////////////////////////////////////////////////////////
178 /** \relates SerialNumberWatcher Stream output */
179 std::ostream & operator<<( std::ostream & str, const SerialNumberWatcher & obj );
181 /////////////////////////////////////////////////////////////////
183 ///////////////////////////////////////////////////////////////////
184 #endif // ZYPP_BASE_SERIALNUMBER_H