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

locale.h

Go to the documentation of this file.
00001 #ifndef locale_h
00002 #define locale_h
00003 
00004 #include "tag.h"
00005 
00006 class ostream;
00007 
00009 class Locale : private Tag
00010 {
00011  private:
00012   std::string language;
00013 
00014   bool is_valid_tag;
00015   bool isdefault;
00016 
00017  public:
00018   Locale( Line& line );
00019   Locale() : Tag() {}
00020 
00021   bool operator!() const { return !is_valid_tag; } 
00022 
00024   std::string get_language() const { return language; }
00025 
00027   bool is_default() const { return isdefault; };
00028 
00029   Line get_line() const { return Tag::get_line(); }
00030 };
00031 
00033 class LocaleClose : private Tag
00034 {
00035  private:
00036   
00037   bool is_valid_tag;
00038  public:
00039   LocaleClose( Line& line );
00040   LocaleClose() : Tag() {}
00041 
00043   bool operator!() const { return !is_valid_tag; }
00044 };
00045 
00046 
00048 /*** the locale tags are used like this:
00049  *
00050  *     <locale>
00051  *       <locale language="de">
00052  *         Hallo Welt!
00053  *       </locale>
00054  *       <locale language="en">
00055  *         Hello world!
00056  *       </locale>
00057  *     </locale>
00058 */
00059 class LocaleSwitcher
00060 {
00061  public:
00062   typedef enum What
00063     {
00064       LOCALE_OPEN,  
00065       LOCALE_LANG,  
00066       LOCALE_CLOSE, 
00067       OTHERS        
00068     };
00069 
00070   typedef struct Tag
00071   {
00072     Locale locale;
00073     Locale locale_lang;
00074     LocaleClose locale_close;
00075     std::string other;
00076 
00077     What what;
00078 
00079     Tag(): what( OTHERS ) {}
00080 
00081     Tag( Locale l ) : locale( l ), locale_lang( l )
00082     { if( l.get_language().empty() ) what = LOCALE_OPEN;  else what = LOCALE_LANG; }
00083 
00084     Tag( std::string o ) : other( o ), what( OTHERS ) {}
00085 
00086     Tag( LocaleClose lc ) : locale_close( lc ), what( LOCALE_CLOSE ) {}
00087   };
00088 
00089   typedef std::list<Tag> tag_list;
00090   typedef tag_list::iterator tag_list_it;
00091 
00092 public:
00093   struct Error
00094   {
00095     enum Type 
00096       {
00097         OK = 0,
00098         NOT_SANE,
00099         LANG_LIST,
00100         LANG_NOT_FOUND,
00101         MULTIPLE_DEFAULTS,
00102         DOUBLE_LOCALE,
00103         DEFAULT_LANG
00104       };
00105 
00106     Type type;
00107     std::string err;
00108 
00109     Error() : type( OK ) {}
00110 
00111     Error( Type t, std::string e )
00112       : type( t ), err( e ) {}
00113 
00114     void operator = ( const Error e )
00115     { 
00116       if( type == OK )
00117         {
00118           type = e.type;
00119           err = e.err;
00120         }
00121       else
00122         err += "; " + e.err; 
00123     }
00124   };
00125 
00126  private:
00127 
00129   struct Language
00130   {
00131     Locale locale; 
00132     
00133     typedef std::list<std::string> string_list;
00134     typedef string_list::iterator string_list_it;
00135 
00136     string_list others; 
00137     
00138     std::string get_language() const { return locale.get_language(); }
00139     void add( std::string s ) { others.push_back( s ); }
00140     bool is_default() const { return locale.is_default(); }
00141   };
00142 
00143   Language lang;
00144 
00145   typedef std::list<Language> language_list;
00146   typedef language_list::iterator language_list_it;
00147 
00148   language_list langs;
00149 
00150   tag_list tlist;
00151 
00152   bool is_valid; 
00153   std::string language; 
00154   
00155   Error error;
00156 
00157  public:
00158 
00159   LocaleSwitcher( tag_list tlist, std::string language, bool no_lang_warn = true );
00160 
00161   bool operator!() const { return !is_valid; }
00162 
00163   std::string get_locale(); 
00164 
00165   Error get_error() const { return error; }
00166 
00167  private:
00168 
00170   /*** returns true if the system is sane */
00171   bool create_lang_list(); 
00172 
00173   bool is_sane(); 
00174 
00176 
00177   bool find_language(); 
00178 
00179   friend  std::ostream& operator << ( std::ostream& , const LocaleSwitcher::Tag& t );
00180 
00181   bool compare_language( std::string loc_lang, std::string lang );
00182 };
00183 
00184 std::ostream& operator << ( std::ostream& , const LocaleSwitcher::Tag& t );
00185 
00186 #endif

Generated on Tue Nov 20 02:19:52 2001 for Leo<HTML> by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001