25 std::optional<std::string>
value;
51 using IniGroupNameList = std::initializer_list<std::string_view>;
76 virtual std::optional<FileHandle>
OpenFile(
const std::string &filename,
Subdirectory subdir,
size_t *size) = 0;
84 virtual void ReportFileError(
const char *
const pre,
const char *
const buffer,
const char *
const post) = 0;
93 std::optional<FileHandle>
OpenFile(
const std::string &filename,
Subdirectory subdir,
size_t *size)
override;
94 void ReportFileError(
const char *
const pre,
const char *
const buffer,
const char *
const post)
override;
Types for Standard In/Out file operations.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
IniGroupType
Types of groups.
@ IGT_SEQUENCE
A list of uninterpreted lines, terminated by the next group block.
@ IGT_VARIABLES
Values of the form "landscape = hilly".
@ IGT_LIST
A list of values, separated by and terminated by the next group block.
Ini file that supports both loading and saving.
std::optional< FileHandle > OpenFile(const std::string &filename, Subdirectory subdir, size_t *size) override
Open the INI file.
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
IniFile(const IniGroupNameList &list_group_names={})
Create a new ini file with given group names.
void ReportFileError(const char *const pre, const char *const buffer, const char *const post) override
Report an error about the file contents.
A group within an ini file.
const IniItem * GetItem(std::string_view name) const
Get the item with the given name.
std::string comment
comment for group
IniGroup(std::string_view name, IniGroupType type)
Construct a new in-memory group of an Ini file.
IniGroupType type
type of group
void Clear()
Clear all items in the group.
void RemoveItem(std::string_view name)
Remove the item with the given name.
std::string name
name of group
IniItem & CreateItem(std::string_view name)
Create an item with the given name.
IniItem & GetOrCreateItem(std::string_view name)
Get the item with the given name, and if it doesn't exist create a new item.
std::list< IniItem > items
all items in the group
A single "line" in an ini file.
std::optional< std::string > value
The value of this item.
std::string name
The name of this item.
std::string comment
The comment associated with this item.
IniItem(std::string_view name)
Construct a new in-memory item of an Ini file.
void SetValue(std::string_view value)
Replace the current value with another value.
Ini file that only supports loading.
std::list< IniGroup > groups
all groups in the ini
void RemoveGroup(std::string_view name)
Remove the group with the given name.
const IniGroupNameList seq_group_names
list of group names that are sequences.
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
IniLoadFile(const IniGroupNameList &list_group_names={}, const IniGroupNameList &seq_group_names={})
Construct a new in-memory Ini file representation.
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
virtual void ReportFileError(const char *const pre, const char *const buffer, const char *const post)=0
Report an error about the file contents.
std::string comment
last comment in file
virtual std::optional< FileHandle > OpenFile(const std::string &filename, Subdirectory subdir, size_t *size)=0
Open the INI file.
IniGroup & CreateGroup(std::string_view name)
Create an group with the given name.
const IniGroupNameList list_group_names
list of group names that are lists
IniGroup & GetOrCreateGroup(std::string_view name)
Get the group with the given name, and if it doesn't exist create a new group.