Codechange: Use std::array as simple string parameter container.

ArrayStringParameters contains extra state that is used when formatting strings which isn't needed when creating parameter lists.

MakeParameters() now returns a std::array which contains only the parameter data. This simpler container is more widely available than before.
This commit is contained in:
2024-12-06 22:16:00 +00:00
committed by Peter Nelson
parent fb70a7fe7e
commit be00fd4447
6 changed files with 78 additions and 37 deletions

View File

@@ -10,6 +10,7 @@
#ifndef STRINGS_TYPE_H
#define STRINGS_TYPE_H
#include "core/convertible_through_base.hpp"
#include "core/strong_typedef_type.hpp"
/**
@@ -73,4 +74,21 @@ static constexpr StringID SPECSTR_PRESIDENT_NAME = 0x70E7; ///< Special string f
using StringParameterData = std::variant<uint64_t, std::string>;
/** The data required to format and validate a single parameter of a string. */
struct StringParameter {
StringParameterData data; ///< The data of the parameter.
char32_t type; ///< The #StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
StringParameter() = default;
inline StringParameter(StringParameterData &&data) : data(std::move(data)), type(0) {}
inline StringParameter(uint64_t data) : data(data), type(0) {}
inline StringParameter(const char *data) : data(std::string{data}), type(0) {}
inline StringParameter(std::string &&data) : data(std::move(data)), type(0) {}
inline StringParameter(const std::string &data) : data(data), type(0) {}
inline StringParameter(const ConvertibleThroughBase auto &data) : data(static_cast<uint64_t>(data.base())), type(0) {}
};
#endif /* STRINGS_TYPE_H */