summaryrefslogtreecommitdiff
path: root/src/ini_type.h
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-05-17 23:32:03 +0200
committerMichael Lutz <michi@icosahedron.de>2020-05-21 20:02:34 +0200
commit715aa67a9c13444ee76e717bfa656472f5fb2ac3 (patch)
tree3a9cd303082ced0bceb6246edc02102a28fcc3fd /src/ini_type.h
parent8aef14386fc403ee631f176abf0ec86af7dcd37b (diff)
downloadopenttd-715aa67a9c13444ee76e717bfa656472f5fb2ac3.tar.xz
Codechange: Use std::string in INI file parsing.
Diffstat (limited to 'src/ini_type.h')
-rw-r--r--src/ini_type.h24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/ini_type.h b/src/ini_type.h
index 679969efd..f98b6395b 100644
--- a/src/ini_type.h
+++ b/src/ini_type.h
@@ -11,6 +11,8 @@
#define INI_TYPE_H
#include "fileio_type.h"
+#include <string>
+#include "3rdparty/optional/ottd_optional.h"
/** Types of groups */
enum IniGroupType {
@@ -21,12 +23,12 @@ enum IniGroupType {
/** A single "line" in an ini file. */
struct IniItem {
- IniItem *next; ///< The next item in this group
- char *name; ///< The name of this item
- char *value; ///< The value of this item
- char *comment; ///< The comment associated with this item
+ IniItem *next; ///< The next item in this group
+ std::string name; ///< The name of this item
+ opt::optional<std::string> value; ///< The value of this item
+ std::string comment; ///< The comment associated with this item
- IniItem(struct IniGroup *parent, const char *name, const char *last = nullptr);
+ IniItem(struct IniGroup *parent, const std::string &name);
~IniItem();
void SetValue(const char *value);
@@ -38,13 +40,13 @@ struct IniGroup {
IniGroupType type; ///< type of group
IniItem *item; ///< the first item in the group
IniItem **last_item; ///< the last item in the group
- char *name; ///< name of group
- char *comment; ///< comment for group
+ std::string name; ///< name of group
+ std::string comment; ///< comment for group
- IniGroup(struct IniLoadFile *parent, const char *name, const char *last = nullptr);
+ IniGroup(struct IniLoadFile *parent, const std::string &name);
~IniGroup();
- IniItem *GetItem(const char *name, bool create);
+ IniItem *GetItem(const std::string &name, bool create);
void Clear();
};
@@ -52,14 +54,14 @@ struct IniGroup {
struct IniLoadFile {
IniGroup *group; ///< the first group in the ini
IniGroup **last_group; ///< the last group in the ini
- char *comment; ///< last comment in file
+ std::string comment; ///< last comment in file
const char * const *list_group_names; ///< nullptr terminated list with group names that are lists
const char * const *seq_group_names; ///< nullptr terminated list with group names that are sequences.
IniLoadFile(const char * const *list_group_names = nullptr, const char * const *seq_group_names = nullptr);
virtual ~IniLoadFile();
- IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
+ IniGroup *GetGroup(const std::string &name, bool create_new = true);
void RemoveGroup(const char *name);
void LoadFromDisk(const char *filename, Subdirectory subdir);