OpenTTD Source 20250501-master-ga30f251d05
IniLoadFile Struct Referenceabstract

Ini file that only supports loading. More...

#include <ini_type.h>

Inheritance diagram for IniLoadFile:
IniFile SettingsIniFile ConfigIniFile

Public Types

using IniGroupNameList = std::initializer_list< std::string_view >
 

Public Member Functions

 IniLoadFile (const IniGroupNameList &list_group_names={}, const IniGroupNameList &seq_group_names={})
 Construct a new in-memory Ini file representation.
 
const IniGroupGetGroup (std::string_view name) const
 Get the group with the given name.
 
IniGroupGetGroup (std::string_view name)
 Get the group with the given name.
 
IniGroupGetOrCreateGroup (std::string_view name)
 Get the group with the given name, and if it doesn't exist create a new group.
 
IniGroupCreateGroup (std::string_view name)
 Create an group with the given name.
 
void RemoveGroup (std::string_view name)
 Remove the group with the given name.
 
void LoadFromDisk (std::string_view filename, Subdirectory subdir)
 Load the Ini file's data from the disk.
 
virtual std::optional< FileHandleOpenFile (std::string_view filename, Subdirectory subdir, size_t *size)=0
 Open the INI file.
 
virtual void ReportFileError (std::string_view pre, std::string_view buffer, std::string_view post)=0
 Report an error about the file contents.
 

Data Fields

std::list< IniGroupgroups
 all groups in the ini
 
std::string comment
 last comment in file
 
const IniGroupNameList list_group_names
 list of group names that are lists
 
const IniGroupNameList seq_group_names
 list of group names that are sequences.
 

Detailed Description

Ini file that only supports loading.

Definition at line 50 of file ini_type.h.

Member Typedef Documentation

◆ IniGroupNameList

using IniLoadFile::IniGroupNameList = std::initializer_list<std::string_view>

Definition at line 51 of file ini_type.h.

Constructor & Destructor Documentation

◆ IniLoadFile()

IniLoadFile::IniLoadFile ( const IniGroupNameList &  list_group_names = {},
const IniGroupNameList &  seq_group_names = {} 
)

Construct a new in-memory Ini file representation.

Parameters
list_group_namesA list with group names that should be loaded as lists instead of variables.
See also
IGT_LIST
Parameters
seq_group_namesA list with group names that should be loaded as lists of names.
See also
IGT_SEQUENCE

Definition at line 107 of file ini_load.cpp.

Member Function Documentation

◆ CreateGroup()

IniGroup & IniLoadFile::CreateGroup ( std::string_view  name)

Create an group with the given name.

This does not reuse an existing group of the same name.

Parameters
namename of the group to create.
Returns
the created group.

Definition at line 161 of file ini_load.cpp.

References groups, IGT_LIST, IGT_SEQUENCE, IGT_VARIABLES, list_group_names, and seq_group_names.

Referenced by GetOrCreateGroup(), and LoadFromDisk().

◆ GetGroup() [1/2]

IniGroup * IniLoadFile::GetGroup ( std::string_view  name)

Get the group with the given name.

Parameters
namename of the group to find.
Returns
The requested group or nullptr if not found.

Definition at line 132 of file ini_load.cpp.

References groups.

◆ GetGroup() [2/2]

const IniGroup * IniLoadFile::GetGroup ( std::string_view  name) const

Get the group with the given name.

Parameters
namename of the group to find.
Returns
The requested group or nullptr if not found.

Definition at line 118 of file ini_load.cpp.

References groups.

Referenced by DumpGroup(), DumpSections(), BaseSet< T >::FillSetDetails(), GraphicsSetLoadConfig(), GRFLoadConfig(), IniLoadSettingList(), IniLoadSettings(), IsConversionNeeded(), HotkeyList::Load(), LoadFromConfig(), PickerLoadConfig(), RemoveEntriesFromIni(), and SaveToConfig().

◆ GetOrCreateGroup()

IniGroup & IniLoadFile::GetOrCreateGroup ( std::string_view  name)

Get the group with the given name, and if it doesn't exist create a new group.

Parameters
namename of the group to find.
Returns
the requested group.

Definition at line 146 of file ini_load.cpp.

References CreateGroup(), and groups.

Referenced by GraphicsSetSaveConfig(), IniSaveSettingList(), IniSaveSettings(), PickerSaveConfig(), HotkeyList::Save(), and SaveVersionInConfig().

◆ LoadFromDisk()

void IniLoadFile::LoadFromDisk ( std::string_view  filename,
Subdirectory  subdir 
)

Load the Ini file's data from the disk.

Parameters
filenamethe file to load.
subdirthe sub directory to load the file from.
Precondition
nothing has been loaded yet.

Definition at line 186 of file ini_load.cpp.

References IniItem::comment, IniGroup::comment, comment, CreateGroup(), IniGroup::CreateItem(), groups, IGT_SEQUENCE, OpenFile(), ReportFileError(), StrMakeValid(), IniGroup::type, and IniItem::value.

Referenced by BaseMedia< Tbase_set >::AddFile(), WindowDesc::LoadFromConfig(), ProcessIniFile(), and WindowDesc::SaveToConfig().

◆ OpenFile()

virtual std::optional< FileHandle > IniLoadFile::OpenFile ( std::string_view  filename,
Subdirectory  subdir,
size_t *  size 
)
pure virtual

Open the INI file.

Parameters
filenameName of the INI file.
subdirThe subdir to load the file from.
[out]sizeSize of the opened file.
Returns
File handle of the opened file, or std::nullopt.

Implemented in IniFile, and SettingsIniFile.

Referenced by LoadFromDisk().

◆ RemoveGroup()

void IniLoadFile::RemoveGroup ( std::string_view  name)

Remove the group with the given name.

Parameters
namename of the group to remove.

Definition at line 174 of file ini_load.cpp.

References groups, and IniGroup::name.

Referenced by DeleteGRFPresetFromConfig(), and SaveToConfig().

◆ ReportFileError()

virtual void IniLoadFile::ReportFileError ( std::string_view  pre,
std::string_view  buffer,
std::string_view  post 
)
pure virtual

Report an error about the file contents.

Parameters
prePrefix text of the buffer part.
bufferPart of the file with the error.
postSuffix text of the buffer part.

Implemented in IniFile, and SettingsIniFile.

Referenced by LoadFromDisk().

Field Documentation

◆ comment

std::string IniLoadFile::comment

last comment in file

Definition at line 54 of file ini_type.h.

Referenced by LoadFromDisk(), and IniFile::SaveToDisk().

◆ groups

std::list<IniGroup> IniLoadFile::groups

◆ list_group_names

const IniGroupNameList IniLoadFile::list_group_names

list of group names that are lists

Definition at line 55 of file ini_type.h.

Referenced by CreateGroup().

◆ seq_group_names

const IniGroupNameList IniLoadFile::seq_group_names

list of group names that are sequences.

Definition at line 56 of file ini_type.h.

Referenced by CreateGroup().


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