libzypp  10.5.0
SoftLocksFile.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_TARGET_SOFTLOCKSFILE_H
00013 #define ZYPP_TARGET_SOFTLOCKSFILE_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/PtrTypes.h"
00018 
00019 #include "zypp/IdString.h"
00020 #include "zypp/Pathname.h"
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace target
00027   { 
00028 
00030     //
00031     //  CLASS NAME : SoftLocksFile
00032     //
00035     class SoftLocksFile
00036     {
00037       friend std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj );
00038       public:
00039         typedef std::tr1::unordered_set<IdString> Data;
00040 
00041       public:
00043         SoftLocksFile( const Pathname & file_r )
00044         : _file( file_r )
00045         {}
00046 
00048         const Pathname & file() const
00049         { return _file; }
00050 
00055         const Data & data() const
00056         {
00057           if ( !_dataPtr )
00058           {
00059             _dataPtr.reset( new Data );
00060             Data & mydata( *_dataPtr );
00061             load( _file, mydata );
00062           }
00063           return *_dataPtr;
00064         }
00065 
00071         void setData( const Data & data_r )
00072         {
00073           if ( !_dataPtr )
00074             _dataPtr.reset( new Data );
00075 
00076           if ( differs( *_dataPtr, data_r ) )
00077           {
00078             store( _file, data_r );
00079             *_dataPtr = data_r;
00080           }
00081         }
00082 
00083       private:
00085         bool differs( const Data & lhs, const Data & rhs ) const
00086         {
00087 
00088           if ( lhs.size() != rhs.size() )
00089             return true;
00090           for_( it, lhs.begin(), lhs.end() )
00091           {
00092             if ( rhs.find( *it ) == rhs.end() )
00093               return true;
00094           }
00095           return false;
00096         }
00098         static void load( const Pathname & file_r, Data & data_r );
00100         static void store( const Pathname & file_r, const Data & data_r );
00101 
00102       private:
00103         Pathname                 _file;
00104         mutable scoped_ptr<Data> _dataPtr;
00105     };
00107 
00109     std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj );
00110 
00112   } // namespace target
00115 } // namespace zypp
00117 #endif // ZYPP_TARGET_SOFTLOCKSFILE_H