libzypp  17.23.6
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 
23 namespace zypp
24 {
25  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:
41  RequestedLocalesFile( const Pathname & file_r )
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
zypp::target::RequestedLocalesFile::_localesPtr
scoped_ptr< LocaleSet > _localesPtr
Definition: RequestedLocalesFile.h:100
PtrTypes.h
zypp::target::RequestedLocalesFile::load
static void load(const Pathname &file_r, LocaleSet &locales_r)
Read LocaleSet from file_r.
Definition: RequestedLocalesFile.cc:34
Pathname.h
zypp::target::RequestedLocalesFile::_file
Pathname _file
Definition: RequestedLocalesFile.h:99
zypp::target::RequestedLocalesFile::operator<<
friend std::ostream & operator<<(std::ostream &str, const RequestedLocalesFile &obj)
Definition: RequestedLocalesFile.cc:79
zypp::target::RequestedLocalesFile::file
const Pathname & file() const
Return the file path.
Definition: RequestedLocalesFile.h:46
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Definition: CommitPackageCache.cc:155
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::LocaleSet
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
Locale.h
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
zypp::target::RequestedLocalesFile::locales
const LocaleSet & locales() const
Return the loacale set.
Definition: RequestedLocalesFile.h:53
zypp::target::RequestedLocalesFile::differs
bool differs(const LocaleSet &lhs, const LocaleSet &rhs) const
Helper testing whether two LocaleSet differ.
Definition: RequestedLocalesFile.h:82
str
String related utilities and Regular expression matching.
zypp::target::RequestedLocalesFile::RequestedLocalesFile
RequestedLocalesFile(const Pathname &file_r)
Ctor taking the file to read/write.
Definition: RequestedLocalesFile.h:41
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::setLocales
void setLocales(const LocaleSet &locales_r)
Store a new locale set.
Definition: RequestedLocalesFile.h:68
zypp::target::RequestedLocalesFile
Save and restore locale set from file.
Definition: RequestedLocalesFile.h:35