libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_BASE_SERIALNUMBER_H 00013 #define ZYPP_BASE_SERIALNUMBER_H 00014 00015 #include <iosfwd> 00016 00017 #include "zypp/base/PtrTypes.h" 00018 00020 namespace zypp 00021 { 00022 00024 // 00025 // CLASS NAME : SerialNumber 00026 // 00044 class SerialNumber 00045 { 00046 friend std::ostream & operator<<( std::ostream & str, const SerialNumber & obj ); 00047 00048 public: 00050 SerialNumber( bool dirty_r = false ); 00052 virtual ~SerialNumber(); 00053 00054 public: 00055 void setDirty() 00056 { _dirty = true; } 00057 00058 public: 00059 bool dirty() const 00060 { return _dirty; } 00061 00062 bool clean() const 00063 { return !_dirty; } 00064 00065 unsigned serial() const 00066 { 00067 if ( _dirty ) 00068 { 00069 ++_serial; 00070 _dirty = false; 00071 } 00072 return _serial; 00073 } 00074 00075 private: 00076 mutable bool _dirty; 00077 mutable unsigned _serial; 00078 }; 00080 00082 std::ostream & operator<<( std::ostream & str, const SerialNumber & obj ); 00083 00085 // 00086 // CLASS NAME : SerialNumberWatcher 00087 // 00122 class SerialNumberWatcher 00123 { 00124 friend std::ostream & operator<<( std::ostream & str, const SerialNumberWatcher & obj ); 00125 00126 public: 00137 SerialNumberWatcher( unsigned serial_r = (unsigned)-1 ); 00139 SerialNumberWatcher( const SerialNumber & serial_r ); 00141 virtual ~SerialNumberWatcher(); 00142 00143 public: 00145 bool isDirty( unsigned serial_r ) const 00146 { return( _serial != serial_r ); } 00148 bool isDirty( const SerialNumber & serial_r ) const 00149 { return( _serial != serial_r.serial() ); } 00150 00152 bool isClean( unsigned serial_r ) const 00153 { return( _serial == serial_r ); } 00155 bool isClean( const SerialNumber & serial_r ) const 00156 { return( _serial == serial_r.serial() ); } 00157 00158 public: 00160 bool remember( unsigned serial_r ) const 00161 { 00162 if ( isDirty( serial_r ) ) 00163 { 00164 _serial = serial_r; 00165 return true; 00166 } 00167 return false; 00168 } 00170 bool remember( const SerialNumber & serial_r ) const 00171 { return remember( serial_r.serial() ); } 00172 00173 private: 00174 mutable unsigned _serial; 00175 }; 00177 00179 std::ostream & operator<<( std::ostream & str, const SerialNumberWatcher & obj ); 00180 00182 } // namespace zypp 00184 #endif // ZYPP_BASE_SERIALNUMBER_H