1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Locale.h
17 #include "zypp/base/PtrTypes.h"
19 #include "zypp/LanguageCode.h"
20 #include "zypp/CountryCode.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : Locale
33 friend std::ostream & operator<<( std::ostream & str, const Locale & obj );
43 /** Ctor taking a string. */
45 Locale( const std::string & code_r );
47 /** Ctor taking LanguageCode and optional CountryCode. */
48 Locale( const LanguageCode & language_r,
49 const CountryCode & country_r = CountryCode() );
55 /** \name Locale constants. */
57 /** No or empty code. */
58 static const Locale noCode;
63 const LanguageCode & language() const;
65 const CountryCode & country() const;
67 /** Return the locale code. */
68 std::string code() const;
70 /** Return the name made of language and country name. */
71 std::string name() const;
73 /** Return a fallback locale for this locale, when giving up, returns empty Locale() */
74 Locale fallback() const;
77 /** Pointer to implementation */
78 RW_pointer<Impl> _pimpl;
80 ///////////////////////////////////////////////////////////////////
82 /** \relates Locale Stream output */
83 inline std::ostream & operator<<( std::ostream & str, const Locale & obj )
84 { return str << obj.code(); }
86 /** Comparison based on string value. */
88 /** \relates Locale */
89 inline bool operator==( const Locale & lhs, const Locale & rhs ) {
90 return( lhs.code() == rhs.code() );
92 /** \relates Locale */
93 inline bool operator==( const std::string & lhs, const Locale & rhs ) {
94 return( lhs == rhs.code() );
96 /** \relates Locale */
97 inline bool operator==( const Locale & lhs, const std::string & rhs ) {
98 return( lhs.code() == rhs );
101 /** \relates Locale */
102 inline bool operator!=( const Locale & lhs, const Locale & rhs ) {
103 return( ! operator==( lhs, rhs ) );
105 /** \relates Locale */
106 inline bool operator!=( const std::string & lhs, const Locale & rhs ) {
107 return( ! operator==( lhs, rhs ) );
109 /** \relates Locale */
110 inline bool operator!=( const Locale & lhs, const std::string & rhs ) {
111 return( ! operator==( lhs, rhs ) );
115 /////////////////////////////////////////////////////////////////
117 ///////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////
121 { /////////////////////////////////////////////////////////////////
122 /** \relates zypp::Locale Default order for std::container based on code string value.*/
124 inline bool less<zypp::Locale>::operator()( const zypp::Locale & lhs, const zypp::Locale & rhs ) const
125 { return lhs.code() < rhs.code(); }
126 /////////////////////////////////////////////////////////////////
128 ///////////////////////////////////////////////////////////////////
129 #endif // ZYPP_LOCALE_H