libzypp: zypp/target/SolvIdentFile.h Source File

libzypp 17.36.6

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
34 class SolvIdentFile
35 {
36 friend std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj );
37 public:
38 using Data = std::unordered_set<IdString>;
39
40 public:
42 SolvIdentFile( Pathname file_r )
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:
102 Pathname _file;
103 mutable scoped_ptr<Data> _dataPtr;
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
IdString.h
scoped_ptr
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::target::SolvIdentFile
Save and restore a list of solvable names (ident IdString)
Definition SolvIdentFile.h:35
zypp::target::SolvIdentFile::SolvIdentFile
SolvIdentFile(Pathname file_r)
Ctor taking the file to read/write.
Definition SolvIdentFile.h:42
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::data
const Data & data() const
Return the data.
Definition SolvIdentFile.h:54
zypp::target::SolvIdentFile::Data
std::unordered_set< IdString > Data
Definition SolvIdentFile.h:38
zypp::target::SolvIdentFile::operator<<
friend std::ostream & operator<<(std::ostream &str, const SolvIdentFile &obj)
Definition SolvIdentFile.cc:88
zypp::target::SolvIdentFile::_file
Pathname _file
Definition SolvIdentFile.h:102
zypp::target::SolvIdentFile::_dataPtr
scoped_ptr< Data > _dataPtr
Definition SolvIdentFile.h:103
zypp::target::SolvIdentFile::differs
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition SolvIdentFile.h:84
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::setData
void setData(const Data &data_r)
Store new Data.
Definition SolvIdentFile.h:70
zypp::target::SolvIdentFile::file
const Pathname & file() const
Return the file path.
Definition SolvIdentFile.h:47
std
Definition Arch.h:364
str
String related utilities and Regular expression matching.
zypp::target
Definition KeyRing.h:325
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Definition CommitPackageCache.cc:160
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Pathname.h
PtrTypes.h