1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/LanguageCode.h
12 #ifndef ZYPP_LANGUAGECODE_H
13 #define ZYPP_LANGUAGECODE_H
18 #include "zypp/base/PtrTypes.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
25 inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs );
26 inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs );
28 ///////////////////////////////////////////////////////////////////
30 // CLASS NAME : LanguageCode
32 /** Language codes (iso639_2/iso639_1).
34 * In fact the class will not prevent to use a non iso language code.
35 * Just a warning will appear in the log.
39 friend std::ostream & operator<<( std::ostream & str, const LanguageCode & obj );
49 /** Ctor taking a string. */
51 LanguageCode( const std::string & code_r );
57 /** \name LanguageCode constants. */
59 /** No or empty code. */
60 static const LanguageCode noCode;
64 /** Return the language code. */
65 std::string code() const;
67 /** Return the language name; if not available the language code. */
68 std::string name() const;
70 /** <tt>*this != noCode</tt>. */
71 inline bool hasCode() const
72 { return *this != noCode; }
75 /** Pointer to implementation */
76 RW_pointer<Impl> _pimpl;
78 ///////////////////////////////////////////////////////////////////
80 /** \relates LanguageCode Stream output */
81 inline std::ostream & operator<<( std::ostream & str, const LanguageCode & obj )
82 { return str << obj.code(); }
84 /** Comparison based on string value. */
86 /** \relates LanguageCode */
87 inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs ) {
88 return( lhs.code() == rhs.code() );
90 /** \relates LanguageCode */
91 inline bool operator==( const std::string & lhs, const LanguageCode & rhs ) {
92 return( lhs == rhs.code() );
94 /** \relates LanguageCode */
95 inline bool operator==( const LanguageCode & lhs, const std::string & rhs ) {
96 return( lhs.code() == rhs );
99 /** \relates LanguageCode */
100 inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs ) {
101 return( ! operator==( lhs, rhs ) );
103 /** \relates LanguageCode */
104 inline bool operator!=( const std::string & lhs, const LanguageCode & rhs ) {
105 return( ! operator==( lhs, rhs ) );
107 /** \relates LanguageCode */
108 inline bool operator!=( const LanguageCode & lhs, const std::string & rhs ) {
109 return( ! operator==( lhs, rhs ) );
113 /////////////////////////////////////////////////////////////////
115 ///////////////////////////////////////////////////////////////////
117 ///////////////////////////////////////////////////////////////////
119 { /////////////////////////////////////////////////////////////////
120 /** \relates LanguageCode Default order for std::container based on code string value.*/
122 inline bool less<zypp::LanguageCode>::operator()( const zypp::LanguageCode & lhs, const zypp::LanguageCode & rhs ) const
123 { return lhs.code() < rhs.code(); }
124 /////////////////////////////////////////////////////////////////
126 ///////////////////////////////////////////////////////////////////
127 #endif // ZYPP_LANGUAGECODE_H