mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Saveload: De-duplicate save load struct handler factory lambda
This commit is contained in:
parent
3e1b0f76f4
commit
aef51c08cf
@ -190,6 +190,15 @@ inline constexpr NamedSaveLoad NSLT(const char *name, SaveLoad save_load)
|
||||
return { name, save_load, NSLF_TABLE_ONLY };
|
||||
}
|
||||
|
||||
template<typename T, auto... ARGS>
|
||||
inline constexpr SaveLoadStructHandlerFactory MakeSaveLoadStructHandlerFactory()
|
||||
{
|
||||
SaveLoadStructHandlerFactory factory = []() -> std::unique_ptr<class SaveLoadStructHandler> {
|
||||
return std::make_unique<T>(ARGS...);
|
||||
};
|
||||
return factory;
|
||||
}
|
||||
|
||||
inline constexpr NamedSaveLoad NSLT_STRUCT(const char *name, SaveLoadStructHandlerFactory factory, SaveLoadVersion from = SL_MIN_VERSION, SaveLoadVersion to = SL_MAX_VERSION, SlXvFeatureTest extver = {})
|
||||
{
|
||||
return { name, SaveLoad { true, SL_STRUCT, SLE_FILE_STRUCT, 0, from, to, SLTAG_DEFAULT, { .struct_handler_factory = factory }, extver }, NSLF_TABLE_ONLY };
|
||||
@ -198,10 +207,7 @@ inline constexpr NamedSaveLoad NSLT_STRUCT(const char *name, SaveLoadStructHandl
|
||||
template <typename T>
|
||||
inline constexpr NamedSaveLoad NSLT_STRUCT(const char *name, SaveLoadVersion from = SL_MIN_VERSION, SaveLoadVersion to = SL_MAX_VERSION, SlXvFeatureTest extver = {})
|
||||
{
|
||||
SaveLoadStructHandlerFactory factory = []() -> std::unique_ptr<class SaveLoadStructHandler> {
|
||||
return std::make_unique<T>();
|
||||
};
|
||||
return NSLT_STRUCT(name, factory, from, to, extver);
|
||||
return NSLT_STRUCT(name, MakeSaveLoadStructHandlerFactory<T>(), from, to, extver);
|
||||
}
|
||||
|
||||
inline constexpr NamedSaveLoad NSLT_STRUCTLIST(const char *name, SaveLoadStructHandlerFactory factory, SaveLoadVersion from = SL_MIN_VERSION, SaveLoadVersion to = SL_MAX_VERSION, SlXvFeatureTest extver = {})
|
||||
@ -212,10 +218,7 @@ inline constexpr NamedSaveLoad NSLT_STRUCTLIST(const char *name, SaveLoadStructH
|
||||
template <typename T>
|
||||
inline constexpr NamedSaveLoad NSLT_STRUCTLIST(const char *name, SaveLoadVersion from = SL_MIN_VERSION, SaveLoadVersion to = SL_MAX_VERSION, SlXvFeatureTest extver = {})
|
||||
{
|
||||
SaveLoadStructHandlerFactory factory = []() -> std::unique_ptr<class SaveLoadStructHandler> {
|
||||
return std::make_unique<T>();
|
||||
};
|
||||
return NSLT_STRUCTLIST(name, factory, from, to, extver);
|
||||
return NSLT_STRUCTLIST(name, MakeSaveLoadStructHandlerFactory<T>(), from, to, extver);
|
||||
}
|
||||
|
||||
inline constexpr NamedSaveLoad NSLTAG(uint16_t label_tag, NamedSaveLoad nsl)
|
||||
|
Loading…
Reference in New Issue
Block a user