Codechange: add clearer named function to get the next (string) parameter

pull/603/head
Rubidium 1 year ago committed by rubidium42
parent ee34fae09a
commit e7937efb01

@ -72,26 +72,28 @@ void StringParameters::PrepareForNextRun()
/** /**
* Read an int64 from the argument array. The offset is increased * Get the next parameter from our parameters.
* so the next time GetInt64 is called the next value is read. * This updates the offset, so the next time this is called the next parameter
* will be read.
* @return The pointer to the next parameter.
*/ */
int64 StringParameters::GetInt64() StringParameter *StringParameters::GetNextParameterPointer()
{ {
assert(this->next_type == 0 || (SCC_CONTROL_START <= this->next_type && this->next_type <= SCC_CONTROL_END)); assert(this->next_type == 0 || (SCC_CONTROL_START <= this->next_type && this->next_type <= SCC_CONTROL_END));
if (this->offset >= this->parameters.size()) { if (this->offset >= this->parameters.size()) {
Debug(misc, 0, "Trying to read invalid string parameter"); Debug(misc, 0, "Trying to read invalid string parameter");
return 0; return nullptr;
} }
auto &param = this->parameters[this->offset++]; auto &param = this->parameters[this->offset++];
if (param.type != 0 && param.type != this->next_type) { if (param.type != 0 && param.type != this->next_type) {
Debug(misc, 0, "Trying to read string parameter with wrong type"); Debug(misc, 0, "Trying to read string parameter with wrong type");
this->next_type = 0; this->next_type = 0;
return 0; return nullptr;
} }
param.type = next_type; param.type = this->next_type;
this->next_type = 0; this->next_type = 0;
return param.data; return &param;
} }

@ -32,6 +32,8 @@ protected:
parameters(parameters) parameters(parameters)
{} {}
StringParameter *GetNextParameterPointer();
public: public:
/** /**
* Create a new StringParameters instance that can reference part of the data of * Create a new StringParameters instance that can reference part of the data of
@ -77,12 +79,28 @@ public:
this->offset = offset; this->offset = offset;
} }
int64 GetInt64(); /**
* Get the next 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.
*/
template <typename T>
T GetNextParameter()
{
auto ptr = GetNextParameterPointer();
return static_cast<T>(ptr == nullptr ? 0 : ptr->data);
}
int64 GetInt64()
{
return GetNextParameter<int64_t>();
}
/** Read an int32 from the argument array. @see GetInt64. */ /** Read an int32 from the argument array. @see GetInt64. */
int32 GetInt32() int32 GetInt32()
{ {
return (int32)this->GetInt64(); return GetNextParameter<int32_t>();
} }
/** /**

Loading…
Cancel
Save