libzypp  17.25.1
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:
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
zypp::target::SolvIdentFile::load
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
Definition: SolvIdentFile.cc:34
zypp::target::SolvIdentFile::differs
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition: SolvIdentFile.h:83
zypp::target::SolvIdentFile::_dataPtr
scoped_ptr< Data > _dataPtr
Definition: SolvIdentFile.h:102
zypp::target::SolvIdentFile::SolvIdentFile
SolvIdentFile(const Pathname &file_r)
Ctor taking the file to read/write.
Definition: SolvIdentFile.h:41
zypp::target::SolvIdentFile::Data
std::unordered_set< IdString > Data
Definition: SolvIdentFile.h:37
PtrTypes.h
zypp::target::SolvIdentFile::setData
void setData(const Data &data_r)
Store new Data.
Definition: SolvIdentFile.h:69
Pathname.h
zypp::target::SolvIdentFile
Save and restore a list of solvable names (ident IdString)
Definition: SolvIdentFile.h:33
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Definition: CommitPackageCache.cc:155
zypp::target::SolvIdentFile::_file
Pathname _file
Definition: SolvIdentFile.h:101
IdString.h
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::target::SolvIdentFile::store
static void store(const Pathname &file_r, const Data &data_r)
Write Data to file_r.
Definition: SolvIdentFile.cc:54
zypp::target::SolvIdentFile::operator<<
friend std::ostream & operator<<(std::ostream &str, const SolvIdentFile &obj)
Definition: SolvIdentFile.cc:87
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::target::SolvIdentFile::data
const Data & data() const
Return the data.
Definition: SolvIdentFile.h:53
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
str
String related utilities and Regular expression matching.
zypp::target::SolvIdentFile::file
const Pathname & file() const
Return the file path.
Definition: SolvIdentFile.h:46