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;
61 /** Advice to use some default code. */
62 static const LanguageCode useDefault;
66 /** Return the language code. */
67 std::string code() const;
69 /** Return the language name; if not available the language code. */
70 std::string name() const;
72 /** <tt>*this != noCode</tt>. */
73 inline bool hasCode() const
74 { return *this != noCode; }
76 /** <tt>*this == useDefault</tt>. */
77 bool useDefaultCode() const
78 { return *this == useDefault; }
81 /** Pointer to implementation */
82 RW_pointer<Impl> _pimpl;
84 ///////////////////////////////////////////////////////////////////
86 /** \relates LanguageCode Stream output */
87 inline std::ostream & operator<<( std::ostream & str, const LanguageCode & obj )
88 { return str << obj.code(); }
90 /** Comparison based on string value. */
92 /** \relates LanguageCode */
93 inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs ) {
94 return( lhs.code() == rhs.code() );
96 /** \relates LanguageCode */
97 inline bool operator==( const std::string & lhs, const LanguageCode & rhs ) {
98 return( lhs == rhs.code() );
100 /** \relates LanguageCode */
101 inline bool operator==( const LanguageCode & lhs, const std::string & rhs ) {
102 return( lhs.code() == rhs );
105 /** \relates LanguageCode */
106 inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs ) {
107 return( ! operator==( lhs, rhs ) );
109 /** \relates LanguageCode */
110 inline bool operator!=( const std::string & lhs, const LanguageCode & rhs ) {
111 return( ! operator==( lhs, rhs ) );
113 /** \relates LanguageCode */
114 inline bool operator!=( const LanguageCode & lhs, const std::string & rhs ) {
115 return( ! operator==( lhs, rhs ) );
119 /////////////////////////////////////////////////////////////////
121 ///////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////
125 { /////////////////////////////////////////////////////////////////
126 /** \relates LanguageCode Default order for std::container based on code string value.*/
128 inline bool less<zypp::LanguageCode>::operator()( const zypp::LanguageCode & lhs, const zypp::LanguageCode & rhs ) const
129 { return lhs.code() < rhs.code(); }
130 /////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////
133 #endif // ZYPP_LANGUAGECODE_H