From ec1cf96b621036f0a60008e095b4fdb7efd91f61 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 10 Oct 2023 19:26:00 +0100 Subject: [PATCH] Codechange: Move initialization of group-type to CreateGroup function. --- src/ini_load.cpp | 11 ++++++----- src/ini_type.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ini_load.cpp b/src/ini_load.cpp index 10a265e5a0..c7f7c59ca6 100644 --- a/src/ini_load.cpp +++ b/src/ini_load.cpp @@ -48,16 +48,13 @@ void IniItem::SetValue(const std::string_view value) * @param parent the file we belong to * @param name the name of the group */ -IniGroup::IniGroup(IniLoadFile *parent, const std::string &name) : next(nullptr), type(IGT_VARIABLES), item(nullptr) +IniGroup::IniGroup(IniLoadFile *parent, const std::string &name, IniGroupType type) : next(nullptr), type(type), item(nullptr) { this->name = StrMakeValid(name); this->last_item = &this->item; *parent->last_group = this; parent->last_group = &this->next; - - if (std::find(parent->list_group_names.begin(), parent->list_group_names.end(), name) != parent->list_group_names.end()) this->type = IGT_LIST; - if (std::find(parent->seq_group_names.begin(), parent->seq_group_names.end(), name) != parent->seq_group_names.end()) this->type = IGT_SEQUENCE; } /** Free everything we loaded. */ @@ -195,7 +192,11 @@ IniGroup &IniLoadFile::GetOrCreateGroup(const std::string &name) */ IniGroup &IniLoadFile::CreateGroup(const std::string &name) { - IniGroup *group = new IniGroup(this, name); + IniGroupType type = IGT_VARIABLES; + if (std::find(this->list_group_names.begin(), this->list_group_names.end(), name) != this->list_group_names.end()) type = IGT_LIST; + if (std::find(this->seq_group_names.begin(), this->seq_group_names.end(), name) != this->seq_group_names.end()) type = IGT_SEQUENCE; + + IniGroup *group = new IniGroup(this, name, type); group->comment = "\n"; return *group; } diff --git a/src/ini_type.h b/src/ini_type.h index cdafeafee8..b0c61dfdb1 100644 --- a/src/ini_type.h +++ b/src/ini_type.h @@ -41,7 +41,7 @@ struct IniGroup { std::string name; ///< name of group std::string comment; ///< comment for group - IniGroup(struct IniLoadFile *parent, const std::string &name); + IniGroup(struct IniLoadFile *parent, const std::string &name, IniGroupType type); ~IniGroup(); IniItem *GetItem(const std::string &name) const;