CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmWindowsRegistry.h
blob42179eda8b75bb5251cd34c16c0491360fb073ff
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <cstdint> // IWYU pragma: keep
8 #include <initializer_list>
9 #include <string>
10 #include <vector>
12 #include <cm/optional>
13 #include <cm/string_view>
14 #include <cmext/enum_set>
15 #include <cmext/string_view>
17 class cmMakefile;
19 class cmWindowsRegistry
21 public:
22 enum class View
24 Both,
25 Target,
26 Host,
27 Reg64_32,
28 Reg32_64,
29 Reg32,
30 Reg64
33 // Registry supported types
34 enum class ValueType : std::uint8_t
36 Reg_SZ,
37 Reg_EXPAND_SZ,
38 Reg_MULTI_SZ,
39 Reg_DWORD,
40 Reg_QWORD
42 using ValueTypeSet = cm::enum_set<ValueType>;
44 // All types as defined by enum ValueType
45 static const ValueTypeSet AllTypes;
46 // same as AllTYpes but without type REG_MULTI_SZ
47 static const ValueTypeSet SimpleTypes;
49 cmWindowsRegistry(cmMakefile&,
50 const ValueTypeSet& supportedTypes = AllTypes);
52 // Helper routine to convert string to enum value
53 static cm::optional<View> ToView(cm::string_view name);
54 // Helper routine to convert enum to string
55 static cm::string_view FromView(View view);
57 cm::optional<std::string> ReadValue(cm::string_view key,
58 View view = View::Both,
59 cm::string_view separator = "\0"_s)
61 return this->ReadValue(key, ""_s, view, separator);
63 cm::optional<std::string> ReadValue(cm::string_view key,
64 cm::string_view name,
65 View view = View::Both,
66 cm::string_view separator = "\0"_s);
68 cm::optional<std::vector<std::string>> GetValueNames(cm::string_view key,
69 View view = View::Both);
70 cm::optional<std::vector<std::string>> GetSubKeys(cm::string_view key,
71 View view = View::Both);
73 // Expand an expression which may contains multiple references
74 // to registry keys.
75 // Depending of the view specified, one or two expansions can be done.
76 cm::optional<std::vector<std::string>> ExpandExpression(
77 cm::string_view expression, View view, cm::string_view separator = "\0"_s);
79 cm::string_view GetLastError() const;
81 private:
82 #if defined(_WIN32) && !defined(__CYGWIN__)
83 std::vector<View> ComputeViews(View view);
85 int TargetSize = 0;
86 ValueTypeSet SupportedTypes = AllTypes;
87 #endif
88 std::string LastError;