From ff055aa1ce39d51b76e13413263880b9d0619590 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 14 Jun 2026 13:43:46 +0100 Subject: [PATCH] Codechange: make IniGroupType a scoped enum --- src/ini.cpp | 2 +- src/ini_load.cpp | 16 ++++++++-------- src/ini_type.h | 8 ++++---- src/settingsgen/settingsgen.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ini.cpp b/src/ini.cpp index 4c87f089f1..c45cd3ecb5 100644 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -28,7 +28,7 @@ /** * Create a new ini file with given group names. - * @param list_group_names A list with group names that should be loaded as lists instead of variables. @see IGT_LIST + * @param list_group_names A list with group names that should be loaded as lists instead of variables. @see IniGroupType::List */ IniFile::IniFile(const IniGroupNameList &list_group_names) : IniLoadFile(list_group_names) { diff --git a/src/ini_load.cpp b/src/ini_load.cpp index 76d02c1099..6ef3aef0cd 100644 --- a/src/ini_load.cpp +++ b/src/ini_load.cpp @@ -100,8 +100,8 @@ void IniGroup::Clear() /** * Construct a new in-memory Ini file representation. - * @param list_group_names A list with group names that should be loaded as lists instead of variables. @see IGT_LIST - * @param seq_group_names A list with group names that should be loaded as lists of names. @see IGT_SEQUENCE + * @param list_group_names A list with group names that should be loaded as lists instead of variables. @see IniGroupType::List + * @param seq_group_names A list with group names that should be loaded as lists of names. @see IniGroupType::Sequence */ IniLoadFile::IniLoadFile(const IniGroupNameList &list_group_names, const IniGroupNameList &seq_group_names) : list_group_names(list_group_names), @@ -159,9 +159,9 @@ IniGroup &IniLoadFile::GetOrCreateGroup(std::string_view name) */ IniGroup &IniLoadFile::CreateGroup(std::string_view name) { - IniGroupType type = IGT_VARIABLES; - if (std::ranges::find(this->list_group_names, name) != this->list_group_names.end()) type = IGT_LIST; - if (std::ranges::find(this->seq_group_names, name) != this->seq_group_names.end()) type = IGT_SEQUENCE; + IniGroupType type = IniGroupType::Variables; + if (std::ranges::find(this->list_group_names, name) != this->list_group_names.end()) type = IniGroupType::List; + if (std::ranges::find(this->seq_group_names, name) != this->seq_group_names.end()) type = IniGroupType::Sequence; return this->groups.emplace_back(name, type); } @@ -202,8 +202,8 @@ void IniLoadFile::LoadFromDisk(std::string_view filename, Subdirectory subdir) ++line; StringConsumer consumer{StrTrimView(buffer, StringConsumer::WHITESPACE_OR_NEWLINE)}; - /* Skip comments and empty lines outside IGT_SEQUENCE groups. */ - if ((group == nullptr || group->type != IGT_SEQUENCE) && (!consumer.AnyBytesLeft() || consumer.PeekCharIfIn("#;"))) { + /* Skip comments and empty lines outside IniGroupType::Sequence groups. */ + if ((group == nullptr || group->type != IniGroupType::Sequence) && (!consumer.AnyBytesLeft() || consumer.PeekCharIfIn("#;"))) { comment += consumer.GetOrigData(); comment += "\n"; continue; @@ -219,7 +219,7 @@ void IniLoadFile::LoadFromDisk(std::string_view filename, Subdirectory subdir) group->comment = std::move(comment); comment.clear(); // std::move leaves comment in a "valid but unspecified state" according to the specification. } else if (group != nullptr) { - if (group->type == IGT_SEQUENCE) { + if (group->type == IniGroupType::Sequence) { /* A sequence group, use the line as item name without further interpretation. */ IniItem &item = group->CreateItem(consumer.GetOrigData()); item.comment = std::move(comment); diff --git a/src/ini_type.h b/src/ini_type.h index d5b0376e60..833319b634 100644 --- a/src/ini_type.h +++ b/src/ini_type.h @@ -13,10 +13,10 @@ #include "fileio_type.h" /** Types of groups */ -enum IniGroupType : uint8_t { - IGT_VARIABLES = 0, ///< Values of the form "landscape = hilly". - IGT_LIST = 1, ///< A list of values, separated by \n and terminated by the next group block. - IGT_SEQUENCE = 2, ///< A list of uninterpreted lines, terminated by the next group block. +enum class IniGroupType : uint8_t { + Variables, ///< Values of the form "landscape = hilly". + List, ///< A list of values, separated by \n and terminated by the next group block. + Sequence, ///< A list of uninterpreted lines, terminated by the next group block. }; /** A single "line" in an ini file. */ diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index c21571b1d7..a6240d7a70 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -137,8 +137,8 @@ private: struct SettingsIniFile : IniLoadFile { /** * Construct a new ini loader. - * @param list_group_names A list with group names that should be loaded as lists instead of variables. @see IGT_LIST - * @param seq_group_names A list with group names that should be loaded as lists of names. @see IGT_SEQUENCE + * @param list_group_names A list with group names that should be loaded as lists instead of variables. @see IniGroupType::List + * @param seq_group_names A list with group names that should be loaded as lists of names. @see IniGroupType::Sequence */ SettingsIniFile(const IniGroupNameList &list_group_names = {}, const IniGroupNameList &seq_group_names = {}) : IniLoadFile(list_group_names, seq_group_names) @@ -175,14 +175,14 @@ static const std::string_view VALIDATION_GROUP_NAME = "validation"; ///< Name of static const std::string_view DEFAULTS_GROUP_NAME = "defaults"; ///< Name of the group containing default values for the template variables. /** - * Dump a #IGT_SEQUENCE group into #_stored_output. + * Dump a #IniGroupType::Sequence group into #_stored_output. * @param ifile Loaded INI data. * @param group_name Name of the group to copy. */ static void DumpGroup(const IniLoadFile &ifile, std::string_view group_name) { const IniGroup *grp = ifile.GetGroup(group_name); - if (grp != nullptr && grp->type == IGT_SEQUENCE) { + if (grp != nullptr && grp->type == IniGroupType::Sequence) { for (const IniItem &item : grp->items) { if (!item.name.empty()) { _stored_output.Add(item.name);