src/strings_func.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
child 6877 889301acc299
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file strings_func.h Functions related to OTTD's strings. */
       
     4 
       
     5 #ifndef STRINGS_FUNC_H
       
     6 #define STRINGS_FUNC_H
       
     7 
       
     8 #include "strings_type.h"
       
     9 
       
    10 char *InlineString(char *buf, StringID string);
       
    11 char *GetString(char *buffr, StringID string, const char *last);
       
    12 
       
    13 extern char _userstring[128];
       
    14 
       
    15 void InjectDParam(int amount);
       
    16 
       
    17 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
       
    18 {
       
    19 	s[n] = v;
       
    20 }
       
    21 
       
    22 static inline void SetDParam(uint n, uint64 v)
       
    23 {
       
    24 	extern uint64 _decode_parameters[20];
       
    25 
       
    26 	assert(n < lengthof(_decode_parameters));
       
    27 	_decode_parameters[n] = v;
       
    28 }
       
    29 
       
    30 /* Used to bind a C string name to a dparam number.
       
    31  * NOTE: This has a short lifetime. You can't
       
    32  *       use this string much later or it will be gone. */
       
    33 void SetDParamStr(uint n, const char *str);
       
    34 
       
    35 /** This function takes a C-string and allocates a temporary string ID.
       
    36  * The duration of the bound string is valid only until the next call to GetString,
       
    37  * so be careful. */
       
    38 StringID BindCString(const char *str);
       
    39 
       
    40 static inline uint64 GetDParamX(const uint64 *s, uint n)
       
    41 {
       
    42 	return s[n];
       
    43 }
       
    44 
       
    45 static inline uint64 GetDParam(uint n)
       
    46 {
       
    47 	extern uint64 _decode_parameters[20];
       
    48 
       
    49 	assert(n < lengthof(_decode_parameters));
       
    50 	return _decode_parameters[n];
       
    51 }
       
    52 
       
    53 static inline void CopyInDParam(int offs, const uint64 *src, int num)
       
    54 {
       
    55 	extern uint64 _decode_parameters[20];
       
    56 	memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num));
       
    57 }
       
    58 
       
    59 static inline void CopyOutDParam(uint64 *dst, int offs, int num)
       
    60 {
       
    61 	extern uint64 _decode_parameters[20];
       
    62 	memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num));
       
    63 }
       
    64 
       
    65 extern DynamicLanguages _dynlang; // defined in strings.cpp
       
    66 
       
    67 bool ReadLanguagePack(int index);
       
    68 void InitializeLanguagePacks();
       
    69 
       
    70 int CDECL StringIDSorter(const void *a, const void *b);
       
    71 
       
    72 /** Key comparison function for std::map */
       
    73 struct StringIDCompare
       
    74 {
       
    75 	bool operator()(StringID s1, StringID s2) const { return StringIDSorter(&s1, &s2) < 0; }
       
    76 };
       
    77 
       
    78 void CheckForMissingGlyphsInLoadedLanguagePack();
       
    79 
       
    80 #endif /* STRINGS_TYPE_H */