Instance: add method FindPartition()

This commit is contained in:
Max Kellermann 2017-02-20 12:38:27 +01:00
parent a99bab935a
commit e48ea5f23a
3 changed files with 19 additions and 6 deletions

View File

@ -39,6 +39,16 @@ Instance::Instance()
{
}
Partition *
Instance::FindPartition(const char *name)
{
for (auto &partition : partitions)
if (partition.name == name)
return &partition;
return nullptr;
}
#ifdef ENABLE_DATABASE
const Database &

View File

@ -106,6 +106,13 @@ struct Instance final
idle_monitor.OrMask(mask);
}
/**
* Find a #Partition with the given name. Returns nullptr if
* no such partition was found.
*/
gcc_pure
Partition *FindPartition(const char *name);
#ifdef ENABLE_DATABASE
/**
* Returns the global #Database instance. May return nullptr

View File

@ -58,13 +58,9 @@ IsValidPartitionName(const char *name)
gcc_pure
static bool
HasPartitionNamed(const Instance &instance, const char *name)
HasPartitionNamed(Instance &instance, const char *name)
{
for (const auto &partition : instance.partitions)
if (partition.name == name)
return true;
return false;
return instance.FindPartition(name) != nullptr;
}
CommandResult