OpenTTD Source 20241224-master-gee860a5c8e
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.
 
void FreeTranslation ()
 Free all data related to the translation.
 
void Add (std::unique_ptr< LangString > ls)
 Add a newly created LangString.
 
LangStringFind (const std::string_view 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

std::vector< std::unique_ptr< LangString > > strings
 List of all known strings.
 
std::unordered_map< std::string_view, LangString * > name_to_string
 Lookup table for the strings.
 
size_t tabs
 The number of 'tabs' of strings.
 
size_t max_strings
 The maximum number of strings.
 
size_t next_string_id
 The next string ID to allocate.
 

Detailed Description

Information about the currently known strings.

Definition at line 41 of file strgen.h.

Constructor & Destructor Documentation

◆ StringData()

StringData::StringData ( size_t  tabs)

Create a new string data container.

Parameters
tabsThe maximum number of strings.

Definition at line 69 of file strgen_base.cpp.

References max_strings, next_string_id, and strings.

Member Function Documentation

◆ Add()

void StringData::Add ( std::unique_ptr< LangString ls)

Add a newly created LangString.

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

Definition at line 89 of file strgen_base.cpp.

References name_to_string, and strings.

◆ CountInUse()

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 163 of file strgen_base.cpp.

References strings, and TAB_SIZE.

Referenced by LanguageWriter::WriteLang().

◆ Find()

LangString * StringData::Find ( const std::string_view  s)

Find a LangString based on the string name.

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

Definition at line 100 of file strgen_base.cpp.

References name_to_string.

◆ FreeTranslation()

void StringData::FreeTranslation ( )

Free all data related to the translation.

Definition at line 76 of file strgen_base.cpp.

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

Referenced by GameStrings::Compile().

◆ Version()

uint StringData::Version ( ) const

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

Returns
The version number.

Definition at line 127 of file strgen_base.cpp.

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

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

◆ VersionHashStr()

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 114 of file strgen_base.cpp.

Referenced by Version().

Field Documentation

◆ max_strings

size_t StringData::max_strings

The maximum number of strings.

Definition at line 45 of file strgen.h.

Referenced by FreeTranslation(), StringReader::ParseFile(), StringData(), Version(), and HeaderWriter::WriteHeader().

◆ name_to_string

std::unordered_map<std::string_view, LangString *> StringData::name_to_string

Lookup table for the strings.

Definition at line 43 of file strgen.h.

Referenced by Add(), and Find().

◆ next_string_id

size_t StringData::next_string_id

The next string ID to allocate.

Definition at line 46 of file strgen.h.

Referenced by FileStringReader::HandlePragma(), StringReader::ParseFile(), and StringData().

◆ strings

std::vector<std::unique_ptr<LangString> > StringData::strings

List of all known strings.

Definition at line 42 of file strgen.h.

Referenced by Add(), CountInUse(), FreeTranslation(), StringData(), Version(), HeaderWriter::WriteHeader(), and LanguageWriter::WriteLang().

◆ tabs

size_t StringData::tabs

The number of 'tabs' of strings.

Definition at line 44 of file strgen.h.

Referenced by LanguageWriter::WriteLang().


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