1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Locale.h
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/Tr1hash.h"
20 #include "zypp/IdString.h"
21 #include "zypp/LanguageCode.h"
22 #include "zypp/CountryCode.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 // CLASS NAME : Locale
33 * \todo migrate to IdString
37 friend std::ostream & operator<<( std::ostream & str, const Locale & obj );
47 /** Ctor taking a string. */
49 Locale( IdString code_r );
52 Locale( const std::string & code_r );
55 Locale( const char * code_r );
57 /** Ctor taking LanguageCode and optional CountryCode. */
58 Locale( const LanguageCode & language_r,
59 const CountryCode & country_r = CountryCode() );
65 /** \name Locale constants. */
67 /** No or empty code. */
68 static const Locale noCode;
73 const LanguageCode & language() const;
75 const CountryCode & country() const;
77 /** Return the locale code. */
78 std::string code() const;
80 /** Return the name made of language and country name. */
81 std::string name() const;
83 /** Return a fallback locale for this locale, when giving up, returns empty Locale() */
84 Locale fallback() const;
87 /** Pointer to implementation */
88 RW_pointer<Impl> _pimpl;
90 ///////////////////////////////////////////////////////////////////
92 /** \relates Locale Stream output */
93 inline std::ostream & operator<<( std::ostream & str, const Locale & obj )
94 { return str << obj.code(); }
96 /** Comparison based on string value. */
98 /** \relates Locale */
99 inline bool operator==( const Locale & lhs, const Locale & rhs ) {
100 return( lhs.code() == rhs.code() );
102 /** \relates Locale */
103 inline bool operator==( const std::string & lhs, const Locale & rhs ) {
104 return( lhs == rhs.code() );
106 /** \relates Locale */
107 inline bool operator==( const Locale & lhs, const std::string & rhs ) {
108 return( lhs.code() == rhs );
111 /** \relates Locale */
112 inline bool operator!=( const Locale & lhs, const Locale & rhs ) {
113 return( ! operator==( lhs, rhs ) );
115 /** \relates Locale */
116 inline bool operator!=( const std::string & lhs, const Locale & rhs ) {
117 return( ! operator==( lhs, rhs ) );
119 /** \relates Locale */
120 inline bool operator!=( const Locale & lhs, const std::string & rhs ) {
121 return( ! operator==( lhs, rhs ) );
125 ///////////////////////////////////////////////////////////////////
127 typedef std::tr1::unordered_set<Locale> LocaleSet;
129 /////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////
133 namespace std { namespace tr1 {
134 /** \relates ::zypp::Locale hash function */
135 template<> struct hash< ::zypp::Locale>
137 size_t operator()( const ::zypp::Locale & __s ) const
138 { return hash<std::string>()(__s.code()); }
142 ///////////////////////////////////////////////////////////////////
144 { /////////////////////////////////////////////////////////////////
145 /** \relates zypp::Locale Default order for std::container based on code string value.*/
147 inline bool less<zypp::Locale>::operator()( const zypp::Locale & lhs, const zypp::Locale & rhs ) const
148 { return lhs.code() < rhs.code(); }
149 /////////////////////////////////////////////////////////////////
151 ///////////////////////////////////////////////////////////////////
152 #endif // ZYPP_LOCALE_H