* Internal templated helper to save/load a list-like type. * @param storage The storage being manipulated. * @param conv VarType type of variable that is used for calculating the size. * @param cmd The SaveLoadType ware are saving/loading. */
| 1387 | * @param cmd The SaveLoadType ware are saving/loading. |
| 1388 | */ |
| 1389 | static void SlSaveLoad(void *storage, VarType conv, SaveLoadType cmd = SL_VAR) |
| 1390 | { |
| 1391 | assert(cmd == SL_VAR || cmd == SL_REF || cmd == SL_STDSTR); |
| 1392 | |
| 1393 | SlStorageT *list = static_cast<SlStorageT *>(storage); |
| 1394 | |
| 1395 | switch (_sl.action) { |
| 1396 | case SLA_SAVE: |
| 1397 | SlWriteArrayLength(list->size()); |
| 1398 | |
| 1399 | for (auto &item : *list) { |
| 1400 | SlSaveLoadMember(cmd, &item, conv); |
| 1401 | } |
| 1402 | break; |
| 1403 | |
| 1404 | case SLA_LOAD_CHECK: |
| 1405 | case SLA_LOAD: { |
| 1406 | size_t length; |
| 1407 | switch (cmd) { |
| 1408 | case SL_VAR: length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? SlReadUint32() : SlReadArrayLength(); break; |
| 1409 | case SL_REF: length = IsSavegameVersionBefore(SLV_69) ? SlReadUint16() : IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? SlReadUint32() : SlReadArrayLength(); break; |
| 1410 | case SL_STDSTR: length = SlReadArrayLength(); break; |
| 1411 | default: NOT_REACHED(); |
| 1412 | } |
| 1413 | |
| 1414 | list->clear(); |
| 1415 | if constexpr (std::is_same_v<SlStorageT, std::vector<Tvar, Tallocator>>) { |
| 1416 | list->reserve(length); |
| 1417 | } |
| 1418 | |
| 1419 | /* Load each value and push to the end of the storage. */ |
| 1420 | for (size_t i = 0; i < length; i++) { |
| 1421 | Tvar &data = list->emplace_back(); |
| 1422 | SlSaveLoadMember(cmd, &data, conv); |
| 1423 | } |
| 1424 | break; |
| 1425 | } |
| 1426 | |
| 1427 | case SLA_PTRS: |
| 1428 | for (auto &item : *list) { |
| 1429 | SlSaveLoadMember(cmd, &item, conv); |
| 1430 | } |
| 1431 | break; |
| 1432 | |
| 1433 | case SLA_NULL: |
| 1434 | list->clear(); |
| 1435 | break; |
| 1436 | |
| 1437 | default: NOT_REACHED(); |
| 1438 | } |
| 1439 | } |
| 1440 | }; |
| 1441 | |
| 1442 | /** |
nothing calls this directly
no test coverage detected