Added try... member functions to property group class
This commit is contained in:
@@ -40,14 +40,10 @@ namespace Targets::TargetDescription
|
|||||||
, subGroupsMappedByKey(subGroupsMappedByKey)
|
, subGroupsMappedByKey(subGroupsMappedByKey)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::optional<std::reference_wrapper<const PropertyGroup>> getSubGroup(std::string_view keyStr) const {
|
|
||||||
return this->getSubGroup(Services::StringService::split(keyStr, '.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename KeysType>
|
template <typename KeysType>
|
||||||
requires
|
requires
|
||||||
std::ranges::sized_range<KeysType>
|
std::ranges::sized_range<KeysType>
|
||||||
std::optional<std::reference_wrapper<const PropertyGroup>> getSubGroup(KeysType keys) const {
|
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubGroup(KeysType keys) const {
|
||||||
auto firstSubGroupIt = this->subGroupsMappedByKey.find(*(keys.begin()));
|
auto firstSubGroupIt = this->subGroupsMappedByKey.find(*(keys.begin()));
|
||||||
if (firstSubGroupIt == this->subGroupsMappedByKey.end()) {
|
if (firstSubGroupIt == this->subGroupsMappedByKey.end()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -55,7 +51,7 @@ namespace Targets::TargetDescription
|
|||||||
|
|
||||||
auto subGroup = std::optional(std::cref(firstSubGroupIt->second));
|
auto subGroup = std::optional(std::cref(firstSubGroupIt->second));
|
||||||
for (const auto key : keys | std::ranges::views::drop(1)) {
|
for (const auto key : keys | std::ranges::views::drop(1)) {
|
||||||
subGroup = subGroup->get().getSubGroup(key);
|
subGroup = subGroup->get().tryGetSubGroup(key);
|
||||||
|
|
||||||
if (!subGroup.has_value()) {
|
if (!subGroup.has_value()) {
|
||||||
break;
|
break;
|
||||||
@@ -65,6 +61,22 @@ namespace Targets::TargetDescription
|
|||||||
return subGroup;
|
return subGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubGroup(std::string_view keyStr) const {
|
||||||
|
return this->tryGetSubGroup(Services::StringService::split(keyStr, '.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::reference_wrapper<const PropertyGroup>> getSubGroup(std::string_view keyStr) const {
|
||||||
|
const auto propertyGroup = this->tryGetSubGroup(keyStr);
|
||||||
|
if (!propertyGroup.has_value()) {
|
||||||
|
throw Exceptions::Exception(
|
||||||
|
"Failed to get subgroup \"" + std::string(keyStr)
|
||||||
|
+ "\" from property group in TDF - subgroup not found"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return propertyGroup->get();
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<std::reference_wrapper<const Property>> tryGetProperty(std::string_view key) const {
|
std::optional<std::reference_wrapper<const Property>> tryGetProperty(std::string_view key) const {
|
||||||
const auto propertyIt = this->propertiesMappedByKey.find(key);
|
const auto propertyIt = this->propertiesMappedByKey.find(key);
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Targets::TargetDescription
|
|||||||
const auto firstSubGroupIt = this->propertyGroupsMappedByKey.find(*keys.begin());
|
const auto firstSubGroupIt = this->propertyGroupsMappedByKey.find(*keys.begin());
|
||||||
return firstSubGroupIt != this->propertyGroupsMappedByKey.end()
|
return firstSubGroupIt != this->propertyGroupsMappedByKey.end()
|
||||||
? keys.size() > 1
|
? keys.size() > 1
|
||||||
? firstSubGroupIt->second.getSubGroup(keys | std::ranges::views::drop(1))
|
? firstSubGroupIt->second.tryGetSubGroup(keys | std::ranges::views::drop(1))
|
||||||
: std::optional(std::cref(firstSubGroupIt->second))
|
: std::optional(std::cref(firstSubGroupIt->second))
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user