OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
43 this->value.emplace(
value);
97 if (!create)
return nullptr;
133 this->
item =
nullptr;
144 list_group_names(list_group_names),
145 seq_group_names(seq_group_names)
170 if (!create_new)
return nullptr;
184 size_t len = strlen(name);
190 if (
group->
name.compare(0, len, name) == 0) {
195 if (
group ==
nullptr)
return;
197 if (prev !=
nullptr) {
201 this->group = this->group->
next;
205 group->
next =
nullptr;
223 uint comment_size = 0;
224 uint comment_alloc = 0;
227 FILE *in = this->
OpenFile(filename, subdir, &end);
228 if (in ==
nullptr)
return;
233 while ((
size_t)ftell(in) < end && fgets(buffer,
sizeof(buffer), in)) {
236 for (s = buffer; *s ==
' ' || *s ==
'\t'; s++) {}
239 char *e = s + strlen(s);
240 while (e > s && ((c = e[-1]) ==
'\n' || c ==
'\r' || c ==
' ' || c ==
'\t')) e--;
245 uint ns = comment_size + (e - s + 1);
246 uint a = comment_alloc;
249 a = std::max(a, 128U);
250 do a *= 2;
while (a < ns);
253 uint pos = comment_size;
254 comment_size += (e - s + 1);
256 memcpy(
comment + pos, s, e - s);
269 if (comment_size != 0) {
273 }
else if (
group !=
nullptr) {
287 for (t = s; *t !=
'\0' && *t !=
'\"'; t++) {}
288 if (*t ==
'\"') *t =
' ';
290 for (t = s; *t !=
'\0' && *t !=
'=' && *t !=
'\t' && *t !=
' '; t++) {}
295 if (comment_size != 0) {
301 while (*t ==
'=' || *t ==
' ' || *t ==
'\t') t++;
303 bool quoted = (*t ==
'\"');
308 if (e > t && e[-1] ==
'\"') e--;
312 if (!quoted && e == t) {
323 if (comment_size > 0) {
324 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 SetValue(const std::string_view value)
Replace the current value with another value.
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 RemoveItem(const std::string &name)
Remove the item with the given name.
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
std::string StrMakeValid(const std::string &str, StringValidationSettings settings)
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
~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
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