cmWindowsRegistry.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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
  4. #include <string>
  5. #include <vector>
  6. #include <cm/optional>
  7. #include <cm/string_view>
  8. #include <cmext/enum_set>
  9. #include <cmext/string_view>
  10. class cmMakefile;
  11. class cmWindowsRegistry
  12. {
  13. public:
  14. enum class View
  15. {
  16. Both,
  17. Target,
  18. Host,
  19. Reg64_32,
  20. Reg32_64,
  21. Reg32,
  22. Reg64
  23. };
  24. // Registry supported types
  25. enum class ValueType : std::uint8_t
  26. {
  27. Reg_SZ,
  28. Reg_EXPAND_SZ,
  29. Reg_MULTI_SZ,
  30. Reg_DWORD,
  31. Reg_QWORD
  32. };
  33. using ValueTypeSet = cm::enum_set<ValueType>;
  34. // All types as defined by enum ValueType
  35. static const ValueTypeSet AllTypes;
  36. // same as AllTYpes but without type REG_MULTI_SZ
  37. static const ValueTypeSet SimpleTypes;
  38. cmWindowsRegistry(cmMakefile&,
  39. const ValueTypeSet& supportedTypes = AllTypes);
  40. // Helper routine to convert string to enum value
  41. static cm::optional<View> ToView(cm::string_view name);
  42. // Helper routine to convert enum to string
  43. static cm::string_view FromView(View view);
  44. cm::optional<std::string> ReadValue(cm::string_view key,
  45. View view = View::Both,
  46. cm::string_view separator = "\0"_s)
  47. {
  48. return this->ReadValue(key, ""_s, view, separator);
  49. }
  50. cm::optional<std::string> ReadValue(cm::string_view key,
  51. cm::string_view name,
  52. View view = View::Both,
  53. cm::string_view separator = "\0"_s);
  54. cm::optional<std::vector<std::string>> GetValueNames(cm::string_view key,
  55. View view = View::Both);
  56. cm::optional<std::vector<std::string>> GetSubKeys(cm::string_view key,
  57. View view = View::Both);
  58. // Expand an expression which may contains multiple references
  59. // to registry keys.
  60. // Depending of the view specified, one or two expansions can be done.
  61. cm::optional<std::vector<std::string>> ExpandExpression(
  62. cm::string_view expression, View view, cm::string_view separator = "\0"_s);
  63. cm::string_view GetLastError() const;
  64. private:
  65. #if defined(_WIN32) && !defined(__CYGWIN__)
  66. std::vector<View> ComputeViews(View view);
  67. int TargetSize = 0;
  68. ValueTypeSet SupportedTypes = AllTypes;
  69. #endif
  70. std::string LastError;
  71. };