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