libzypp 17.37.17
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
24namespace zypp
25{
27 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 }
96
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:
104 };
105
106
108 std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
109
111 } // namespace target
114} // namespace zypp
116#endif // ZYPP_TARGET_SOLVIDENTFILE_H
Save and restore a list of solvable names (ident IdString)
SolvIdentFile(Pathname file_r)
Ctor taking the file to read/write.
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
const Data & data() const
Return the data.
std::unordered_set< IdString > Data
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.
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.
const Pathname & file() const
Return the file path.
Definition Arch.h:364
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.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27