SlHelpers
Loading...
Searching...
No Matches
CollectConfigs.h
1// SPDX-License-Identifier: GPL-2.0-only
2
3#pragma once
4
5#include <filesystem>
6#include <string>
7#include <unordered_map>
8
9#include "../helpers/String.h"
10
11namespace SlGit {
12class Commit;
13class Repo;
14class TreeEntry;
15}
16
17namespace SlKernCVS {
18
20enum class ConfigValue : char {
21 Disabled = 'n',
22 BuiltIn = 'y',
23 Module = 'm',
24 WithValue = 'v',
25};
26
32public:
33
35 using ConfigMap = std::unordered_map<std::string, ConfigValue, SlHelpers::String::Hash,
38 using FlavorMap = std::unordered_map<std::string, ConfigMap, SlHelpers::String::Hash,
41 using ArchMap = std::unordered_map<std::string, FlavorMap, SlHelpers::String::Hash,
43
49
51 CollectConfigs(const CollectConfigs &) = delete;
54
59
65 static CollectConfigs create(const std::filesystem::path &repoPath,
66 const std::string &rev);
67
69 const auto &getArchMap() const {
70 return m_archs;
71 }
72
74 const auto &getFlavorMap(const std::string &arch) const {
75 return m_archs.at(arch);
76 }
77
79 const auto &getConfigMap(const std::string &arch, const std::string &flavor) const {
80 return m_archs.at(arch).at(flavor);
81 }
82
84 auto getConfig(const std::string &arch, const std::string &flavor,
85 const std::string &config) const {
86 return m_archs.at(arch).at(flavor).at(config);
87 }
88
90 auto begin() const {
91 return m_archs.begin();
92 }
93
95 auto end() const {
96 return m_archs.end();
97 }
98
99private:
100 void processFlavor(const SlGit::Repo &repo, std::string &&arch, std::string &&flavor,
101 const SlGit::TreeEntry &treeEntry);
102 void processConfigFile(std::string &&arch, std::string &&flavor,
103 std::string_view configFile);
104 void processConfig(ConfigMap &map, std::string_view line);
105
106 ArchMap m_archs;
107};
108
109}
Commit is a representation of a git commit.
Definition Commit.h:21
The most important Git class.
Definition Repo.h:45
The TreeEntry represents one git tree entry.
Definition Tree.h:107
static CollectConfigs create(const std::filesystem::path &repoPath, const std::string &rev)
Create a CollectConfigs from the repoPath and rev.
const auto & getArchMap() const
Get the arch map.
Definition CollectConfigs.h:69
auto begin() const
Get the archs iterator.
Definition CollectConfigs.h:90
const auto & getConfigMap(const std::string &arch, const std::string &flavor) const
Get the config map for a given arch, flavor.
Definition CollectConfigs.h:79
std::unordered_map< std::string, ConfigValue, SlHelpers::String::Hash, SlHelpers::String::Eq > ConfigMap
Map of config name to config value.
Definition CollectConfigs.h:35
auto getConfig(const std::string &arch, const std::string &flavor, const std::string &config) const
Get the config value for a given arch, flavor and config.
Definition CollectConfigs.h:84
CollectConfigs(const CollectConfigs &)=delete
Deleted copy constructor.
std::unordered_map< std::string, ConfigMap, SlHelpers::String::Hash, SlHelpers::String::Eq > FlavorMap
Map of flavor name to config map.
Definition CollectConfigs.h:38
const auto & getFlavorMap(const std::string &arch) const
Get the flavor map for a given arch.
Definition CollectConfigs.h:74
CollectConfigs(CollectConfigs &&)=default
Defaulted move constructor.
std::unordered_map< std::string, FlavorMap, SlHelpers::String::Hash, SlHelpers::String::Eq > ArchMap
Map of arch name to flavor map.
Definition CollectConfigs.h:41
CollectConfigs & operator=(CollectConfigs &&)=default
Defaulted move assignment operator.
CollectConfigs(const SlGit::Commit &commit)
CollectConfigs constructor.
CollectConfigs & operator=(const CollectConfigs &)=delete
Deleted copy assignment operator.
auto end() const
Get the archs end iterator.
Definition CollectConfigs.h:95
Equality test for string and string_view to be used in containers.
Definition String.h:250
Hash for string and string_view to be used in hashing containers.
Definition String.h:223