libzypp  17.37.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 #include <utility>
17 
18 #include <zypp/base/PtrTypes.h>
19 
20 #include <zypp/IdString.h>
21 #include <zypp/Pathname.h>
22 
24 namespace zypp
25 {
26  namespace target
28  {
29 
35  {
36  friend std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
37  public:
38  using Data = std::unordered_set<IdString>;
39 
40  public:
43  : _file(std::move( file_r ))
44  {}
45 
47  const Pathname & file() const
48  { return _file; }
49 
54  const Data & data() const
55  {
56  if ( !_dataPtr )
57  {
58  _dataPtr.reset( new Data );
59  Data & mydata( *_dataPtr );
60  load( _file, mydata );
61  }
62  return *_dataPtr;
63  }
64 
70  void setData( const Data & data_r )
71  {
72  if ( !_dataPtr )
73  _dataPtr.reset( new Data );
74 
75  if ( differs( *_dataPtr, data_r ) )
76  {
77  store( _file, data_r );
78  *_dataPtr = data_r;
79  }
80  }
81 
82  private:
84  bool differs( const Data & lhs, const Data & rhs ) const
85  {
86 
87  if ( lhs.size() != rhs.size() )
88  return true;
89  for_( it, lhs.begin(), lhs.end() )
90  {
91  if ( rhs.find( *it ) == rhs.end() )
92  return true;
93  }
94  return false;
95  }
97  static void load( const Pathname & file_r, Data & data_r );
99  static void store( const Pathname & file_r, const Data & data_r );
100 
101  private:
103  mutable scoped_ptr<Data> _dataPtr;
104  };
106 
108  std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
109 
111  } // namespace target
114 } // namespace zypp
116 #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:70
const Pathname & file() const
Return the file path.
Definition: SolvIdentFile.h:47
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
String related utilities and Regular expression matching.
Definition: Arch.h:363
const Data & data() const
Return the data.
Definition: SolvIdentFile.h:54
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)
SolvIdentFile(Pathname file_r)
Ctor taking the file to read/write.
Definition: SolvIdentFile.h:42
Save and restore a list of solvable names (ident IdString)
Definition: SolvIdentFile.h:34
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition: SolvIdentFile.h:84
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
std::unordered_set< IdString > Data
Definition: SolvIdentFile.h:38
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
scoped_ptr< Data > _dataPtr