OpenTTD Source  20240919-master-gdf0233f4c2
IniFile Struct Reference

Ini file that supports both loading and saving. More...

#include <ini_type.h>

Inheritance diagram for IniFile:
IniLoadFile ConfigIniFile

Public Member Functions

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

Additional Inherited Members

- Public Types inherited from IniLoadFile
using IniGroupNameList = std::initializer_list< std::string_view >
 
- Data Fields inherited from IniLoadFile
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 supports both loading and saving.

Definition at line 88 of file ini_type.h.

Constructor & Destructor Documentation

◆ IniFile()

IniFile::IniFile ( const IniGroupNameList &  list_group_names = {})

Create a new ini file with given group names.

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

Definition at line 33 of file ini.cpp.

Member Function Documentation

◆ OpenFile()

std::optional< FileHandle > IniFile::OpenFile ( const std::string &  filename,
Subdirectory  subdir,
size_t *  size 
)
overridevirtual

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.

Implements IniLoadFile.

Definition at line 103 of file ini.cpp.

References FioFOpenFile().

◆ ReportFileError()

void IniFile::ReportFileError ( const char *const  pre,
const char *const  buffer,
const char *const  post 
)
overridevirtual

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.

Implements IniLoadFile.

Definition at line 110 of file ini.cpp.

◆ SaveToDisk()

bool IniFile::SaveToDisk ( const std::string &  filename)

Save the Ini file's data to the disk.

Parameters
filenamethe file to save to.
Returns
true if saving succeeded.

Definition at line 42 of file ini.cpp.

References IniItem::comment, IniLoadFile::comment, Debug, IniLoadFile::groups, IniItem::name, OTTD2FS(), and IniItem::value.

Referenced by DeleteGRFPresetFromConfig(), and WindowDesc::SaveToConfig().


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