Locale.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_LOCALE_H
00013 #define ZYPP_LOCALE_H
00014
00015 #include <iosfwd>
00016
00017 #include "zypp/base/PtrTypes.h"
00018 #include "zypp/base/Tr1hash.h"
00019
00020 #include "zypp/IdString.h"
00021 #include "zypp/LanguageCode.h"
00022 #include "zypp/CountryCode.h"
00023
00025 namespace zypp
00026 {
00027
00028 class Locale;
00029 typedef std::tr1::unordered_set<Locale> LocaleSet;
00030
00032
00033
00034
00038 class Locale
00039 {
00040 friend std::ostream & operator<<( std::ostream & str, const Locale & obj );
00041
00042 public:
00044 class Impl;
00045
00046 public:
00048 Locale();
00049
00051 explicit
00052 Locale( IdString code_r );
00053
00054 explicit
00055 Locale( const std::string & code_r );
00056
00057 explicit
00058 Locale( const char * code_r );
00059
00061 Locale( const LanguageCode & language_r,
00062 const CountryCode & country_r = CountryCode() );
00063
00065 ~Locale();
00066
00067 public:
00071 static const Locale noCode;
00073
00074 public:
00076 const LanguageCode & language() const;
00078 const CountryCode & country() const;
00079
00081 std::string code() const;
00082
00084 std::string name() const;
00085
00087 Locale fallback() const;
00088
00089 public:
00090
00099 static Locale bestMatch( const LocaleSet & avLocales_r, const Locale & requested_r = Locale() );
00100
00101 private:
00103 RW_pointer<Impl> _pimpl;
00104 };
00106
00108 inline std::ostream & operator<<( std::ostream & str, const Locale & obj )
00109 { return str << obj.code(); }
00110
00114 inline bool operator==( const Locale & lhs, const Locale & rhs ) {
00115 return( lhs.code() == rhs.code() );
00116 }
00118 inline bool operator==( const std::string & lhs, const Locale & rhs ) {
00119 return( lhs == rhs.code() );
00120 }
00122 inline bool operator==( const Locale & lhs, const std::string & rhs ) {
00123 return( lhs.code() == rhs );
00124 }
00125
00127 inline bool operator!=( const Locale & lhs, const Locale & rhs ) {
00128 return( ! operator==( lhs, rhs ) );
00129 }
00131 inline bool operator!=( const std::string & lhs, const Locale & rhs ) {
00132 return( ! operator==( lhs, rhs ) );
00133 }
00135 inline bool operator!=( const Locale & lhs, const std::string & rhs ) {
00136 return( ! operator==( lhs, rhs ) );
00137 }
00139
00141 }
00143
00144 namespace std { namespace tr1 {
00146 template<> struct hash< ::zypp::Locale>
00147 {
00148 size_t operator()( const ::zypp::Locale & __s ) const
00149 { return hash<std::string>()(__s.code()); }
00150 };
00151 }}
00152
00154 namespace std
00155 {
00156
00157 template<>
00158 inline bool less<zypp::Locale>::operator()( const zypp::Locale & lhs, const zypp::Locale & rhs ) const
00159 { return lhs.code() < rhs.code(); }
00161 }
00163 #endif // ZYPP_LOCALE_H