libzypp 17.31.0
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
17#include <zypp/base/PtrTypes.h>
18
19#include <zypp/Pathname.h>
20#include <zypp/Locale.h>
21
23namespace zypp
24{
26 namespace target
27 {
28
30 //
31 // CLASS NAME : RequestedLocalesFile
32 //
36 {
37 friend std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
38
39 public:
42 : _file( file_r )
43 {}
44
46 const Pathname & file() const
47 { return _file; }
48
53 const LocaleSet & locales() const
54 {
55 if ( !_localesPtr )
56 {
57 _localesPtr.reset( new LocaleSet );
58 LocaleSet & ls( *_localesPtr );
59 load( _file, ls );
60 }
61 return *_localesPtr;
62 }
63
68 void setLocales( const LocaleSet & locales_r )
69 {
70 if ( !_localesPtr )
71 _localesPtr.reset( new LocaleSet );
72
73 if ( differs( *_localesPtr, locales_r ) )
74 {
75 store( _file, locales_r );
76 *_localesPtr = locales_r;
77 }
78 }
79
80 private:
82 bool differs( const LocaleSet & lhs, const LocaleSet & rhs ) const
83 {
84 if ( lhs.size() != rhs.size() )
85 return true;
86 for_( it, lhs.begin(), lhs.end() )
87 {
88 if ( rhs.find( *it ) == rhs.end() )
89 return true;
90 }
91 return false;
92 }
94 static void load( const Pathname & file_r, LocaleSet & locales_r );
96 static void store( const Pathname & file_r, const LocaleSet & locales_r );
97
98 private:
100 mutable scoped_ptr<LocaleSet> _localesPtr;
101 };
103
105 std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
106
108 } // namespace target
111} // namespace zypp
113#endif // ZYPP_TARGET_REQUESTEDLOCALESFILE_H
Save and restore locale set from file.
RequestedLocalesFile(const Pathname &file_r)
Ctor taking the file to read/write.
bool differs(const LocaleSet &lhs, const LocaleSet &rhs) const
Helper testing whether two LocaleSet differ.
const LocaleSet & locales() const
Return the loacale set.
static void load(const Pathname &file_r, LocaleSet &locales_r)
Read LocaleSet from file_r.
void setLocales(const LocaleSet &locales_r)
Store a new locale set.
static void store(const Pathname &file_r, const LocaleSet &locales_r)
Write LocaleSet to file_r.
friend std::ostream & operator<<(std::ostream &str, const RequestedLocalesFile &obj)
const Pathname & file() const
Return the file path.
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
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28