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