mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-15 15:19:52 +00:00
Codechange: make IniGroupType a scoped enum
This commit is contained in:
committed by
Peter Nelson
parent
1a2a527530
commit
ff055aa1ce
+1
-1
@@ -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)
|
||||
{
|
||||
|
||||
+8
-8
@@ -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);
|
||||
|
||||
+4
-4
@@ -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. */
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user