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

Function LoadIntList

src/settings.cpp:282–299  ·  view source on GitHub ↗

* Load parsed string-values into an integer-array (intlist) * @param str the string that contains the values (and will be parsed) * @param array pointer to the integer-arrays that will be filled * @param nelems the number of elements the array holds. * @param type the type of elements the array holds (eg INT8, UINT16, etc.) * @return return true on success and false on error */

Source from the content-addressed store, hash-verified

280 * @return return true on success and false on error
281 */
282static bool LoadIntList(std::optional<std::string_view> str, void *array, int nelems, VarType type)
283{
284 size_t elem_size = SlVarSize(type);
285 std::byte *p = static_cast<std::byte *>(array);
286 if (!str.has_value()) {
287 std::fill_n(p, nelems * elem_size, static_cast<std::byte>(0));
288 return true;
289 }
290
291 auto opt_items = ParseIntList(*str);
292 if (!opt_items.has_value() || opt_items->size() != (size_t)nelems) return false;
293
294 for (auto item : *opt_items) {
295 WriteValue(p, type, item);
296 p += elem_size;
297 }
298 return true;
299}
300
301/**
302 * Convert an integer-array (intlist) to a string representation. Each value

Callers 1

ParseValueMethod · 0.85

Calls 5

SlVarSizeFunction · 0.85
fill_nFunction · 0.85
ParseIntListFunction · 0.85
WriteValueFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected