OpenTTD Source: StringParameters Class Reference

OpenTTD Source 14.0-beta1

Public Member Functions | Protected Member Functions | Protected Attributes
StringParameters Class Reference
Inheritance diagram for StringParameters:

## Public Member Functions
| StringParameters (StringParameters &parent, size_t size)
| Create a new StringParameters instance that can reference part of the data of the given parent instance.
void | PrepareForNextRun ()
| Prepare the string parameters for the next formatting run. More...
void | SetTypeOfNextParameter (char32_t type)
size_t | GetOffset ()
| Get the current offset, so it can be backed up for certain processing steps, or be used to offset the argument index within sub strings. More...
void | SetOffset (size_t offset)
| Set the offset within the string from where to return the next result of `GetInt64` or `GetInt32`. More...
void | AdvanceOffset (size_t advance)
| Advance the offset within the string from where to return the next result of `GetInt64` or `GetInt32`. More...
template<typename T >
T | GetNextParameter ()
| Get the next parameter from our parameters. More...
const char * | GetNextParameterString ()
| Get the next string parameter from our parameters. More...
StringParameters | GetRemainingParameters ()
| Get a new instance of StringParameters that is a "range" into the remaining existing parameters. More...
StringParameters | GetRemainingParameters (size_t offset)
| Get a new instance of StringParameters that is a "range" into the remaining existing parameters from the given offset. More...
size_t | GetDataLeft () const
| Return the amount of elements which can still be read.
char32_t | GetTypeAtOffset (size_t offset) const
| Get the type of a specific element.
void | SetParam (size_t n, uint64_t v)
template<typename T , std::enable_if_t< std::is_base_of< StrongTypedefBase, T >::value, int > = 0>
void | SetParam (size_t n, T v)
void | SetParam (size_t n, const char *str)
void | SetParam (size_t n, const std::string &str)
void | SetParam (size_t n, std::string &&str)
uint64_t | GetParam (size_t n) const
const char * | GetParamStr (size_t n) const
| Get the stored string of the parameter, or `nullptr` when there is none. More...

## Protected Member Functions
| StringParameters (std::span< StringParameter > parameters={})
StringParameter * | GetNextParameterPointer ()
| Get the next parameter from our parameters. More...

## Protected Attributes
StringParameters * | parent = nullptr
| If not nullptr, this instance references data from this parent instance.
std::span< StringParameter > | parameters = {}
| Array with the actual parameters.
size_t | offset = 0
| Current offset in the parameters span.
char32_t | next_type = 0
| The type of the next data that is retrieved.

## Detailed Description

Definition at line 23 of file strings_internal.h.

## Member Function Documentation

## ◆ AdvanceOffset()

void StringParameters::AdvanceOffset | ( | size_t | advance | ) |
| inline

Advance the offset within the string from where to return the next result of `GetInt64` or `GetInt32`.

Parameters

  advance | The amount to advance the offset by.

Definition at line 80 of file strings_internal.h.

References parameters.

## ◆ GetNextParameter()

template<typename T >

T StringParameters::GetNextParameter | ( |  | ) |
| inline

Get the next parameter from our parameters.

This updates the offset, so the next time this is called the next parameter will be read.

Returns
  The next parameter's value.

Definition at line 93 of file strings_internal.h.

## ◆ GetNextParameterPointer()

StringParameter * StringParameters::GetNextParameterPointer | ( |  | ) |
| protected

Get the next parameter from our parameters.

This updates the offset, so the next time this is called the next parameter will be read.

Returns
  The pointer to the next parameter.

Definition at line 81 of file strings.cpp.

References next_type.

Referenced by GetNextParameterString().

## ◆ GetNextParameterString()

const char* StringParameters::GetNextParameterString | ( |  | ) |
| inline

Get the next string parameter from our parameters.

This updates the offset, so the next time this is called the next parameter will be read.

Returns
  The next parameter's value.

Definition at line 105 of file strings_internal.h.

References GetNextParameterPointer().

## ◆ GetOffset()

size_t StringParameters::GetOffset | ( |  | ) |
| inline

Get the current offset, so it can be backed up for certain processing steps, or be used to offset the argument index within sub strings.

Returns
  The current offset.

Definition at line 55 of file strings_internal.h.

References offset.

Referenced by FormatString().

## ◆ GetParamStr()

const char* StringParameters::GetParamStr | ( | size_t | n | ) | const
| inline

Get the stored string of the parameter, or `nullptr` when there is none.

Parameters

  n | The index into the parameters.

Returns
  The stored string.

Definition at line 190 of file strings_internal.h.

References parameters.

## ◆ GetRemainingParameters() [1/2]

StringParameters StringParameters::GetRemainingParameters | ( |  | ) |
| inline

Get a new instance of StringParameters that is a "range" into the remaining existing parameters.

Upon destruction the offset in the parent is not updated. However, calls to SetDParam do update the parameters.

The returned StringParameters must not outlive this StringParameters.

Returns
  A "range" of the string parameters.

Definition at line 119 of file strings_internal.h.

References GetRemainingParameters().

Referenced by GetRemainingParameters().

## ◆ GetRemainingParameters() [2/2]

StringParameters StringParameters::GetRemainingParameters | ( | size_t | offset | ) |
| inline

Get a new instance of StringParameters that is a "range" into the remaining existing parameters from the given offset.

Upon destruction the offset in the parent is not updated. However, calls to SetDParam do update the parameters.

The returned StringParameters must not outlive this StringParameters.

Parameters

  offset | The offset to get the remaining parameters for.

Returns
  A "range" of the string parameters.

Definition at line 131 of file strings_internal.h.

References offset.

## ◆ PrepareForNextRun()

void StringParameters::PrepareForNextRun | ( |  | ) |

Prepare the string parameters for the next formatting run.

This means resetting the type information and resetting the offset to the begin.

Definition at line 68 of file strings.cpp.

References offset, and parameters.

## ◆ SetOffset()

void StringParameters::SetOffset | ( | size_t | offset | ) |
| inline

Set the offset within the string from where to return the next result of `GetInt64` or `GetInt32`.

Parameters

  offset | The offset.

Definition at line 62 of file strings_internal.h.

References offset, and parameters.

Referenced by FormatString().

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

- src/strings_internal.h
- src/strings.cpp