00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef ArmageTron_tLocale_H
00028 #define ArmageTron_tLocale_H
00029 
00030 #include "tMemManager.h"
00031 #include "tString.h"
00032 #include "tLinkedList.h"
00033 #include "tError.h"
00034 
00035 class tLocaleItem;
00036 class tOutputItemBase;
00037 
00038 class tLanguage: public tListItem<tLanguage>      
00039 {
00040     tString name;           
00041     mutable tString file;   
00042 public:
00043     tLanguage(const tString& n);
00044 
00045     static tLanguage* FirstLanguage();
00046 
00047     void SetFirstLanguage()  const;  
00048     void SetSecondLanguage() const;
00049 
00050     void Load() const; 
00051     void LoadLater( char const * file ) const; 
00052 
00053     static tLanguage* Find(tString const & name); 
00054     static tLanguage* FindStrict(tString const & name); 
00055     static tLanguage* FindSloppy(tString const & name); 
00056 
00057     const tString& Name(){
00058         return name;
00059     }
00060 };
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 class tOutput{
00080     friend class tOutputItemBase;
00081 
00082     tOutputItemBase *anchor;
00083 
00084     tOutput& operator << (const tOutput &o);
00085 public:
00086     tOutput();
00087     ~tOutput();
00088 
00089     operator const char *() const;   
00090     
00091     void AddLiteral(const char *);       
00092     void AddLocale(const char *);        
00093     void AddSpace();                     
00094 
00095     
00096     tOutput & SetTemplateParameter(int num, const char *parameter);
00097     tOutput & SetTemplateParameter(int num, int         parameter);
00098     tOutput & SetTemplateParameter(int num, float       parameter);
00099 
00100     
00101     void Clear();
00102 
00103     tOutput(const std::string& identifier);
00104     tOutput(const tString& identifier);
00105     tOutput(const char * identifier);
00106     tOutput(const tLocaleItem &locale);
00107 
00108     
00109     template< class T1>
00110     tOutput( char const * identifier, T1 const & template1 )
00111             :anchor(NULL)
00112     {
00113         tASSERT( identifier && identifier[0] == '$' );
00114 
00115         SetTemplateParameter(1, template1);
00116 
00117         *this << identifier;
00118     }
00119 
00120     template< class T1, class T2 >
00121     tOutput( char const * identifier, T1 const & template1, T2 const & template2 )
00122             :anchor(NULL)
00123     {
00124         tASSERT( identifier && identifier[0] == '$' );
00125 
00126         SetTemplateParameter(1, template1);
00127         SetTemplateParameter(2, template2);
00128 
00129         *this << identifier;
00130     }
00131 
00132     template< class T1, class T2, class T3 >
00133     tOutput( char const * identifier, T1 const & template1, T2 const & template2, T3 const & template3 )
00134             :anchor(NULL)
00135     {
00136         tASSERT( identifier && identifier[0] == '$' );
00137 
00138         SetTemplateParameter(1, template1);
00139         SetTemplateParameter(2, template2);
00140         SetTemplateParameter(3, template3);
00141 
00142         *this << identifier;
00143     }
00144 
00145     template< class T1, class T2, class T3, class T4 >
00146     tOutput( char const * identifier, T1 const & template1, T2 const & template2, T3 const & template3, T4 const & template4 )
00147             :anchor(NULL)
00148     {
00149         tASSERT( identifier && identifier[0] == '$' );
00150 
00151         SetTemplateParameter(1, template1);
00152         SetTemplateParameter(2, template2);
00153         SetTemplateParameter(3, template3);
00154         SetTemplateParameter(4, template4);
00155 
00156         *this << identifier;
00157     }
00158 
00159     tOutput(const tOutput &o); 
00160     tOutput& operator=(const tOutput &o); 
00161 
00162     void Append(const tOutput &o);
00163 
00164     bool IsEmpty()const {
00165         return !anchor;
00166     }
00167 };
00168 
00169 class tOutputItemBase: public tListItem<tOutputItemBase>
00170 {
00171 public:
00172     tOutputItemBase(tOutput& o);
00173     virtual ~tOutputItemBase();
00174     virtual void Print(tString& target) const = 0;
00175     virtual void Clone(tOutput& o)      const = 0;
00176 };
00177 
00178 
00179 template <class T>class tOutputItem: public tOutputItemBase
00180 {
00181     T element;
00182     public:
00183 tOutputItem(tOutput& o, const T& e): tOutputItemBase(o), element(e){};
00184 virtual void Print(tString& target) const {
00185     target << element;
00186 }
00187 virtual void Clone(tOutput& o)      const {
00188     tNEW(tOutputItem<T>)(o, element);
00189 }
00190 };
00191 
00192 
00193 
00194 
00195 template<class T> tOutput&  operator<< (tOutput& o, const T& e)
00196 {
00197     tNEW(tOutputItem<T>)(o, e);
00198     return o;
00199 }
00200 
00201 
00202 tOutput& operator << (tOutput &o, const char *locale);
00203 tOutput& operator << (tOutput &o, char *locale);
00204 
00205 
00206 std::ostream& operator<< (std::ostream& s, const tOutput& o);
00207 
00208 tString& operator<< (tString& s, const tOutput& o);
00209 
00210 
00211 
00212 
00213 class tLocale
00214 {
00215 public:
00216     static const tLocaleItem& Find(const char* id);
00217     static void               Load(const char* filename);
00218     static void               Clear();           
00219 };
00220 
00221 std::ostream& operator<< (std::ostream& s, const tLocaleItem& o);
00222 
00223 tString& operator<< (tString& s, const tLocaleItem& o);
00224 
00225 
00226 #endif