18
#include "zypp/base/PtrTypes.h"
18
#include "zypp/IdStringType.h"
20
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.
23
///////////////////////////////////////////////////////////////////
24
/// \class LanguageCode
25
/// \brief Language codes (iso639_2/iso639_1).
27
/// In fact the class will not prevent to use a non iso language code.
28
/// Just a warning will appear in the log.
29
///////////////////////////////////////////////////////////////////
30
class LanguageCode : public IdStringType<LanguageCode>
39
friend std::ostream & operator<<( std::ostream & str, const LanguageCode & obj );
33
/** Default Ctor: \ref noCode */
49
/** Ctor taking a string. */
51
LanguageCode( const std::string & code_r );
36
/** Ctor from string. */
37
explicit LanguageCode( IdString str_r );
39
/** Ctor from string. */
40
explicit LanguageCode( const std::string & str_r );
42
/** Ctor from string. */
43
explicit LanguageCode( const char * str_r );
57
49
/** \name LanguageCode constants. */
59
/** No or empty code. */
60
52
static const LanguageCode noCode;
53
/** Last resort "en". */
54
static const LanguageCode enCode;
64
/** Return the language code. */
65
std::string code() const;
58
/** Return the language code asString. */
59
std::string code() const
60
{ return std::string(_str); }
67
/** Return the language name; if not available the language code. */
62
/** Return the translated language name; if unknown the language code. */
68
63
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;
66
friend class IdStringType<LanguageCode>;
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
/////////////////////////////////////////////////////////////////
114
69
} // namespace zypp
115
70
///////////////////////////////////////////////////////////////////
117
///////////////////////////////////////////////////////////////////
119
{ /////////////////////////////////////////////////////////////////
120
/** \relates zypp::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
///////////////////////////////////////////////////////////////////
72
ZYPP_DEFINE_ID_HASHABLE( ::zypp::LanguageCode );
127
74
#endif // ZYPP_LANGUAGECODE_H