|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
34 this->value.emplace(
value);
55 if (item.name ==
name)
return &item;
69 if (item.name ==
name)
return item;
83 return this->
items.emplace_back(name);
109 list_group_names(list_group_names),
110 seq_group_names(seq_group_names)
122 if (group.name == name)
return &group;
136 if (group.name == name)
return &group;
150 if (group.name == name)
return group;
165 if (std::find(this->
list_group_names.begin(), this->list_group_names.end(), name) != this->list_group_names.end()) type =
IGT_LIST;
166 if (std::find(this->
seq_group_names.begin(), this->seq_group_names.end(), name) != this->seq_group_names.end()) type =
IGT_SEQUENCE;
168 return this->
groups.emplace_back(name, type);
177 size_t len = name.length();
178 this->
groups.remove_if([&name, &len](
const IniGroup &group) {
return group.
name.compare(0, len, name) == 0; });
189 assert(this->
groups.empty());
195 uint comment_size = 0;
196 uint comment_alloc = 0;
199 FILE *in = this->
OpenFile(filename, subdir, &end);
200 if (in ==
nullptr)
return;
205 while ((
size_t)ftell(in) < end && fgets(buffer,
sizeof(buffer), in)) {
208 for (s = buffer; *s ==
' ' || *s ==
'\t'; s++) {}
211 char *e = s + strlen(s);
212 while (e > s && ((c = e[-1]) ==
'\n' || c ==
'\r' || c ==
' ' || c ==
'\t')) e--;
216 if ((group ==
nullptr || group->
type !=
IGT_SEQUENCE) && (*s ==
'#' || *s ==
';' || *s ==
'\0')) {
217 uint ns = comment_size + (e - s + 1);
218 uint a = comment_alloc;
221 a = std::max(a, 128U);
222 do a *= 2;
while (a < ns);
225 uint pos = comment_size;
226 comment_size += (e - s + 1);
228 memcpy(
comment + pos, s, e - s);
241 if (comment_size != 0) {
245 }
else if (group !=
nullptr) {
259 for (t = s; *t !=
'\0' && *t !=
'\"'; t++) {}
260 if (*t ==
'\"') *t =
' ';
262 for (t = s; *t !=
'\0' && *t !=
'=' && *t !=
'\t' && *t !=
' '; t++) {}
267 if (comment_size != 0) {
273 while (*t ==
'=' || *t ==
' ' || *t ==
'\t') t++;
275 bool quoted = (*t ==
'\"');
280 if (e > t && e[-1] ==
'\"') e--;
284 if (!quoted && e == t) {
295 if (comment_size > 0) {
296 this->comment.assign(
comment, comment_size);
void SetValue(const std::string_view value)
Replace the current value with another value.
std::string comment
last comment in file
@ IGT_LIST
A list of values, separated by and terminated by the next group block.
A single "line" in an ini file.
const IniItem * GetItem(const std::string &name) const
Get the item with the given name.
A group within an ini file.
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
void RemoveItem(const std::string &name)
Remove the item with the given name.
IniGroup & GetOrCreateGroup(const std::string &name)
Get the group with the given name, and if it doesn't exist create a new group.
std::list< IniItem > items
all items in the group
const IniGroupNameList seq_group_names
list of group names that are sequences.
void Clear()
Clear all items in the group.
const IniGroupNameList list_group_names
list of group names that are lists
T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
void RemoveGroup(const std::string &name)
Remove the group with the given name.
IniItem(const std::string &name)
Construct a new in-memory item of an Ini file.
IniGroup & CreateGroup(const std::string &name)
Create an group with the given name.
virtual FILE * OpenFile(const std::string &filename, Subdirectory subdir, size_t *size)=0
Open the INI file.
IniItem & GetOrCreateItem(const std::string &name)
Get the item with the given name, and if it doesn't exist create a new item.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
std::optional< std::string > value
The value of this item.
const IniGroup * GetGroup(const std::string &name) const
Get the group with the given name.
IniGroupType
Types of groups.
IniGroupType type
type of group
@ IGT_VARIABLES
Values of the form "landscape = hilly".
std::string comment
comment for group
std::string name
name of group
virtual void ReportFileError(const char *const pre, const char *const buffer, const char *const post)=0
Report an error about the file contents.
IniLoadFile(const IniGroupNameList &list_group_names={}, const IniGroupNameList &seq_group_names={})
Construct a new in-memory Ini file representation.
IniItem & CreateItem(const std::string &name)
Create an item with the given name.
@ IGT_SEQUENCE
A list of uninterpreted lines, terminated by the next group block.
IniGroup(const std::string &name, IniGroupType type)
Construct a new in-memory group of an Ini file.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
std::list< IniGroup > groups
all groups in the ini
std::string name
The name of this item.
std::string comment
The comment associated with this item.
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.