OpenTTD Source: StringParameters Class Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Protected Member Functions | Protected Attributes
StringParameters Class Reference

## 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.
| StringParameters (std::span< StringParameter > parameters={})
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.
void | SetOffset (size_t offset)
| Set the offset within the string from where to return the next result of `GetInt64` or `GetInt32`.
void | AdvanceOffset (size_t advance)
| Advance the offset within the string from where to return the next result of `GetInt64` or `GetInt32`.
uint64_t | GetNextParameter ()
| Get the next parameter from our parameters.
template<typename T >
T | GetNextParameter ()
| Get the next parameter from our parameters.
std::string_view | GetNextParameterString ()
| Get the next string parameter from our parameters.
StringParameters | GetRemainingParameters ()
| Get a new instance of StringParameters that is a "range" into the remaining existing parameters.
StringParameters | GetRemainingParameters (size_t offset)
| Get a new instance of StringParameters that is a "range" into the remaining existing parameters from the given offset.
size_t | GetDataLeft () const
| Return the amount of elements which can still be read.
size_t | GetNumParameters () const
| Return the number of parameters.
char32_t | GetTypeAtOffset (size_t offset) const
| Get the type of a specific element.
void | SetParam (size_t n, const StringParameterData &v)
void | SetParam (size_t n, uint64_t v)
void | SetParam (size_t n, ConvertibleThroughBase auto v)
void | SetParam (size_t n, const std::string &str)
void | SetParam (size_t n, std::string &&str)
const StringParameterData & | GetParam (size_t n) const

## Protected Member Functions
const StringParameter & | GetNextParameterReference ()
| Get the next parameter from our parameters.

## 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 18 of file strings_internal.h.

## Constructor & Destructor Documentation

## ◆ StringParameters() [1/2]

StringParameters::StringParameters | ( | StringParameters & | parent,
|  | size_t | size
| ) |  |
| inline

Create a new StringParameters instance that can reference part of the data of the given parent instance.

Definition at line 33 of file strings_internal.h.

## ◆ StringParameters() [2/2]

StringParameters::StringParameters | ( | std::span< StringParameter > | parameters = `{}` | ) |
| inline

Definition at line 38 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 72 of file strings_internal.h.

References parameters.

Referenced by FormatString().

## ◆ GetDataLeft()

size_t StringParameters::GetDataLeft | ( |  | ) | const
| inline

Return the amount of elements which can still be read.

Definition at line 153 of file strings_internal.h.

References offset.

Referenced by FormatString().

## ◆ GetNextParameter() [1/2]

uint64_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 84 of file strings_internal.h.

References GetNextParameterReference().

Referenced by FormatString(), GetNextParameter(), and GetStringWithArgs().

## ◆ GetNextParameter() [2/2]

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.

Template Parameters

  T | The return type of the parameter.

Returns
  The next parameter's value.

Definition at line 104 of file strings_internal.h.

References GetNextParameter().

## ◆ GetNextParameterReference()

const StringParameter & StringParameters::GetNextParameterReference | ( |  | ) |
| 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 next parameter.

Definition at line 68 of file strings.cpp.

References next_type, offset, and parameters.

Referenced by GetNextParameter(), and GetNextParameterString().

## ◆ GetNextParameterString()

std::string_view 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 115 of file strings_internal.h.

References GetNextParameterReference().

Referenced by FormatString().

## ◆ GetNumParameters()

size_t StringParameters::GetNumParameters | ( |  | ) | const
| inline

Return the number of parameters.

Definition at line 159 of file strings_internal.h.

Referenced by FormatString().

## ◆ 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 47 of file strings_internal.h.

References offset.

Referenced by FormatString().

## ◆ GetParam()

const StringParameterData & StringParameters::GetParam | ( | size_t | n | ) | const
| inline

Definition at line 200 of file strings_internal.h.

## ◆ 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 SetParam do update the parameters.

The returned StringParameters must not outlive this StringParameters.

Returns
  A "range" of the string parameters.

Definition at line 135 of file strings_internal.h.

References GetRemainingParameters().

Referenced by FormatString(), and 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 SetParam 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 147 of file strings_internal.h.

References offset.

## ◆ GetTypeAtOffset()

char32_t StringParameters::GetTypeAtOffset | ( | size_t | offset | ) | const
| inline

Get the type of a specific element.

Definition at line 165 of file strings_internal.h.

References offset, and parameters.

Referenced by FormatString().

## ◆ 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 54 of file strings_internal.h.

References offset, and parameters.

Referenced by FormatString().

## ◆ SetParam() [1/5]

void StringParameters::SetParam | ( | size_t | n,
|  | const std::string & | str
| ) |  |
| inline

Definition at line 188 of file strings_internal.h.

## ◆ SetParam() [2/5]

void StringParameters::SetParam | ( | size_t | n,
|  | const StringParameterData & | v
| ) |  |
| inline

Definition at line 171 of file strings_internal.h.

## ◆ SetParam() [3/5]

void StringParameters::SetParam | ( | size_t | n,
|  | ConvertibleThroughBase auto | v
| ) |  |
| inline

Definition at line 183 of file strings_internal.h.

## ◆ SetParam() [4/5]

void StringParameters::SetParam | ( | size_t | n,
|  | std::string && | str
| ) |  |
| inline

Definition at line 194 of file strings_internal.h.

## ◆ SetParam() [5/5]

void StringParameters::SetParam | ( | size_t | n,
|  | uint64_t | v
| ) |  |
| inline

Definition at line 177 of file strings_internal.h.

## ◆ SetTypeOfNextParameter()

void StringParameters::SetTypeOfNextParameter | ( | char32_t | type | ) |
| inline

Definition at line 40 of file strings_internal.h.

## Field Documentation

## ◆ next_type

char32_t StringParameters::next_type = 0
| protected

The type of the next data that is retrieved.

Definition at line 24 of file strings_internal.h.

Referenced by GetNextParameterReference().

## ◆ offset

size_t StringParameters::offset = 0
| protected

Current offset in the parameters span.

Definition at line 23 of file strings_internal.h.

Referenced by GetDataLeft(), GetNextParameterReference(), GetOffset(), GetRemainingParameters(), GetTypeAtOffset(), and SetOffset().

## ◆ parameters

std::span<StringParameter> StringParameters::parameters = {}
| protected

Array with the actual parameters.

Definition at line 21 of file strings_internal.h.

Referenced by AdvanceOffset(), GetNextParameterReference(), GetTypeAtOffset(), and SetOffset().

## ◆ parent

StringParameters* StringParameters::parent = nullptr
| protected

If not nullptr, this instance references data from this parent instance.

Definition at line 20 of file strings_internal.h.

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

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