Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

PMLangCode.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                    (C) SuSE Linux AG |
00011 \----------------------------------------------------------------------/
00012 
00013   File:       PMLangCode.h
00014 
00015   Author:     Michael Andres <ma@suse.de>
00016   Maintainer: Michael Andres <ma@suse.de>
00017 
00018   Purpose:
00019 
00020 /-*/
00021 #ifndef PMLangCode_h
00022 #define PMLangCode_h
00023 
00024 #include <iosfwd>
00025 #include <set>
00026 #include <map>
00027 #include <list>
00028 #include <string>
00029 
00030 #include <y2util/LangCode.h>
00031 
00033 namespace PM {
00034 ;
00035 
00039 typedef std::set<LangCode>  LocaleSet;
00040 
00044 typedef std::list<LangCode> LocaleOrder;
00045 
00047 //
00048 //      CLASS NAME : LocaleInfo
00052 struct LocaleInfo {
00056   static LangCode preferredLocale();
00060   static LocaleOrder localeFallback( const LangCode & lang_r );
00064   static LocaleOrder localeFallback() { return localeFallback( preferredLocale() ); }
00065 };
00066 
00068 
00070 //
00071 //      CLASS NAME : LocaleData<_Tp>
00075 template<typename _Tp>
00076 struct LocaleData : public LocaleInfo {
00077   typedef std::map<LangCode,_Tp> datamap;
00078   datamap _datamap;
00079 
00084   _Tp operator()( const LangCode & lang_r ) const {
00085     // ckeck locale and fallbacks
00086     LocaleOrder langs( localeFallback( lang_r ) );
00087     for ( LocaleOrder::const_iterator lang = langs.begin(); lang != langs.end(); ++lang ) {
00088       typename datamap::const_iterator found( _datamap.find( *lang ) );
00089       if ( found != _datamap.end() ) {
00090         return found->second; // gotcha
00091       }
00092     }
00093     // ckeck empty locale
00094     typename datamap::const_iterator found( _datamap.find( LangCode() ) );
00095     if ( found != _datamap.end() ) {
00096       return found->second; // gotcha
00097     }
00098     // nothing found
00099     return _Tp();
00100   }
00101 
00105   _Tp operator()() const { return operator()( preferredLocale() ); }
00106 };
00107 
00109 
00113 typedef LocaleData<std::string> LocaleString;
00114 
00115 
00117 } // namespace PM
00119 
00120 #endif // PMLangCode_h

Generated on Fri Nov 9 14:30:31 2007 for yast2-packagemanager by doxygen 1.3.6