strings_func.h

Go to the documentation of this file.
00001 /* $Id: strings_func.h 23644 2011-12-20 22:11:22Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef STRINGS_FUNC_H
00013 #define STRINGS_FUNC_H
00014 
00015 #include "strings_type.h"
00016 #include "string_type.h"
00017 #include "gfx_type.h"
00018 
00019 class StringParameters {
00020   StringParameters *parent; 
00021   uint64 *data;             
00022   WChar *type;              
00023 
00024 public:
00025   uint offset;              
00026   uint num_param;           
00027 
00029   StringParameters(uint64 *data, uint num_param, WChar *type) :
00030     parent(NULL),
00031     data(data),
00032     type(type),
00033     offset(0),
00034     num_param(num_param)
00035   { }
00036 
00038   template <size_t Tnum_param>
00039   StringParameters(int64 (&data)[Tnum_param]) :
00040     parent(NULL),
00041     data((uint64 *)data),
00042     type(NULL),
00043     offset(0),
00044     num_param(Tnum_param)
00045   {
00046     assert_compile(sizeof(data[0]) == sizeof(uint64));
00047   }
00048 
00053   StringParameters(StringParameters &parent, uint size) :
00054     parent(&parent),
00055     data(parent.data + parent.offset),
00056     offset(0),
00057     num_param(size)
00058   {
00059     assert(size <= parent.num_param - parent.offset);
00060     if (parent.type == NULL) {
00061       this->type = NULL;
00062     } else {
00063       this->type = parent.type + parent.offset;
00064     }
00065   }
00066 
00067   ~StringParameters()
00068   {
00069     if (this->parent != NULL) {
00070       this->parent->offset += this->num_param;
00071     }
00072   }
00073 
00074   void ClearTypeInformation();
00075 
00080   int64 GetInt64(WChar type = 0)
00081   {
00082     assert(this->offset < this->num_param);
00083     if (this->type != NULL) {
00084       assert(this->type[this->offset] == 0 || this->type[this->offset] == type);
00085       this->type[this->offset] = type;
00086     }
00087     return this->data[this->offset++];
00088   }
00089 
00091   int32 GetInt32(WChar type = 0)
00092   {
00093     return (int32)this->GetInt64(type);
00094   }
00095 
00096   void ShiftParameters(uint amount);
00097 
00099   uint64 *GetDataPointer() const
00100   {
00101     return &this->data[this->offset];
00102   }
00103 
00105   uint64 *GetPointerToOffset(uint offset) const
00106   {
00107     assert(offset < this->num_param);
00108     return &this->data[offset];
00109   }
00110 
00112   bool HasTypeInformation() const
00113   {
00114     return this->type != NULL;
00115   }
00116 
00118   WChar GetTypeAtOffset(uint offset) const
00119   {
00120     assert(offset < this->num_param);
00121     assert(this->HasTypeInformation());
00122     return this->type[offset];
00123   }
00124 
00125   void SetParam(uint n, uint64 v)
00126   {
00127     assert(n < this->num_param);
00128     this->data[n] = v;
00129   }
00130 
00131   uint64 GetParam(uint n) const
00132   {
00133     assert(n < this->num_param);
00134     return this->data[n];
00135   }
00136 };
00137 extern StringParameters _global_string_params;
00138 
00139 char *InlineString(char *buf, StringID string);
00140 char *GetString(char *buffr, StringID string, const char *last);
00141 char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false);
00142 const char *GetStringPtr(StringID string);
00143 
00144 void InjectDParam(uint amount);
00145 
00152 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
00153 {
00154   s[n] = v;
00155 }
00156 
00162 static inline void SetDParam(uint n, uint64 v)
00163 {
00164   _global_string_params.SetParam(n, v);
00165 }
00166 
00167 void SetDParamStr(uint n, const char *str);
00168 
00169 void CopyInDParam(int offs, const uint64 *src, int num);
00170 void CopyOutDParam(uint64 *dst, int offs, int num);
00171 void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
00172 
00179 static inline uint64 GetDParamX(const uint64 *s, uint n)
00180 {
00181   return s[n];
00182 }
00183 
00189 static inline uint64 GetDParam(uint n)
00190 {
00191   return _global_string_params.GetParam(n);
00192 }
00193 
00194 extern TextDirection _current_text_dir; 
00195 
00196 void InitializeLanguagePacks();
00197 const char *GetCurrentLanguageIsoCode();
00198 
00199 int CDECL StringIDSorter(const StringID *a, const StringID *b);
00200 
00204 class MissingGlyphSearcher {
00205 public:
00207   virtual ~MissingGlyphSearcher() {}
00208 
00213   virtual const char *NextString() = 0;
00214 
00219   virtual FontSize DefaultSize() = 0;
00220 
00224   virtual void Reset() = 0;
00225 
00230   virtual bool Monospace() = 0;
00231 
00237   virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
00238 
00239   bool FindMissingGlyphs(const char **str);
00240 };
00241 
00242 void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL);
00243 
00244 #endif /* STRINGS_FUNC_H */