#pragma once #include #include #include #include #include #include #include #include "src/Services/StringService.hpp" #include "src/Exceptions/Exception.hpp" namespace Targets::TargetDescription { struct Property { std::string key; std::string value; Property(const std::string& key, const std::string& value) : key(key) , value(value) {} }; struct PropertyGroup { std::string key; std::map> propertiesMappedByKey; std::map> subGroupsMappedByKey; PropertyGroup( const std::string& key, const std::map>& propertiesMappedByKey, const std::map>& subGroupsMappedByKey ) : key(key) , propertiesMappedByKey(propertiesMappedByKey) , subGroupsMappedByKey(subGroupsMappedByKey) {} template requires std::ranges::sized_range std::optional> tryGetSubGroup(KeysType keys) const { auto firstSubGroupIt = this->subGroupsMappedByKey.find(*(keys.begin())); if (firstSubGroupIt == this->subGroupsMappedByKey.end()) { return std::nullopt; } auto subGroup = std::optional(std::cref(firstSubGroupIt->second)); for (const auto key : keys | std::ranges::views::drop(1)) { subGroup = subGroup->get().tryGetSubGroup(key); if (!subGroup.has_value()) { break; } } return subGroup; } std::optional> tryGetSubGroup(std::string_view keyStr) const { return this->tryGetSubGroup(Services::StringService::split(keyStr, '.')); } std::optional> 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> tryGetProperty(std::string_view key) const { const auto propertyIt = this->propertiesMappedByKey.find(key); if (propertyIt == this->propertiesMappedByKey.end()) { return std::nullopt; } return std::cref(propertyIt->second); } const Property& getProperty(std::string_view key) const { const auto property = this->tryGetProperty(key); if (!property.has_value()) { throw Exceptions::Exception( "Failed to get property \"" + std::string(key) + "\" from property group in TDF - property not found" ); } return property->get(); } }; }