libzypp  11.13.5
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 
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:
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:
99  Pathname _file;
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