libzypp  13.10.6
SoftLocksFile.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_TARGET_SOFTLOCKSFILE_H
13 #define ZYPP_TARGET_SOFTLOCKSFILE_H
14 
15 #include <iosfwd>
16 
17 #include "zypp/base/PtrTypes.h"
18 
19 #include "zypp/IdString.h"
20 #include "zypp/Pathname.h"
21 
23 namespace zypp
24 {
25  namespace target
27  {
28 
30  //
31  // CLASS NAME : SoftLocksFile
32  //
36  {
37  friend std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj );
38  public:
39  typedef std::tr1::unordered_set<IdString> Data;
40 
41  public:
43  SoftLocksFile( const Pathname & file_r )
44  : _file( file_r )
45  {}
46 
48  const Pathname & file() const
49  { return _file; }
50 
55  const Data & data() const
56  {
57  if ( !_dataPtr )
58  {
59  _dataPtr.reset( new Data );
60  Data & mydata( *_dataPtr );
61  load( _file, mydata );
62  }
63  return *_dataPtr;
64  }
65 
71  void setData( const Data & data_r )
72  {
73  if ( !_dataPtr )
74  _dataPtr.reset( new Data );
75 
76  if ( differs( *_dataPtr, data_r ) )
77  {
78  store( _file, data_r );
79  *_dataPtr = data_r;
80  }
81  }
82 
83  private:
85  bool differs( const Data & lhs, const Data & rhs ) const
86  {
87 
88  if ( lhs.size() != rhs.size() )
89  return true;
90  for_( it, lhs.begin(), lhs.end() )
91  {
92  if ( rhs.find( *it ) == rhs.end() )
93  return true;
94  }
95  return false;
96  }
98  static void load( const Pathname & file_r, Data & data_r );
100  static void store( const Pathname & file_r, const Data & data_r );
101 
102  private:
103  Pathname _file;
104  mutable scoped_ptr<Data> _dataPtr;
105  };
107 
109  std::ostream & operator<<( std::ostream & str, const SoftLocksFile & obj );
110 
112  } // namespace target
115 } // namespace zypp
117 #endif // ZYPP_TARGET_SOFTLOCKSFILE_H
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition: SoftLocksFile.h:85
void setData(const Data &data_r)
Store new Data.
Definition: SoftLocksFile.h:71
const Data & data() const
Return the data.
Definition: SoftLocksFile.h:55
SoftLocksFile(const Pathname &file_r)
Ctor taking the file to read/write.
Definition: SoftLocksFile.h:43
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
static void store(const Pathname &file_r, const Data &data_r)
Write Data to file_r.
const Pathname & file() const
Return the file path.
Definition: SoftLocksFile.h:48
friend std::ostream & operator<<(std::ostream &str, const SoftLocksFile &obj)
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
scoped_ptr< Data > _dataPtr
Save and restore soft locks.
Definition: SoftLocksFile.h:35
std::tr1::unordered_set< IdString > Data
Definition: SoftLocksFile.h:39