libzypp  17.35.12
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 {
26  namespace target
28  {
29 
31  //
32  // CLASS NAME : RequestedLocalesFile
33  //
37  {
38  friend std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
39 
40  public:
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  }
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:
101  mutable scoped_ptr<LocaleSet> _localesPtr;
102  };
104 
106  std::ostream & operator<<( std::ostream & str, const RequestedLocalesFile & obj );
107 
109  } // namespace target
112 } // namespace zypp
114 #endif // ZYPP_TARGET_REQUESTEDLOCALESFILE_H
const Pathname & file() const
Return the file path.
Save and restore locale set from file.
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:29
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
String related utilities and Regular expression matching.
Definition: Arch.h:363
static void load(const Pathname &file_r, LocaleSet &locales_r)
Read LocaleSet from file_r.
const LocaleSet & locales() const
Return the loacale set.
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.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
RequestedLocalesFile(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.
friend std::ostream & operator<<(std::ostream &str, const RequestedLocalesFile &obj)
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19