2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-02-26 19:27:36 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "ModuleInstance.hpp"
|
|
|
|
|
#include "RegisterGroup.hpp"
|
|
|
|
|
|
2024-02-26 19:27:36 +00:00
|
|
|
#include "src/Services/StringService.hpp"
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace Targets::TargetDescription
|
2021-04-04 21:04:12 +01:00
|
|
|
{
|
2021-05-31 01:01:14 +01:00
|
|
|
struct Module
|
|
|
|
|
{
|
2024-02-26 19:27:36 +00:00
|
|
|
std::string key;
|
2021-04-04 21:04:12 +01:00
|
|
|
std::string name;
|
2024-02-26 19:27:36 +00:00
|
|
|
std::string description;
|
|
|
|
|
std::map<std::string, RegisterGroup, std::less<void>> registerGroupsByKey;
|
|
|
|
|
|
|
|
|
|
Module(
|
|
|
|
|
const std::string& key,
|
|
|
|
|
const std::string& name,
|
|
|
|
|
const std::string& description,
|
|
|
|
|
const std::map<std::string, RegisterGroup, std::less<void>>& registerGroupsByKey
|
|
|
|
|
)
|
|
|
|
|
: key(key)
|
|
|
|
|
, name(name)
|
|
|
|
|
, description(description)
|
|
|
|
|
, registerGroupsByKey(registerGroupsByKey)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
std::optional<std::reference_wrapper<const RegisterGroup>> tryGetRegisterGroup(std::string_view keyStr) const {
|
|
|
|
|
const auto keys = Services::StringService::split(keyStr, '.');
|
|
|
|
|
|
|
|
|
|
const auto firstGroupIt = this->registerGroupsByKey.find(*keys.begin());
|
|
|
|
|
return firstGroupIt != this->registerGroupsByKey.end()
|
|
|
|
|
? keys.size() > 1
|
|
|
|
|
? firstGroupIt->second.tryGetSubgroup(keys | std::ranges::views::drop(1))
|
|
|
|
|
: std::optional(std::cref(firstGroupIt->second))
|
|
|
|
|
: std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<std::reference_wrapper<const RegisterGroup>> getRegisterGroup(std::string_view keyStr) const {
|
|
|
|
|
const auto group = this->tryGetRegisterGroup(keyStr);
|
|
|
|
|
if (!group.has_value()) {
|
|
|
|
|
throw Exceptions::InvalidTargetDescriptionDataException(
|
|
|
|
|
"Failed to get register group \"" + std::string(keyStr)
|
|
|
|
|
+ "\" from module in TDF - register group not found"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return group->get();
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|