Refactored descriptor ID generation and added IDs to peripherals, register groups and registers

This commit is contained in:
Nav
2024-07-25 19:03:26 +01:00
parent 8f7c3bc1be
commit 3f88e2022c
14 changed files with 191 additions and 52 deletions

View File

@@ -6,6 +6,8 @@
#include <iomanip>
#include <ranges>
#include <functional>
#include <unordered_map>
#include <mutex>
namespace Services
{
@@ -100,9 +102,16 @@ namespace Services
return static_cast<std::uint8_t>(StringService::toUint64(str, base));
}
std::size_t StringService::hash(const std::string& str) {
static const auto hash = std::hash<std::string>{};
return hash(str);
std::size_t StringService::generateUniqueInteger(const std::string& str) {
static auto mutex = std::mutex{};
static auto lastValue = std::size_t{0};
static auto map = std::unordered_map<std::string, std::size_t>{};
const auto lock = std::unique_lock{mutex};
const auto valueIt = map.find(str);
return valueIt != map.end() ? valueIt->second : map.emplace(str, ++lastValue).first->second;
}
std::vector<std::string_view> StringService::split(std::string_view str, char delimiter) {