Return end of string pointer in SettingDesc formatters
This commit is contained in:
@@ -393,8 +393,9 @@ static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
|
|||||||
* @param array pointer to the integer-arrays that is read from
|
* @param array pointer to the integer-arrays that is read from
|
||||||
* @param nelems the number of elements the array holds.
|
* @param nelems the number of elements the array holds.
|
||||||
* @param type the type of elements the array holds (eg INT8, UINT16, etc.)
|
* @param type the type of elements the array holds (eg INT8, UINT16, etc.)
|
||||||
|
* @return The pointer to the terminating null-character in the destination buffer
|
||||||
*/
|
*/
|
||||||
void ListSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
char *ListSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
||||||
{
|
{
|
||||||
const byte *p = static_cast<const byte *>(GetVariableAddress(object, this->save));
|
const byte *p = static_cast<const byte *>(GetVariableAddress(object, this->save));
|
||||||
int i, v = 0;
|
int i, v = 0;
|
||||||
@@ -416,6 +417,7 @@ void ListSettingDesc::FormatValue(char *buf, const char *last, const void *objec
|
|||||||
buf += seprintf(buf, last, (i == 0) ? "%u" : ",%u", v);
|
buf += seprintf(buf, last, (i == 0) ? "%u" : ",%u", v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *OneOfManySettingDesc::FormatSingleValue(char *buf, const char *last, uint id) const
|
char *OneOfManySettingDesc::FormatSingleValue(char *buf, const char *last, uint id) const
|
||||||
@@ -426,17 +428,17 @@ char *OneOfManySettingDesc::FormatSingleValue(char *buf, const char *last, uint
|
|||||||
return strecpy(buf, this->many[id].c_str(), last);
|
return strecpy(buf, this->many[id].c_str(), last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
char *OneOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
||||||
{
|
{
|
||||||
this->FormatSingleValue(buf, last, value);
|
return this->FormatSingleValue(buf, last, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManyOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
char *ManyOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
||||||
{
|
{
|
||||||
uint bitmask = (uint)value;
|
uint bitmask = (uint)value;
|
||||||
if (bitmask == 0) {
|
if (bitmask == 0) {
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
return;
|
return buf;
|
||||||
}
|
}
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (uint id : SetBitIterator(bitmask)) {
|
for (uint id : SetBitIterator(bitmask)) {
|
||||||
@@ -444,6 +446,7 @@ void ManyOfManySettingDesc::FormatIntValue(char *buf, const char *last, uint32_t
|
|||||||
buf = this->FormatSingleValue(buf, last, id);
|
buf = this->FormatSingleValue(buf, last, id);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -808,20 +811,20 @@ static void IniSaveSettings(IniFile &ini, const SettingTable &settings_table, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
char *IntSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
||||||
{
|
{
|
||||||
uint32_t i = (uint32_t)this->Read(object);
|
uint32_t i = (uint32_t)this->Read(object);
|
||||||
this->FormatIntValue(buf, last, i);
|
return this->FormatIntValue(buf, last, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntSettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
char *IntSettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
||||||
{
|
{
|
||||||
seprintf(buf, last, IsSignedVarMemType(this->save.conv) ? "%d" : "%u", value);
|
return buf + seprintf(buf, last, IsSignedVarMemType(this->save.conv) ? "%d" : "%u", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoolSettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
char *BoolSettingDesc::FormatIntValue(char *buf, const char *last, uint32_t value) const
|
||||||
{
|
{
|
||||||
strecpy(buf, (value != 0) ? "true" : "false", last);
|
return strecpy(buf, (value != 0) ? "true" : "false", last);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
||||||
@@ -837,7 +840,7 @@ bool IntSettingDesc::IsDefaultValue(void *object) const
|
|||||||
return this->def == object_value;
|
return this->def == object_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
char *StringSettingDesc::FormatValue(char *buf, const char *last, const void *object) const
|
||||||
{
|
{
|
||||||
const std::string &str = this->Read(object);
|
const std::string &str = this->Read(object);
|
||||||
switch (GetVarMemType(this->save.conv)) {
|
switch (GetVarMemType(this->save.conv)) {
|
||||||
@@ -847,12 +850,13 @@ void StringSettingDesc::FormatValue(char *buf, const char *last, const void *obj
|
|||||||
if (str.empty()) {
|
if (str.empty()) {
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
} else {
|
} else {
|
||||||
seprintf(buf, last, "\"%s\"", str.c_str());
|
buf += seprintf(buf, last, "\"%s\"", str.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
bool StringSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
||||||
|
@@ -145,8 +145,9 @@ struct SettingDesc {
|
|||||||
* @param buf The before of the buffer to format into.
|
* @param buf The before of the buffer to format into.
|
||||||
* @param last The end of the buffer to format into.
|
* @param last The end of the buffer to format into.
|
||||||
* @param object The object the setting is in.
|
* @param object The object the setting is in.
|
||||||
|
* @return The pointer to the terminating null-character in the destination buffer
|
||||||
*/
|
*/
|
||||||
virtual void FormatValue(char *buf, const char *last, const void *object) const = 0;
|
virtual char *FormatValue(char *buf, const char *last, const void *object) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse/read the value from the Ini item into the setting associated with this object.
|
* Parse/read the value from the Ini item into the setting associated with this object.
|
||||||
@@ -223,8 +224,8 @@ struct IntSettingDesc : SettingDesc {
|
|||||||
void MakeValueValidAndWrite(const void *object, int32_t value) const;
|
void MakeValueValidAndWrite(const void *object, int32_t value) const;
|
||||||
|
|
||||||
virtual size_t ParseValue(const char *str) const;
|
virtual size_t ParseValue(const char *str) const;
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
char *FormatValue(char *buf, const char *last, const void *object) const override;
|
||||||
virtual void FormatIntValue(char *buf, const char *last, uint32_t value) const;
|
virtual char *FormatIntValue(char *buf, const char *last, uint32_t value) const;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
bool IsDefaultValue(void *object) const override;
|
bool IsDefaultValue(void *object) const override;
|
||||||
@@ -246,7 +247,7 @@ struct BoolSettingDesc : IntSettingDesc {
|
|||||||
|
|
||||||
bool IsBoolSetting() const override { return true; }
|
bool IsBoolSetting() const override { return true; }
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatIntValue(char *buf, const char *last, uint32_t value) const override;
|
char *FormatIntValue(char *buf, const char *last, uint32_t value) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** One of many setting. */
|
/** One of many setting. */
|
||||||
@@ -269,7 +270,7 @@ struct OneOfManySettingDesc : IntSettingDesc {
|
|||||||
char *FormatSingleValue(char *buf, const char *last, uint id) const;
|
char *FormatSingleValue(char *buf, const char *last, uint id) const;
|
||||||
|
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatIntValue(char *buf, const char *last, uint32_t value) const override;
|
char *FormatIntValue(char *buf, const char *last, uint32_t value) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Many of many setting. */
|
/** Many of many setting. */
|
||||||
@@ -282,7 +283,7 @@ struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
|||||||
str_val, cat, pre_check, post_callback, many, many_cnvt) {}
|
str_val, cat, pre_check, post_callback, many, many_cnvt) {}
|
||||||
|
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatIntValue(char *buf, const char *last, uint32_t value) const override;
|
char *FormatIntValue(char *buf, const char *last, uint32_t value) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** String settings. */
|
/** String settings. */
|
||||||
@@ -315,7 +316,7 @@ struct StringSettingDesc : SettingDesc {
|
|||||||
bool IsStringSetting() const override { return true; }
|
bool IsStringSetting() const override { return true; }
|
||||||
void ChangeValue(const void *object, std::string &newval, SaveToConfigFlags ini_save_flags) const;
|
void ChangeValue(const void *object, std::string &newval, SaveToConfigFlags ini_save_flags) const;
|
||||||
|
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
char *FormatValue(char *buf, const char *last, const void *object) const override;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
bool IsDefaultValue(void *object) const override;
|
bool IsDefaultValue(void *object) const override;
|
||||||
@@ -333,7 +334,7 @@ struct ListSettingDesc : SettingDesc {
|
|||||||
|
|
||||||
const char *def; ///< default value given when none is present
|
const char *def; ///< default value given when none is present
|
||||||
|
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
char *FormatValue(char *buf, const char *last, const void *object) const override;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
bool IsDefaultValue(void *object) const override;
|
bool IsDefaultValue(void *object) const override;
|
||||||
@@ -346,7 +347,7 @@ struct NullSettingDesc : SettingDesc {
|
|||||||
NullSettingDesc(const SaveLoad &save, const char *name, const char *patx_name) :
|
NullSettingDesc(const SaveLoad &save, const char *name, const char *patx_name) :
|
||||||
SettingDesc(save, name, SF_NOT_IN_CONFIG, nullptr, false, patx_name) {}
|
SettingDesc(save, name, SF_NOT_IN_CONFIG, nullptr, false, patx_name) {}
|
||||||
|
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
|
char *FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
|
||||||
void ParseValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
void ParseValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
bool IsSameValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
||||||
bool IsDefaultValue(void *object) const override { NOT_REACHED(); }
|
bool IsDefaultValue(void *object) const override { NOT_REACHED(); }
|
||||||
|
Reference in New Issue
Block a user