|
OpenTTD Source
14.0-beta3
|
10 #ifndef STRINGS_INTERNAL_H
11 #define STRINGS_INTERNAL_H
48 void SetTypeOfNextParameter(char32_t type) { this->next_type = type; }
82 this->offset += advance;
83 assert(this->offset <= this->
parameters.size());
96 return static_cast<T
>(ptr->data);
108 return ptr->string !=
nullptr ? ptr->string->c_str() :
nullptr;
139 return this->parameters.size() - this->
offset;
146 return this->parameters[
offset].type;
149 void SetParam(
size_t n, uint64_t v)
152 this->parameters[n].data = v;
153 this->parameters[n].string.reset();
156 template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value,
int> = 0>
157 void SetParam(
size_t n, T v)
159 SetParam(n, v.base());
162 void SetParam(
size_t n,
const char *str)
165 this->parameters[n].data = 0;
166 this->parameters[n].string = std::make_unique<std::string>(str);
169 void SetParam(
size_t n,
const std::string &str) { this->SetParam(n, str.c_str()); }
171 void SetParam(
size_t n, std::string &&str)
174 this->parameters[n].data = 0;
175 this->parameters[n].string = std::make_unique<std::string>(std::move(str));
178 uint64_t GetParam(
size_t n)
const
181 assert(this->parameters[n].
string ==
nullptr);
182 return this->parameters[n].data;
193 auto ¶m = this->parameters[n];
194 return param.string !=
nullptr ? param.string->c_str() :
nullptr;
209 this->parameters = std::span(
params.data(),
params.size());
214 *
this = std::move(other);
219 this->offset = other.
offset;
220 this->next_type = other.next_type;
221 this->
params = std::move(other.params);
222 this->parameters = std::span(
params.data(),
params.size());
236 template <
typename... Args>
237 static auto MakeParameters(
const Args&... args)
241 (parameters.SetParam(index++, std::forward<const Args&>(args)), ...);
254 using value_type = void;
255 using difference_type = void;
256 using iterator_category = std::output_iterator_tag;
257 using pointer = void;
258 using reference = void;
291 this->
string->push_back(value);
302 *this->
string += str;
312 auto iterator = std::back_inserter(*this->
string);
323 this->
string->erase(this->string->size() - std::min(amount, this->string->size()));
332 return this->
string->size();
341 return (*this->
string)[index];
351 void GRFTownNameGenerate(
StringBuilder &builder, uint32_t grfid, uint16_t gen, uint32_t seed);
void SetOffset(size_t offset)
Set the offset within the string from where to return the next result of GetInt64 or GetInt32.
Equivalent to the std::back_insert_iterator in function, with some convenience helpers for string con...
size_t GetOffset()
Get the current offset, so it can be backed up for certain processing steps, or be used to offset the...
Extension of StringParameters with its own statically sized buffer for the parameters.
void PrepareForNextRun()
Prepare the string parameters for the next formatting run.
uint64_t data
The data of the parameter.
StringParameters * parent
If not nullptr, this instance references data from this parent instance.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
T GetNextParameter()
Get the next parameter from our parameters.
void GenerateTownNameString(StringBuilder &builder, size_t lang, uint32_t seed)
Generates town name from given seed.
const char * GetParamStr(size_t n) const
Get the stored string of the parameter, or nullptr when there is none.
StringParameter * GetNextParameterPointer()
Get the next parameter from our parameters.
The data required to format and validate a single parameter of a string.
const char * GetNextParameterString()
Get the next string parameter from our parameters.
void RemoveElementsFromBack(size_t amount)
Remove the given amount of characters from the back of the string.
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
StringParameters GetRemainingParameters()
Get a new instance of StringParameters that is a "range" into the remaining existing parameters.
uint RemapNewGRFStringControlCode(uint scc, const char **str, StringParameters ¶meters, bool modify_parameters)
FormatString for NewGRF specific "magic" string control codes.
void AdvanceOffset(size_t advance)
Advance the offset within the string from where to return the next result of GetInt64 or GetInt32.
char32_t GetTypeAtOffset(size_t offset) const
Get the type of a specific element.
size_t GetDataLeft() const
Return the amount of elements which can still be read.
StringBuilder & operator+=(const char value)
Operator to add a character to the end of the buffer.
std::array< StringParameter, N > params
The actual parameters.
char & operator[](size_t index)
Get the reference to the character at the given index.
StringBuilder & operator+=(std::string_view str)
Operator to append the given string to the output buffer.
StringBuilder(std::string &string)
Create the builder of an external buffer.
StringParameters(StringParameters &parent, size_t size)
Create a new StringParameters instance that can reference part of the data of the given parent instan...
size_t offset
Current offset in the parameters span.
static void GetTownName(StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts)
Fills builder with specified town name.
std::unique_ptr< std::string > string
Copied string value, if it has any.
size_t CurrentIndex()
Get the current index in the string.
std::span< StringParameter > parameters
Array with the actual parameters.
char32_t type
The StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
StringBuilder & operator=(const char value)
Operator to add a character to the end of the buffer.
StringParameters GetRemainingParameters(size_t offset)
Get a new instance of StringParameters that is a "range" into the remaining existing parameters from ...
void Utf8Encode(char32_t c)
Encode the given Utf8 character into the output buffer.
char32_t next_type
The type of the next data that is retrieved.