libzypp  16.22.5
SolvIdentFile.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_TARGET_SOLVIDENTFILE_H
13 #define ZYPP_TARGET_SOLVIDENTFILE_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 
34  {
35  friend std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
36  public:
37  typedef std::unordered_set<IdString> Data;
38 
39  public:
41  SolvIdentFile( const Pathname & file_r )
42  : _file( file_r )
43  {}
44 
46  const Pathname & file() const
47  { return _file; }
48 
53  const Data & data() const
54  {
55  if ( !_dataPtr )
56  {
57  _dataPtr.reset( new Data );
58  Data & mydata( *_dataPtr );
59  load( _file, mydata );
60  }
61  return *_dataPtr;
62  }
63 
69  void setData( const Data & data_r )
70  {
71  if ( !_dataPtr )
72  _dataPtr.reset( new Data );
73 
74  if ( differs( *_dataPtr, data_r ) )
75  {
76  store( _file, data_r );
77  *_dataPtr = data_r;
78  }
79  }
80 
81  private:
83  bool differs( const Data & lhs, const Data & rhs ) const
84  {
85 
86  if ( lhs.size() != rhs.size() )
87  return true;
88  for_( it, lhs.begin(), lhs.end() )
89  {
90  if ( rhs.find( *it ) == rhs.end() )
91  return true;
92  }
93  return false;
94  }
96  static void load( const Pathname & file_r, Data & data_r );
98  static void store( const Pathname & file_r, const Data & data_r );
99 
100  private:
101  Pathname _file;
102  mutable scoped_ptr<Data> _dataPtr;
103  };
105 
107  std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
108 
110  } // namespace target
113 } // namespace zypp
115 #endif // ZYPP_TARGET_SOLVIDENTFILE_H
friend std::ostream & operator<<(std::ostream &str, const SolvIdentFile &obj)
void setData(const Data &data_r)
Store new Data.
Definition: SolvIdentFile.h:69
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
SolvIdentFile(const Pathname &file_r)
Ctor taking the file to read/write.
Definition: SolvIdentFile.h:41
const Data & data() const
Return the data.
Definition: SolvIdentFile.h:53
static void store(const Pathname &file_r, const Data &data_r)
Write Data to file_r.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Save and restore a list of solvable names (ident IdString)
Definition: SolvIdentFile.h:33
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition: SolvIdentFile.h:83
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
std::unordered_set< IdString > Data
Definition: SolvIdentFile.h:37
scoped_ptr< Data > _dataPtr
const Pathname & file() const
Return the file path.
Definition: SolvIdentFile.h:46