# strings_func.h

Go to the documentation of this file.

    00001 /* $Id: strings_func.h 24801 2012-12-08 17:18:51Z frosch $ */
    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
    00076   int64 GetInt64(WChar type = 0);
    00077
    00079   int32 GetInt32(WChar type = 0)
    00080   {
    00081     return (int32)this->GetInt64(type);
    00082   }
    00083
    00084   void ShiftParameters(uint amount);
    00085
    00087   uint64 *GetDataPointer() const
    00088   {
    00089     return &this->data[this->offset];
    00090   }
    00091
    00093   uint64 *GetPointerToOffset(uint offset) const
    00094   {
    00095     assert(offset < this->num_param);
    00096     return &this->data[offset];
    00097   }
    00098
    00100   bool HasTypeInformation() const
    00101   {
    00102     return this->type != NULL;
    00103   }
    00104
    00106   WChar GetTypeAtOffset(uint offset) const
    00107   {
    00108     assert(offset < this->num_param);
    00109     assert(this->HasTypeInformation());
    00110     return this->type[offset];
    00111   }
    00112
    00113   void SetParam(uint n, uint64 v)
    00114   {
    00115     assert(n < this->num_param);
    00116     this->data[n] = v;
    00117   }
    00118
    00119   uint64 GetParam(uint n) const
    00120   {
    00121     assert(n < this->num_param);
    00122     return this->data[n];
    00123   }
    00124 };
    00125 extern StringParameters _global_string_params;
    00126
    00127 char *InlineString(char *buf, StringID string);
    00128 char *GetString(char *buffr, StringID string, const char *last);
    00129 char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false);
    00130 const char *GetStringPtr(StringID string);
    00131
    00132 uint ConvertKmhishSpeedToDisplaySpeed(uint speed);
    00133 uint ConvertDisplaySpeedToKmhishSpeed(uint speed);
    00134
    00135 void InjectDParam(uint amount);
    00136
    00143 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
    00144 {
    00145   s[n] = v;
    00146 }
    00147
    00153 static inline void SetDParam(uint n, uint64 v)
    00154 {
    00155   _global_string_params.SetParam(n, v);
    00156 }
    00157
    00158 void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0);
    00159 void SetDParamMaxDigits(uint n, uint count);
    00160
    00161 void SetDParamStr(uint n, const char *str);
    00162
    00163 void CopyInDParam(int offs, const uint64 *src, int num);
    00164 void CopyOutDParam(uint64 *dst, int offs, int num);
    00165 void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
    00166
    00173 static inline uint64 GetDParamX(const uint64 *s, uint n)
    00174 {
    00175   return s[n];
    00176 }
    00177
    00183 static inline uint64 GetDParam(uint n)
    00184 {
    00185   return _global_string_params.GetParam(n);
    00186 }
    00187
    00188 extern TextDirection _current_text_dir;
    00189
    00190 void InitializeLanguagePacks();
    00191 const char *GetCurrentLanguageIsoCode();
    00192
    00193 int CDECL StringIDSorter(const StringID *a, const StringID *b);
    00194
    00198 class MissingGlyphSearcher {
    00199 public:
    00201   virtual ~MissingGlyphSearcher() {}
    00202
    00207   virtual const char *NextString() = 0;
    00208
    00213   virtual FontSize DefaultSize() = 0;
    00214
    00218   virtual void Reset() = 0;
    00219
    00224   virtual bool Monospace() = 0;
    00225
    00231   virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
    00232
    00233   bool FindMissingGlyphs(const char **str);
    00234 };
    00235
    00236 void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = NULL);
    00237
    00238 #endif /* STRINGS_FUNC_H */