OpenTTD
Public Member Functions | Data Fields
StringData Struct Reference

Information about the currently known strings. More...

#include <strgen.h>

Public Member Functions

 StringData (size_t tabs)
 Create a new string data container.
 ~StringData ()
 Free everything we allocated.
void FreeTranslation ()
 Free all data related to the translation.
uint HashStr (const char *s) const
 Create a hash of the string for finding them back quickly.
void Add (const char *s, LangString *ls)
 Add a newly created LangString.
LangStringFind (const char *s)
 Find a LangString based on the string name.
uint VersionHashStr (uint hash, const char *s) const
 Create a compound hash.
uint Version () const
 Make a hash of the file to get a unique "version number".
uint CountInUse (uint tab) const
 Count the number of tab elements that are in use.

Data Fields

LangString ** strings
 Array of all known strings.
uint16 * hash_heads
 Hash table for the strings.
size_t tabs
 The number of 'tabs' of strings.
size_t max_strings
 The maximum number of strings.
int next_string_id
 The next string ID to allocate.

Detailed Description

Information about the currently known strings.

Definition at line 43 of file strgen.h.

Constructor & Destructor Documentation

StringData::StringData ( size_t  tabs)

Create a new string data container.

Parameters
max_stringsThe maximum number of strings.

Definition at line 90 of file strgen_base.cpp.

References hash_heads, max_strings, next_string_id, and strings.

StringData::~StringData ( )

Free everything we allocated.

Definition at line 98 of file strgen_base.cpp.

References free(), hash_heads, max_strings, and strings.

Member Function Documentation

void StringData::Add ( const char *  s,
LangString ls 
)

Add a newly created LangString.

Parameters
sThe name of the string.
lsThe string to add.

Definition at line 131 of file strgen_base.cpp.

References hash_heads, LangString::hash_next, HashStr(), LangString::index, and strings.

uint StringData::CountInUse ( uint  tab) const

Count the number of tab elements that are in use.

Parameters
tabThe tab to count the elements of.

Definition at line 213 of file strgen_base.cpp.

References strings, and TAB_SIZE.

Referenced by LanguageWriter::WriteLang().

LangString * StringData::Find ( const char *  s)

Find a LangString based on the string name.

Parameters
sThe string name to search on.
Returns
The LangString or NULL if it is not known.

Definition at line 145 of file strgen_base.cpp.

References hash_heads, LangString::hash_next, HashStr(), LangString::name, and strings.

void StringData::FreeTranslation ( )

Free all data related to the translation.

Definition at line 106 of file strgen_base.cpp.

References LangString::FreeTranslation(), max_strings, and strings.

Referenced by GameStrings::Compile().

uint StringData::HashStr ( const char *  s) const

Create a hash of the string for finding them back quickly.

Parameters
sThe string to hash.
Returns
The hashed string.

Definition at line 119 of file strgen_base.cpp.

References max_strings, and ROL().

Referenced by Add(), and Find().

uint StringData::Version ( ) const

Make a hash of the file to get a unique "version number".

Returns
The version number.

Definition at line 177 of file strgen_base.cpp.

References C_DONTCOUNT, LangString::english, MAX_COMMAND_PARAM_SIZE, max_strings, LangString::name, strings, and VersionHashStr().

Referenced by GameStrings::Compile(), HeaderFileWriter::Finalise(), and LanguageWriter::WriteLang().

uint StringData::VersionHashStr ( uint  hash,
const char *  s 
) const

Create a compound hash.

Parameters
hashThe hash to add the string hash to.
sThe string hash.
Returns
The new hash.

Definition at line 164 of file strgen_base.cpp.

References ROL().

Referenced by Version().


The documentation for this struct was generated from the following files: