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