Codechange: Add VectorSaveLoadHandler to simplify handlers for vectors. (#13093)

This reduces the duplication needed for each saved complex vector.
This commit is contained in:
Peter Nelson
2024-11-17 23:46:32 +00:00
committed by GitHub
parent a6c526cfa0
commit d903806e59
4 changed files with 65 additions and 95 deletions

View File

@@ -441,7 +441,7 @@ public:
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
};
class SlAllowListData : public DefaultSaveLoadHandler<SlAllowListData, CompanyProperties> {
class SlAllowListData : public VectorSaveLoadHandler<SlAllowListData, CompanyProperties, std::string> {
public:
struct KeyWrapper {
std::string key;
@@ -452,23 +452,7 @@ public:
};
inline const static SaveLoadCompatTable compat_description = {};
void Save(CompanyProperties *cprops) const override
{
SlSetStructListLength(cprops->allow_list.size());
for (std::string &str : cprops->allow_list) {
SlObject(&str, this->GetDescription());
}
}
void Load(CompanyProperties *cprops) const override
{
size_t num_keys = SlGetStructListLength(UINT32_MAX);
cprops->allow_list.clear();
cprops->allow_list.resize(num_keys);
for (std::string &str : cprops->allow_list) {
SlObject(&str, this->GetLoadDescription());
}
}
std::vector<std::string> &GetVector(CompanyProperties *cprops) const override { return cprops->allow_list; }
void LoadCheck(CompanyProperties *cprops) const override { this->Load(cprops); }
};