libzypp  13.10.6
Locale.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_LOCALE_H
13 #define ZYPP_LOCALE_H
14 
15 #include <iosfwd>
16 
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/Tr1hash.h"
19 
20 #include "zypp/IdString.h"
21 #include "zypp/LanguageCode.h"
22 #include "zypp/CountryCode.h"
23 
25 namespace zypp
26 {
27 
28  class Locale;
29  typedef std::tr1::unordered_set<Locale> LocaleSet;
30 
32  //
33  // CLASS NAME : Locale
34  //
38  class Locale
39  {
40  friend std::ostream & operator<<( std::ostream & str, const Locale & obj );
41 
42  public:
44  class Impl;
45 
46  public:
48  Locale();
49 
51  explicit
52  Locale( IdString code_r );
53 
54  explicit
55  Locale( const std::string & code_r );
56 
57  explicit
58  Locale( const char * code_r );
59 
61  Locale( const LanguageCode & language_r,
62  const CountryCode & country_r = CountryCode() );
63 
65  ~Locale();
66 
67  public:
71  static const Locale noCode;
73 
74  public:
76  const LanguageCode & language() const;
78  const CountryCode & country() const;
79 
81  std::string code() const;
82 
84  std::string name() const;
85 
87  Locale fallback() const;
88 
89  public:
90 
99  static Locale bestMatch( const LocaleSet & avLocales_r, const Locale & requested_r = Locale() );
100 
101  private:
104  };
106 
108  inline std::ostream & operator<<( std::ostream & str, const Locale & obj )
109  { return str << obj.code(); }
110 
114  inline bool operator==( const Locale & lhs, const Locale & rhs ) {
115  return( lhs.code() == rhs.code() );
116  }
118  inline bool operator==( const std::string & lhs, const Locale & rhs ) {
119  return( lhs == rhs.code() );
120  }
122  inline bool operator==( const Locale & lhs, const std::string & rhs ) {
123  return( lhs.code() == rhs );
124  }
125 
127  inline bool operator!=( const Locale & lhs, const Locale & rhs ) {
128  return( ! operator==( lhs, rhs ) );
129  }
131  inline bool operator!=( const std::string & lhs, const Locale & rhs ) {
132  return( ! operator==( lhs, rhs ) );
133  }
135  inline bool operator!=( const Locale & lhs, const std::string & rhs ) {
136  return( ! operator==( lhs, rhs ) );
137  }
139 
141 } // namespace zypp
143 
144 namespace std { namespace tr1 {
146  template<> struct hash< ::zypp::Locale>
147  {
148  size_t operator()( const ::zypp::Locale & __s ) const
149  { return hash<std::string>()(__s.code()); }
150  };
151 }}
152 
154 namespace std
155 {
156 
157  template<>
158  inline bool less<zypp::Locale>::operator()( const zypp::Locale & lhs, const zypp::Locale & rhs ) const
159  { return lhs.code() < rhs.code(); }
161 } // namespace std
163 #endif // ZYPP_LOCALE_H
static const Locale noCode
No or empty code.
Definition: Locale.h:71
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: Locale.h:103
const CountryCode & country() const
Definition: Locale.cc:199
Locale()
Default ctor.
Definition: Locale.cc:137
bool operator==(const std::string &lhs, const Locale &rhs)
Definition: Locale.h:118
Access to the sat-pools string space.
Definition: IdString.h:39
size_t operator()(const ::zypp::Locale &__s) const
Definition: Locale.h:148
friend std::ostream & operator<<(std::ostream &str, const Locale &obj)
Locale fallback() const
Return a fallback locale for this locale, when giving up, returns empty Locale()
Definition: Locale.cc:223
std::tr1::unordered_set< Locale > LocaleSet
Definition: Locale.h:28
std::string name() const
Return the name made of language and country name.
Definition: Locale.cc:215
std::ostream & operator<<(std::ostream &str, const Locale &obj)
Definition: Locale.h:108
bool operator!=(const std::string &lhs, const Locale &rhs)
Definition: Locale.h:131
std::string code() const
Return the locale code.
Definition: Locale.cc:207
bool operator==(const Locale &lhs, const std::string &rhs)
Definition: Locale.h:122
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:265
const LanguageCode & language() const
Definition: Locale.cc:191
Locale implementation.
Definition: Locale.cc:32
~Locale()
Dtor.
Definition: Locale.cc:183
bool operator!=(const Locale &lhs, const Locale &rhs)
Definition: Locale.h:127
static Locale bestMatch(const LocaleSet &avLocales_r, const Locale &requested_r=Locale())
Return the best match for Locale requested_r within the available avLocales_r.
Definition: Locale.cc:229
bool operator!=(const Locale &lhs, const std::string &rhs)
Definition: Locale.h:135
Language codes (iso639_2/iso639_1).
Definition: LanguageCode.h:37
bool operator==(const Locale &lhs, const Locale &rhs)
Comparison based on string value.
Definition: Locale.h:114
Country codes (iso3166-1-alpha-2).
Definition: CountryCode.h:37