Registry.hxx.in 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef @KWSYS_NAMESPACE@_Registry_hxx
  11. #define @KWSYS_NAMESPACE@_Registry_hxx
  12. #include <@KWSYS_NAMESPACE@/Configure.h>
  13. #include <@KWSYS_NAMESPACE@/stl/string>
  14. namespace @KWSYS_NAMESPACE@
  15. {
  16. class RegistryHelper;
  17. /** \class Registry
  18. * \brief Portable registry class
  19. *
  20. * This class abstracts the storing of data that can be restored
  21. * when the program executes again. On Win32 platform it is
  22. * implemented using the registry and on unix as a file in
  23. * the user's home directory.
  24. */
  25. class @KWSYS_NAMESPACE@_EXPORT Registry
  26. {
  27. public:
  28. enum RegistryType
  29. {
  30. #ifdef _WIN32
  31. WIN32_REGISTRY,
  32. #endif
  33. FILE_REGISTRY
  34. };
  35. #ifdef _WIN32
  36. Registry(RegistryType registryType = WIN32_REGISTRY);
  37. #else
  38. Registry(RegistryType registryType = FILE_REGISTRY);
  39. #endif
  40. virtual ~Registry();
  41. //! Read a value from the registry.
  42. bool ReadValue(const char *subkey, const char *key, const char **value);
  43. //! Delete a key from the registry.
  44. bool DeleteKey(const char *subkey, const char *key);
  45. //! Delete a value from a given key.
  46. bool DeleteValue(const char *subkey, const char *key);
  47. //! Set value in a given key.
  48. bool SetValue(const char *subkey, const char *key,
  49. const char *value);
  50. //! Open the registry at toplevel/subkey.
  51. bool Open(const char *toplevel, const char *subkey,
  52. int readonly);
  53. //! Close the registry.
  54. bool Close();
  55. //! Read from local or global scope. On Windows this mean from local machine
  56. // or local user. On unix this will read from $HOME/.Projectrc or
  57. // /etc/Project
  58. void GlobalScopeOn() { this->SetGlobalScope(1); }
  59. void GlobalScopeOff() { this->SetGlobalScope(0); }
  60. void SetGlobalScope(bool b);
  61. bool GetGlobalScope();
  62. // Set or get the toplevel registry key.
  63. void SetTopLevel(const char* tl);
  64. const char* GetTopLevel();
  65. // Return true if registry opened
  66. bool GetOpened() { return m_Opened; }
  67. // Should the registry be locked?
  68. bool GetLocked() { return m_Locked; }
  69. enum {
  70. READONLY,
  71. READWRITE
  72. };
  73. // Return true if the character is space.
  74. int IsSpace(char c);
  75. private:
  76. RegistryHelper* Helper;
  77. bool m_Opened;
  78. bool m_Locked;
  79. }; // End Class: Registry
  80. } // namespace @KWSYS_NAMESPACE@
  81. #endif