SlHelpers
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 
11 namespace SlGit {
12 class Commit;
13 class Repo;
14 class TreeEntry;
15 }
16 
17 namespace SlKernCVS {
18 
20 enum class ConfigValue : char {
21  Disabled = 'n',
22  BuiltIn = 'y',
23  Module = 'm',
24  WithValue = 'v',
25 };
26 
32 public:
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 
48  CollectConfigs(const SlGit::Commit &commit);
49 
51  CollectConfigs(const CollectConfigs &) = delete;
53  CollectConfigs &operator=(const CollectConfigs &) = delete;
54 
56  CollectConfigs(CollectConfigs &&) = default;
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 
99 private:
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 }
Definition: Blob.h:11
Equality test for string and string_view to be used in containers.
Definition: String.h:250
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 SlGit::Commit &commit)
CollectConfigs constructor.
Hash for string and string_view to be used in hashing containers.
Definition: String.h:223
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
Class to walk the KernCVS repository and report arch, flavor and configs via callbacks passed to the ...
Definition: CollectConfigs.h:31
auto begin() const
Get the archs iterator.
Definition: CollectConfigs.h:90
std::unordered_map< std::string, ConfigMap, SlHelpers::String::Hash, SlHelpers::String::Eq > FlavorMap
Map of flavor name to config map.
Definition: CollectConfigs.h:39
The most important Git class.
Definition: Repo.h:45
Commit is a representation of a git commit.
Definition: Commit.h:21
const auto & getArchMap() const
Get the arch map.
Definition: CollectConfigs.h:69
static CollectConfigs create(const std::filesystem::path &repoPath, const std::string &rev)
Create a CollectConfigs from the repoPath and rev.
std::unordered_map< std::string, FlavorMap, SlHelpers::String::Hash, SlHelpers::String::Eq > ArchMap
Map of arch name to flavor map.
Definition: CollectConfigs.h:42
auto end() const
Get the archs end iterator.
Definition: CollectConfigs.h:95
std::unordered_map< std::string, ConfigValue, SlHelpers::String::Hash, SlHelpers::String::Eq > ConfigMap
Map of config name to config value.
Definition: CollectConfigs.h:36
CollectConfigs & operator=(const CollectConfigs &)=delete
Deleted copy assignment operator.
Definition: Branches.h:15
const auto & getFlavorMap(const std::string &arch) const
Get the flavor map for a given arch.
Definition: CollectConfigs.h:74
The TreeEntry represents one git tree entry.
Definition: Tree.h:107