HardLocksFile.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_TARGET_HARDLOCKSFILE_H
00013 #define ZYPP_TARGET_HARDLOCKSFILE_H
00014
00015 #include <iosfwd>
00016
00017 #include "zypp/base/PtrTypes.h"
00018
00019 #include "zypp/Pathname.h"
00020 #include "zypp/pool/PoolTraits.h"
00021 #include "zypp/PoolQuery.h"
00022
00024 namespace zypp
00025 {
00026
00027 namespace target
00028 {
00029
00031
00032
00033
00036 class HardLocksFile
00037 {
00038 friend std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
00039 public:
00040
00041 typedef pool::PoolTraits::HardLockQueries Data;
00042
00043 public:
00045 HardLocksFile( const Pathname & file_r )
00046 : _file( file_r )
00047 {}
00048
00050 const Pathname & file() const
00051 { return _file; }
00052
00057 const Data & data() const
00058 {
00059 if ( !_dataPtr )
00060 {
00061 _dataPtr.reset( new Data );
00062 Data & mydata( *_dataPtr );
00063 load( _file, mydata );
00064 }
00065 return *_dataPtr;
00066 }
00067
00073 void setData( const Data & data_r )
00074 {
00075 if ( !_dataPtr )
00076 _dataPtr.reset( new Data );
00077
00078 if ( differs( *_dataPtr, data_r ) )
00079 {
00080 store( _file, data_r );
00081 *_dataPtr = data_r;
00082 }
00083 }
00084
00085 private:
00087 bool differs( const Data & lhs, const Data & rhs ) const
00088 {
00089 if ( lhs.size() != rhs.size() )
00090 return true;
00091
00092
00093 Data::const_iterator rit = rhs.begin();
00094 for_( it, lhs.begin(), lhs.end() )
00095 {
00096 if ( *it != *rit )
00097 return true;
00098 ++rit;
00099 }
00100 return false;
00101 }
00103 static void load( const Pathname & file_r, Data & data_r );
00105 static void store( const Pathname & file_r, const Data & data_r );
00106
00107 private:
00108 Pathname _file;
00109 mutable scoped_ptr<Data> _dataPtr;
00110 };
00112
00114 std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
00115
00117 }
00120 }
00122 #endif // ZYPP_TARGET_HARDLOCKSFILE_H