diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2022-04-15 15:47:22 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2022-04-29 14:51:17 (GMT) |
commit | 08941a9a40c7786aa2ee8ff8e7c684eaf016513e (patch) | |
tree | f274ba07968bdcf6b96899a22f30f5b608cfe256 /Source/cmWindowsRegistry.cxx | |
parent | 769f25aa3cd2bd294ab2a07d4530307798a0d7d9 (diff) | |
download | CMake-08941a9a40c7786aa2ee8ff8e7c684eaf016513e.zip CMake-08941a9a40c7786aa2ee8ff8e7c684eaf016513e.tar.gz CMake-08941a9a40c7786aa2ee8ff8e7c684eaf016513e.tar.bz2 |
cmWindowsRegistry: Add helper for conversion between string and enum View
Diffstat (limited to 'Source/cmWindowsRegistry.cxx')
-rw-r--r-- | Source/cmWindowsRegistry.cxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Source/cmWindowsRegistry.cxx b/Source/cmWindowsRegistry.cxx index b452ec6..9048334 100644 --- a/Source/cmWindowsRegistry.cxx +++ b/Source/cmWindowsRegistry.cxx @@ -3,6 +3,8 @@ #include "cmWindowsRegistry.h" +#include <unordered_map> + #if defined(_WIN32) && !defined(__CYGWIN__) # include <algorithm> # include <cstdint> @@ -335,6 +337,38 @@ cmWindowsRegistry::cmWindowsRegistry(cmMakefile& makefile) #endif } +cm::optional<cmWindowsRegistry::View> cmWindowsRegistry::ToView( + cm::string_view name) +{ + static std::unordered_map<cm::string_view, cmWindowsRegistry::View> + ViewDefinitions{ + { "BOTH"_s, View::Both }, { "HOST"_s, View::Host }, + { "TARGET"_s, View::Target }, { "32"_s, View::Reg32 }, + { "64"_s, View::Reg64 }, { "32_64"_s, View::Reg32_64 }, + { "64_32"_s, View::Reg64_32 } + }; + + auto it = ViewDefinitions.find(name); + + return it == ViewDefinitions.end() ? cm::nullopt + : cm::optional{ it->second }; +} + +cm::string_view cmWindowsRegistry::FromView(View view) +{ + static std::unordered_map<cmWindowsRegistry::View, cm::string_view> + ViewDefinitions{ + { View::Both, "BOTH"_s }, { View::Host, "HOST"_s }, + { View::Target, "TARGET"_s }, { View::Reg32, "32"_s }, + { View::Reg64, "64"_s }, { View::Reg32_64, "32_64"_s }, + { View::Reg64_32, "64_32"_s } + }; + + auto it = ViewDefinitions.find(view); + + return it == ViewDefinitions.end() ? ""_s : it->second; +} + cm::string_view cmWindowsRegistry::GetLastError() const { return this->LastError; |