OpenTTD Source 20260820-master-g39da062c0c
SaveLoad Struct Reference

SaveLoad type struct. More...

#include <saveload.h>

Public Types

using AddressFunction = const void *(*)(const void *base, size_t extra)
 Function that returns the address of a variable.

Static Public Member Functions

static constexpr bool IsIntegralFileType (VarFileType file_type)
 Check whether the given file type is stored as a simple number.
template<typename T, VarFileType file_type>
static constexpr VarMemType DetermineMemType ()
 Determine the VarMemType type given the variable's decltype and occasionally the file type to distinguish options.

Data Fields

std::string name
 Name of this field (optional, used for tables).
SaveLoadType cmd
 The action to take with the saved/loaded type, All types need different action.
VarType conv
 Type of the variable to be saved; this field combines both FileVarType and MemVarType.
uint16_t length
 (Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
SaveLoadVersion version_from
 Save/load the variable starting from this savegame version.
SaveLoadVersion version_to
 Save/load the variable before this savegame version.
AddressFunction address_func
 Callback function the get the actual variable address in memory.
size_t extra_data
 Extra data for the callback proc.
std::shared_ptr< SaveLoadHandlerhandler
 Custom handler for Save/Load procs.

Detailed Description

SaveLoad type struct.

Do NOT use this directly but use the SLE_ macros defined just below!

Definition at line 765 of file saveload.h.

Member Typedef Documentation

◆ AddressFunction

using SaveLoad::AddressFunction = const void *(*)(const void *base, size_t extra)

Function that returns the address of a variable.

Parameters
baseIn case the variable comes from an object, this is the pointer to the begin of that object. Will be non-nullptr for objects, can be both non-nullptr and nullptr for global variables.
extraAn extra offset to apply. Mostly 0, except for a few LinkGraph settings variables.
Returns
The address of the variable.

Definition at line 773 of file saveload.h.

Member Function Documentation

◆ DetermineMemType()

template<typename T, VarFileType file_type>
constexpr VarMemType SaveLoad::DetermineMemType ( )
inlinestaticconstexpr

Determine the VarMemType type given the variable's decltype and occasionally the file type to distinguish options.

If feasible a sanity check is do to check the file type against the variable's decltype, for example to prevent a bool to be saved as string.

Template Parameters
TThe variable's decltype.
file_typeThe way this variable will be/is stored in the save file.
Returns
The VarMemType.
Note
file_type is a template parameter to be able to perform all type checks at compile time.

Definition at line 817 of file saveload.h.

References DetermineMemType(), I16, I32, I64, I8, IsIntegralFileType(), StringID, T, U16, U32, U64, and U8.

Referenced by DetermineMemType(), and SlCopy().

◆ IsIntegralFileType()

constexpr bool SaveLoad::IsIntegralFileType ( VarFileType file_type)
inlinestaticconstexpr

Check whether the given file type is stored as a simple number.

Parameters
file_typeThe file type to check.
Returns
true iff signed or unsigned 8, 16, 32 or 64 bit integer.

Definition at line 790 of file saveload.h.

References I16, I32, I64, I8, U16, U32, U64, and U8.

Referenced by DetermineMemType().

Field Documentation

◆ address_func

AddressFunction SaveLoad::address_func

Callback function the get the actual variable address in memory.

Definition at line 781 of file saveload.h.

Referenced by GetVariableAddress().

◆ cmd

SaveLoadType SaveLoad::cmd

The action to take with the saved/loaded type, All types need different action.

Definition at line 776 of file saveload.h.

Referenced by GetSavegameFileType(), GetSettingsDesc(), SlCompatTableHeader(), and SlTableHeader().

◆ conv

VarType SaveLoad::conv

Type of the variable to be saved; this field combines both FileVarType and MemVarType.

Definition at line 777 of file saveload.h.

Referenced by GetSavegameFileType(), GetSettingsDesc(), GetVariableAddress(), and SetSettingValue().

◆ extra_data

size_t SaveLoad::extra_data

Extra data for the callback proc.

Definition at line 782 of file saveload.h.

Referenced by GetVariableAddress().

◆ handler

std::shared_ptr<SaveLoadHandler> SaveLoad::handler

Custom handler for Save/Load procs.

Definition at line 783 of file saveload.h.

Referenced by SlCompatTableHeader(), and SlTableHeader().

◆ length

uint16_t SaveLoad::length

(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).

Definition at line 778 of file saveload.h.

Referenced by GetSettingsDesc().

◆ name

std::string SaveLoad::name

Name of this field (optional, used for tables).

Definition at line 775 of file saveload.h.

Referenced by SettingDesc::GetName(), SlCompatTableHeader(), and SlTableHeader().

◆ version_from

SaveLoadVersion SaveLoad::version_from

◆ version_to

SaveLoadVersion SaveLoad::version_to

The documentation for this struct was generated from the following file: