Remove non-owning string pointer from StringParameter
(For the time being) See: https://github.com/OpenTTD/OpenTTD/issues/11922
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
/** The data required to format and validate a single parameter of a string. */
|
/** The data required to format and validate a single parameter of a string. */
|
||||||
struct StringParameter {
|
struct StringParameter {
|
||||||
uint64_t data; ///< The data of the parameter.
|
uint64_t data; ///< The data of the parameter.
|
||||||
const char *string_view; ///< The string value, if it has any.
|
|
||||||
std::unique_ptr<std::string> string; ///< Copied string value, if it has any.
|
std::unique_ptr<std::string> string; ///< Copied string value, if it has any.
|
||||||
char32_t type; ///< The #StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
|
char32_t type; ///< The #StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
|
||||||
};
|
};
|
||||||
@@ -108,7 +107,7 @@ public:
|
|||||||
const char *GetNextParameterString()
|
const char *GetNextParameterString()
|
||||||
{
|
{
|
||||||
auto ptr = GetNextParameterPointer();
|
auto ptr = GetNextParameterPointer();
|
||||||
return ptr->string != nullptr ? ptr->string->c_str() : ptr->string_view;
|
return ptr->string != nullptr ? ptr->string->c_str() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,7 +153,6 @@ public:
|
|||||||
assert(n < this->parameters.size());
|
assert(n < this->parameters.size());
|
||||||
this->parameters[n].data = v;
|
this->parameters[n].data = v;
|
||||||
this->parameters[n].string.reset();
|
this->parameters[n].string.reset();
|
||||||
this->parameters[n].string_view = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||||
@@ -167,8 +165,7 @@ public:
|
|||||||
{
|
{
|
||||||
assert(n < this->parameters.size());
|
assert(n < this->parameters.size());
|
||||||
this->parameters[n].data = 0;
|
this->parameters[n].data = 0;
|
||||||
this->parameters[n].string.reset();
|
this->parameters[n].string = std::make_unique<std::string>(str);
|
||||||
this->parameters[n].string_view = str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetParam(size_t n, std::string str)
|
void SetParam(size_t n, std::string str)
|
||||||
@@ -176,13 +173,12 @@ public:
|
|||||||
assert(n < this->parameters.size());
|
assert(n < this->parameters.size());
|
||||||
this->parameters[n].data = 0;
|
this->parameters[n].data = 0;
|
||||||
this->parameters[n].string = std::make_unique<std::string>(std::move(str));
|
this->parameters[n].string = std::make_unique<std::string>(std::move(str));
|
||||||
this->parameters[n].string_view = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetParam(size_t n) const
|
uint64_t GetParam(size_t n) const
|
||||||
{
|
{
|
||||||
assert(n < this->parameters.size());
|
assert(n < this->parameters.size());
|
||||||
assert(this->parameters[n].string_view == nullptr && this->parameters[n].string == nullptr);
|
assert(this->parameters[n].string == nullptr);
|
||||||
return this->parameters[n].data;
|
return this->parameters[n].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +191,7 @@ public:
|
|||||||
{
|
{
|
||||||
assert(n < this->parameters.size());
|
assert(n < this->parameters.size());
|
||||||
auto ¶m = this->parameters[n];
|
auto ¶m = this->parameters[n];
|
||||||
return param.string != nullptr ? param.string->c_str() : param.string_view;
|
return param.string != nullptr ? param.string->c_str() : nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user