LangCode.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       LangCode.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef LangCode_h
00020 #define LangCode_h
00021 
00022 #include <iosfwd>
00023 
00024 #include <y2util/ISOLanguage.h>
00025 #include <y2util/ISOCountry.h>
00026 
00028 //
00029 //      CLASS NAME : LangCode
00033 class LangCode {
00034 
00035   private:
00036 
00037     ISOLanguage _language;
00038     ISOCountry  _country;
00039 
00040   public:
00041 
00042     LangCode() {}
00043 
00044     explicit LangCode( const std::string & code_r );
00045 
00046     LangCode( const ISOLanguage & language_r,
00047               const ISOCountry & country_r = ISOCountry() )
00048       : _language( language_r )
00049       , _country( country_r )
00050     {}
00051 
00052     ~LangCode() {}
00053 
00054     bool isSet() const { return( _language.isSet() || _country.isSet() ); }
00055 
00056     bool hasLanguage() const { return _language.isSet(); }
00057     bool hasCountry() const { return _country.isSet(); }
00058 
00059     std::string code() const;
00060     std::string languageCode() const { return _language.code(); }
00061     std::string countryCode() const { return _country.code(); }
00062 
00063     std::string name() const;
00064     std::string languageName() const { return _language.name(); }
00065     std::string countryName() const { return _country.name(); }
00066 
00067   public:
00068 
00069     ISOLanguage language() const { return _language; }
00070     ISOCountry country() const { return _country; }
00071 };
00072 
00074 
00075 std::ostream & operator<<( std::ostream & str, const LangCode & obj );
00076 
00078 
00079 inline bool operator==( const LangCode & lhs, const LangCode & rhs ) {
00080   return( lhs.code() == rhs.code() );
00081 }
00082 inline bool operator==( const std::string & lhs, const LangCode & rhs ) {
00083   return( lhs == rhs.code() );
00084 }
00085 inline bool operator==( const LangCode & lhs, const std::string & rhs ) {
00086   return( lhs.code() == rhs );
00087 }
00088 
00089 inline bool operator!=( const LangCode & lhs, const LangCode & rhs ) {
00090   return( ! operator==( lhs, rhs ) );
00091 }
00092 inline bool operator!=( const std::string & lhs, const LangCode & rhs ) {
00093   return( ! operator==( lhs, rhs ) );
00094 }
00095 inline bool operator!=( const LangCode & lhs, const std::string & rhs ) {
00096   return( ! operator==( lhs, rhs ) );
00097 }
00098 
00100 
00101 
00102 namespace std {
00103   template<>
00104     inline bool less<LangCode>::operator()( const LangCode & lhs,
00105                                             const LangCode & rhs ) const
00106     {
00107       if ( less<ISOLanguage>()( lhs.language(), rhs.language() ) )
00108         return true;
00109       if ( less<ISOLanguage>()( rhs.language(), lhs.language() ) )
00110         return false;
00111       return less<ISOCountry>()( lhs.country(), rhs.country() );
00112     }
00113 }
00114 
00116 
00117 #endif // LangCode_h

Generated on Fri Jun 16 15:51:35 2006 for liby2util by  doxygen 1.4.6