Codechange: Split GetGroup into GetGroup/GetOrCreateGroup.

This follows the pattern used for GetItem/GetOrCreateItem, and allows use
of references where we know the group must exist.
This commit is contained in:
Peter Nelson
2023-10-10 19:25:58 +01:00
committed by Peter Nelson
parent 54b1a067eb
commit 6ce7195ef1
4 changed files with 36 additions and 26 deletions

View File

@@ -193,6 +193,21 @@ IniGroup *IniLoadFile::GetGroup(const std::string &name, bool create_new)
return &this->CreateGroup(name);
}
/**
* Get the group with the given name, and if it doesn't exist create a new group.
* @param name name of the group to find.
* @return the requested group.
*/
IniGroup &IniLoadFile::GetOrCreateGroup(const std::string &name)
{
for (IniGroup *group = this->group; group != nullptr; group = group->next) {
if (group->name == name) return *group;
}
/* Group doesn't exist, make a new one. */
return this->CreateGroup(name);
}
/**
* Create an group with the given name. This does not reuse an existing group of the same name.
* @param name name of the group to create.