Codechange: separate integer and string usage in StringParameters
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
/** The data required to format and validate a single parameter of a string. */
|
||||
struct StringParameter {
|
||||
uint64_t data; ///< The data of the parameter.
|
||||
const char *string_view; ///< The string value, if it has any.
|
||||
WChar type; ///< The #StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
|
||||
};
|
||||
|
||||
@@ -92,6 +93,18 @@ public:
|
||||
return static_cast<T>(ptr == nullptr ? 0 : ptr->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return The next parameter's value.
|
||||
*/
|
||||
const char *GetNextParameterString()
|
||||
{
|
||||
auto ptr = GetNextParameterPointer();
|
||||
return ptr == nullptr ? nullptr : ptr->string_view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new instance of StringParameters that is a "range" into the
|
||||
* remaining existing parameters. Upon destruction the offset in the parent
|
||||
@@ -134,17 +147,36 @@ public:
|
||||
{
|
||||
assert(n < this->parameters.size());
|
||||
this->parameters[n].data = v;
|
||||
this->parameters[n].string_view = nullptr;
|
||||
}
|
||||
|
||||
void SetParam(size_t n, const char *str)
|
||||
{
|
||||
assert(n < this->parameters.size());
|
||||
this->parameters[n].data = 0;
|
||||
this->parameters[n].string_view = str;
|
||||
}
|
||||
|
||||
void SetParam(size_t n, const char *str) { this->SetParam(n, (uint64_t)(size_t)str); }
|
||||
void SetParam(size_t n, const std::string &str) { this->SetParam(n, str.c_str()); }
|
||||
void SetParam(size_t n, std::string &&str) = delete; // block passing temporaries to SetDParam
|
||||
|
||||
uint64 GetParam(size_t n) const
|
||||
{
|
||||
assert(n < this->parameters.size());
|
||||
assert(this->parameters[n].string_view == nullptr);
|
||||
return this->parameters[n].data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stored string of the parameter, or \c nullptr when there is none.
|
||||
* @param n The index into the parameters.
|
||||
* @return The stored string.
|
||||
*/
|
||||
const char *GetParamStr(size_t n) const
|
||||
{
|
||||
assert(n < this->parameters.size());
|
||||
return this->parameters[n].string_view;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user