MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FormatValue

Method FormatValue

src/settings.cpp:310–331  ·  view source on GitHub ↗

* Convert an integer-array (intlist) to a string representation. Each value * is separated by a comma or a space character * @param buf output buffer where the string-representation will be stored * @param last last item to write to in the output buffer * @param array pointer to the integer-arrays that is read from * @param nelems the number of elements the array holds. * @param type the typ

Source from the content-addressed store, hash-verified

308 * @param type the type of elements the array holds (eg INT8, UINT16, etc.)
309 */
310std::string ListSettingDesc::FormatValue(const void *object) const
311{
312 const uint8_t *p = static_cast<const uint8_t *>(GetVariableAddress(object, this->save));
313
314 std::string result;
315 for (size_t i = 0; i != this->save.length; i++) {
316 int64_t v;
317 switch (GetVarMemType(this->save.conv)) {
318 case SLE_VAR_BL:
319 case SLE_VAR_I8: v = *(const int8_t *)p; p += 1; break;
320 case SLE_VAR_U8: v = *(const uint8_t *)p; p += 1; break;
321 case SLE_VAR_I16: v = *(const int16_t *)p; p += 2; break;
322 case SLE_VAR_U16: v = *(const uint16_t *)p; p += 2; break;
323 case SLE_VAR_I32: v = *(const int32_t *)p; p += 4; break;
324 case SLE_VAR_U32: v = *(const uint32_t *)p; p += 4; break;
325 default: NOT_REACHED();
326 }
327 if (i != 0) result += ',';
328 format_append(result, "{}", v);
329 }
330 return result;
331}
332
333std::string OneOfManySettingDesc::FormatSingleValue(uint id) const
334{

Callers 4

IniSaveSettingsFunction · 0.45
IConsoleGetSettingFunction · 0.45
SurveySettingsTableFunction · 0.45

Calls 10

ReadMethod · 0.95
FormatSingleValueMethod · 0.95
GetVariableAddressFunction · 0.85
GetVarMemTypeFunction · 0.85
NOT_REACHEDFunction · 0.85
format_appendFunction · 0.85
SetBitIteratorClass · 0.85
IsSignedVarMemTypeFunction · 0.85
formatFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected