libzypp 17.37.10

RequestedLocalesFile.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_TARGET_REQUESTEDLOCALESFILE_H
13#define ZYPP_TARGET_REQUESTEDLOCALESFILE_H
14
15#include <iosfwd>
16#include <utility>
17
18#include <zypp/base/PtrTypes.h>
19
20#include <zypp/Pathname.h>
21#include <zypp/Locale.h>
22
24 namespace zypp
25{
27 namespace target
28 {
29
31 //
32 // CLASS NAME : RequestedLocalesFile
33 //
36 class RequestedLocalesFile
37 {
38 friend std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
39
40 public:
42 RequestedLocalesFile( Pathname file_r )
43 : _file(std::move( file_r ))
44 {}
45
47 const Pathname & file() const
48 { return _file; }
49
54 const LocaleSet & locales() const
55 {
56 if ( !_localesPtr )
57 {
58 _localesPtr.reset( new LocaleSet );
59 LocaleSet & ls( *_localesPtr );
60 load( _file, ls );
61 }
62 return *_localesPtr;
63 }
64
69 void setLocales( const LocaleSet & locales_r )
70 {
71 if ( !_localesPtr )
72 _localesPtr.reset( new LocaleSet );
73
74 if ( differs( *_localesPtr, locales_r ) )
75 {
76 store( _file, locales_r );
77 *_localesPtr = locales_r;
78 }
79 }
80
81 private:
83 bool differs( const LocaleSet & lhs, const LocaleSet & rhs ) const
84 {
85 if ( lhs.size() != rhs.size() )
86 return true;
87 for_( it, lhs.begin(), lhs.end() )
88 {
89 if ( rhs.find( *it ) == rhs.end() )
90 return true;
91 }
92 return false;
93 }
94
95 static void load( const Pathname & file_r, LocaleSet & locales_r );
97 static void store( const Pathname & file_r, const LocaleSet & locales_r );
98
99 private:
100 Pathname _file;
101 mutable scoped_ptr<LocaleSet> _localesPtr;
102 };
103
104
106 std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
107
109 } // namespace target
112} // namespace zypp
114#endif // ZYPP_TARGET_REQUESTEDLOCALESFILE_H
Locale.h
scoped_ptr
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::target::RequestedLocalesFile
Save and restore locale set from file.
Definition RequestedLocalesFile.h:37
zypp::target::RequestedLocalesFile::_file
Pathname _file
Definition RequestedLocalesFile.h:100
zypp::target::RequestedLocalesFile::differs
bool differs(const LocaleSet &lhs, const LocaleSet &rhs) const
Helper testing whether two LocaleSet differ.
Definition RequestedLocalesFile.h:83
zypp::target::RequestedLocalesFile::locales
const LocaleSet & locales() const
Return the loacale set.
Definition RequestedLocalesFile.h:54
zypp::target::RequestedLocalesFile::RequestedLocalesFile
RequestedLocalesFile(Pathname file_r)
Ctor taking the file to read/write.
Definition RequestedLocalesFile.h:42
zypp::target::RequestedLocalesFile::load
static void load(const Pathname &file_r, LocaleSet &locales_r)
Read LocaleSet from file_r.
Definition RequestedLocalesFile.cc:34
zypp::target::RequestedLocalesFile::setLocales
void setLocales(const LocaleSet &locales_r)
Store a new locale set.
Definition RequestedLocalesFile.h:69
zypp::target::RequestedLocalesFile::store
static void store(const Pathname &file_r, const LocaleSet &locales_r)
Write LocaleSet to file_r.
Definition RequestedLocalesFile.cc:54
zypp::target::RequestedLocalesFile::operator<<
friend std::ostream & operator<<(std::ostream &str, const RequestedLocalesFile &obj)
Definition RequestedLocalesFile.cc:80
zypp::target::RequestedLocalesFile::_localesPtr
scoped_ptr< LocaleSet > _localesPtr
Definition RequestedLocalesFile.h:101
zypp::target::RequestedLocalesFile::file
const Pathname & file() const
Return the file path.
Definition RequestedLocalesFile.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
zypp::LocaleSet
std::unordered_set< Locale > LocaleSet
Definition Locale.h:29
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Pathname.h
PtrTypes.h