chore: use CommonTechset instead of TechsetDefinition

This commit is contained in:
Jan Laupetin
2026-03-02 22:08:55 +00:00
parent c9d5f208d5
commit e61ec8582a
40 changed files with 306 additions and 301 deletions
+41 -14
View File
@@ -2,21 +2,48 @@
#include <algorithm>
techset::CommonTechniqueTypeNames::CommonTechniqueTypeNames(const char** names, const size_t nameCount)
: m_names(nameCount)
namespace techset
{
std::copy(names, &names[nameCount], m_names.data());
}
CommonTechniqueTypeNames::CommonTechniqueTypeNames(const char** names, const size_t nameCount)
: m_names(nameCount)
{
std::copy(names, &names[nameCount], m_names.data());
const char* techset::CommonTechniqueTypeNames::GetTechniqueTypeName(const size_t techniqueTypeIndex) const
{
if (techniqueTypeIndex >= m_names.size())
return nullptr;
m_technique_type_lookup.reserve(nameCount);
for (size_t i = 0; i < nameCount; i++)
m_technique_type_lookup.emplace(names[i], i);
}
return m_names[techniqueTypeIndex];
}
const char* CommonTechniqueTypeNames::GetTechniqueTypeName(const size_t techniqueTypeIndex) const
{
if (techniqueTypeIndex >= m_names.size())
return nullptr;
size_t techset::CommonTechniqueTypeNames::GetTechniqueTypeCount() const
{
return m_names.size();
}
return m_names[techniqueTypeIndex];
}
[[nodiscard]] std::optional<size_t> CommonTechniqueTypeNames::GetTechniqueTypeByName(const std::string& name) const
{
const auto foundValue = m_technique_type_lookup.find(name);
if (foundValue != m_technique_type_lookup.end())
return foundValue->second;
return std::nullopt;
}
size_t CommonTechniqueTypeNames::GetTechniqueTypeCount() const
{
return m_names.size();
}
CommonTechset::CommonTechset(const size_t techniqueTypeCount)
: m_technique_names(techniqueTypeCount)
{
}
CommonTechset::CommonTechset(std::string name, std::vector<std::string> techniqueNames)
: m_name(std::move(name)),
m_technique_names(std::move(techniqueNames))
{
}
} // namespace techset
+8
View File
@@ -1,7 +1,9 @@
#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
namespace techset
@@ -12,15 +14,21 @@ namespace techset
CommonTechniqueTypeNames(const char** names, size_t nameCount);
[[nodiscard]] const char* GetTechniqueTypeName(size_t techniqueTypeIndex) const;
[[nodiscard]] std::optional<size_t> GetTechniqueTypeByName(const std::string& name) const;
[[nodiscard]] size_t GetTechniqueTypeCount() const;
private:
std::vector<const char*> m_names;
std::unordered_map<std::string, size_t> m_technique_type_lookup;
};
class CommonTechset
{
public:
CommonTechset() = default;
explicit CommonTechset(size_t techniqueTypeCount);
CommonTechset(std::string name, std::vector<std::string> techniqueNames);
std::string m_name;
std::vector<std::string> m_technique_names;
};