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