Added Locale
[platform/upstream/libzypp.git] / zypp / LanguageCode.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/LanguageCode.h
10  *
11 */
12 #ifndef ZYPP_LANGUAGECODE_H
13 #define ZYPP_LANGUAGECODE_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include "zypp/base/PtrTypes.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   class LanguageCode;
25   inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs );
26   inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs );
27
28   ///////////////////////////////////////////////////////////////////
29   //
30   //    CLASS NAME : LanguageCode
31   //
32   /** Language codes (iso639_2/iso639_1).
33    *
34    * In fact the class will not prevent to use a non iso language code.
35    * Just a warning will appear in the log.
36   */
37   class LanguageCode
38   {
39     friend std::ostream & operator<<( std::ostream & str, const LanguageCode & obj );
40
41   public:
42     /** Implementation  */
43     class Impl;
44
45   public:
46     /** Default ctor */
47     LanguageCode();
48
49     /** Ctor taking a string. */
50     explicit
51     LanguageCode( const std::string & code_r );
52
53     /** Dtor */
54     ~LanguageCode();
55
56   public:
57     /** \name LanguageCode constants. */
58     //@{
59     /** No or empty code. */
60     static const LanguageCode noCode;
61     /** Advice to use some default code. */
62     static const LanguageCode useDefault;
63     //@}
64
65   public:
66     /** Return the language code. */
67     std::string code() const;
68
69     /** Return the language name; if not available the language code. */
70     std::string name() const;
71
72     /** <tt>*this != noCode</tt>. */
73     inline bool hasCode() const
74     { return *this != noCode; }
75
76     /** <tt>*this == useDefault</tt>. */
77     bool useDefaultCode() const
78     { return *this == useDefault; }
79
80   private:
81     /** Pointer to implementation */
82     RW_pointer<Impl> _pimpl;
83   };
84   ///////////////////////////////////////////////////////////////////
85
86   /** \relates LanguageCode Stream output */
87   inline std::ostream & operator<<( std::ostream & str, const LanguageCode & obj )
88   { return str << obj.code(); }
89
90   /** Comparison based on string value. */
91   //@{
92   /** \relates LanguageCode */
93   inline bool operator==( const LanguageCode & lhs, const LanguageCode & rhs ) {
94     return( lhs.code() == rhs.code() );
95   }
96   /** \relates LanguageCode */
97   inline bool operator==( const std::string & lhs, const LanguageCode & rhs ) {
98     return( lhs == rhs.code() );
99   }
100   /** \relates LanguageCode */
101   inline bool operator==( const LanguageCode & lhs, const std::string & rhs ) {
102     return( lhs.code() == rhs );
103   }
104
105   /** \relates LanguageCode */
106   inline bool operator!=( const LanguageCode & lhs, const LanguageCode & rhs ) {
107     return( ! operator==( lhs, rhs ) );
108   }
109   /** \relates LanguageCode */
110   inline bool operator!=( const std::string & lhs, const LanguageCode & rhs ) {
111     return( ! operator==( lhs, rhs ) );
112   }
113   /** \relates LanguageCode */
114   inline bool operator!=( const LanguageCode & lhs, const std::string & rhs ) {
115     return( ! operator==( lhs, rhs ) );
116   }
117   //@}
118
119   /////////////////////////////////////////////////////////////////
120 } // namespace zypp
121 ///////////////////////////////////////////////////////////////////
122
123 ///////////////////////////////////////////////////////////////////
124 namespace std
125 { /////////////////////////////////////////////////////////////////
126   /** \relates LanguageCode Default order for std::container based on code string value.*/
127   template<>
128     inline bool less<zypp::LanguageCode>::operator()( const zypp::LanguageCode & lhs, const zypp::LanguageCode & rhs ) const
129     { return lhs.code() < rhs.code(); }
130   /////////////////////////////////////////////////////////////////
131 } // namespace std
132 ///////////////////////////////////////////////////////////////////
133 #endif // ZYPP_LANGUAGECODE_H