OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
43 if (
value ==
nullptr) {
46 this->value.emplace(
value);
101 if (!create)
return nullptr;
113 this->
item =
nullptr;
124 list_group_names(list_group_names),
125 seq_group_names(seq_group_names)
150 if (!create_new)
return nullptr;
164 size_t len = strlen(name);
170 if (
group->
name.compare(0, len, name) == 0) {
175 if (
group ==
nullptr)
return;
177 if (prev !=
nullptr) {
181 this->group = this->group->
next;
185 group->
next =
nullptr;
203 uint comment_size = 0;
204 uint comment_alloc = 0;
207 FILE *in = this->
OpenFile(filename, subdir, &end);
208 if (in ==
nullptr)
return;
213 while ((
size_t)ftell(in) < end && fgets(buffer,
sizeof(buffer), in)) {
216 for (s = buffer; *s ==
' ' || *s ==
'\t'; s++) {}
219 char *e = s + strlen(s);
220 while (e > s && ((c = e[-1]) ==
'\n' || c ==
'\r' || c ==
' ' || c ==
'\t')) e--;
225 uint ns = comment_size + (e - s + 1);
226 uint a = comment_alloc;
229 a = std::max(a, 128U);
230 do a *= 2;
while (a < ns);
233 uint pos = comment_size;
234 comment_size += (e - s + 1);
236 memcpy(
comment + pos, s, e - s);
249 if (comment_size != 0) {
253 }
else if (
group !=
nullptr) {
267 for (t = s; *t !=
'\0' && *t !=
'\"'; t++) {}
268 if (*t ==
'\"') *t =
' ';
270 for (t = s; *t !=
'\0' && *t !=
'=' && *t !=
'\t' && *t !=
' '; t++) {}
275 if (comment_size != 0) {
281 while (*t ==
'=' || *t ==
' ' || *t ==
'\t') t++;
283 bool quoted = (*t ==
'\"');
288 if (e > t && e[-1] ==
'\"') e--;
292 if (!quoted && e == t) {
303 if (comment_size > 0) {
304 this->comment.assign(
comment, comment_size);
void RemoveGroup(const char *name)
Remove the group with the given name.
virtual ~IniLoadFile()
Free everything we loaded.
void str_validate(char *str, const char *last, StringValidationSettings settings)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
std::string comment
last comment in file
IniItem * next
The next item in this group.
@ IGT_LIST
A list of values, separated by and terminated by the next group block.
A single "line" in an ini file.
A group within an ini file.
void Clear()
Clear all items in the group.
Ini file that only supports loading.
virtual FILE * OpenFile(const std::string &filename, Subdirectory subdir, size_t *size)=0
Open the INI file.
std::optional< std::string > value
The value of this item.
IniGroupType type
type of group
@ IGT_VARIABLES
Values of the form "landscape = hilly".
IniItem ** last_item
the last item in the group
const char *const * list_group_names
nullptr terminated list with group names that are lists
IniGroup * group
the first group in the ini
std::string comment
comment for group
std::string name
name of group
~IniItem()
Free everything we loaded.
virtual void ReportFileError(const char *const pre, const char *const buffer, const char *const post)=0
Report an error about the file contents.
~IniGroup()
Free everything we loaded.
IniItem(struct IniGroup *parent, const std::string &name)
Construct a new in-memory item of an Ini file.
@ IGT_SEQUENCE
A list of uninterpreted lines, terminated by the next group block.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
IniGroup ** last_group
the last group in the ini
void SetValue(const char *value)
Replace the current value with another value.
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
std::string name
The name of this item.
IniItem * item
the first item in the group
IniLoadFile(const char *const *list_group_names=nullptr, const char *const *seq_group_names=nullptr)
Construct a new in-memory Ini file representation.
const char *const * seq_group_names
nullptr terminated list with group names that are sequences.
std::string comment
The comment associated with this item.
IniItem * GetItem(const std::string &name, bool create)
Get the item with the given name, and if it doesn't exist and create is true it creates a new item.
IniGroup(struct IniLoadFile *parent, const std::string &name)
Construct a new in-memory group of an Ini file.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
IniGroup * GetGroup(const std::string &name, bool create_new=true)
Get the group with the given name.
IniGroup * next
the next group within this file