Codechange: Use std::list instead of C-linked list for ini files.
This removes self-management of memory with new/delete and allows simpler iteration.
This commit is contained in:

committed by
Peter Nelson

parent
ec1cf96b62
commit
233aac567b
@@ -21,30 +21,25 @@ enum IniGroupType {
|
||||
|
||||
/** A single "line" in an ini file. */
|
||||
struct IniItem {
|
||||
IniItem *next; ///< The next item in this group
|
||||
std::string name; ///< The name of this item
|
||||
std::optional<std::string> value; ///< The value of this item
|
||||
std::string comment; ///< The comment associated with this item
|
||||
|
||||
IniItem(struct IniGroup *parent, const std::string &name);
|
||||
~IniItem();
|
||||
IniItem(const std::string &name);
|
||||
|
||||
void SetValue(const std::string_view value);
|
||||
};
|
||||
|
||||
/** A group within an ini file. */
|
||||
struct IniGroup {
|
||||
IniGroup *next; ///< the next group within this file
|
||||
std::list<IniItem> items; ///< all items in the group
|
||||
IniGroupType type; ///< type of group
|
||||
IniItem *item; ///< the first item in the group
|
||||
IniItem **last_item; ///< the last item in the group
|
||||
std::string name; ///< name of group
|
||||
std::string comment; ///< comment for group
|
||||
|
||||
IniGroup(struct IniLoadFile *parent, const std::string &name, IniGroupType type);
|
||||
~IniGroup();
|
||||
IniGroup(const std::string &name, IniGroupType type);
|
||||
|
||||
IniItem *GetItem(const std::string &name) const;
|
||||
IniItem *GetItem(const std::string &name);
|
||||
IniItem &GetOrCreateItem(const std::string &name);
|
||||
IniItem &CreateItem(const std::string &name);
|
||||
void RemoveItem(const std::string &name);
|
||||
@@ -55,16 +50,15 @@ struct IniGroup {
|
||||
struct IniLoadFile {
|
||||
using IniGroupNameList = std::initializer_list<std::string_view>;
|
||||
|
||||
IniGroup *group; ///< the first group in the ini
|
||||
IniGroup **last_group; ///< the last group in the ini
|
||||
std::list<IniGroup> groups; ///< all groups in the ini
|
||||
std::string comment; ///< last comment in file
|
||||
const IniGroupNameList list_group_names; ///< list of group names that are lists
|
||||
const IniGroupNameList seq_group_names; ///< list of group names that are sequences.
|
||||
|
||||
IniLoadFile(const IniGroupNameList &list_group_names = {}, const IniGroupNameList &seq_group_names = {});
|
||||
virtual ~IniLoadFile();
|
||||
virtual ~IniLoadFile() { }
|
||||
|
||||
IniGroup *GetGroup(const std::string &name) const;
|
||||
IniGroup *GetGroup(const std::string &name);
|
||||
IniGroup &GetOrCreateGroup(const std::string &name);
|
||||
IniGroup &CreateGroup(const std::string &name);
|
||||
void RemoveGroup(const std::string &name);
|
||||
|
Reference in New Issue
Block a user