summaryrefslogtreecommitdiff
path: root/Source/kwsys/Registry.hxx.in
blob: ed9b0107267a82cce46518e66c1d3aea3c435d25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*============================================================================
  KWSys - Kitware System Library
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#ifndef @KWSYS_NAMESPACE@_Registry_hxx
#define @KWSYS_NAMESPACE@_Registry_hxx

#include <@KWSYS_NAMESPACE@/Configure.h>

#include <@KWSYS_NAMESPACE@/stl/string>

namespace @KWSYS_NAMESPACE@
{

class RegistryHelper;

/** \class Registry
 * \brief Portable registry class
 *
 * This class abstracts the storing of data that can be restored
 * when the program executes again. On Win32 platform it is
 * implemented using the registry and on unix as a file in
 * the user's home directory.
 */
class @KWSYS_NAMESPACE@_EXPORT Registry
{
public:
  enum RegistryType
    {
#ifdef _WIN32
    WIN32_REGISTRY,
#endif
    FILE_REGISTRY
    };

#ifdef _WIN32
  Registry(RegistryType registryType = WIN32_REGISTRY);
#else
  Registry(RegistryType registryType = FILE_REGISTRY);
#endif

  virtual ~Registry();

  //! Read a value from the registry.
  bool ReadValue(const char *subkey, const char *key, const char **value);

  //! Delete a key from the registry.
  bool DeleteKey(const char *subkey, const char *key);

  //! Delete a value from a given key.
  bool DeleteValue(const char *subkey, const char *key);

  //! Set value in a given key.
  bool SetValue(const char *subkey, const char *key,
               const char *value);

  //! Open the registry at toplevel/subkey.
  bool Open(const char *toplevel, const char *subkey,
           int readonly);

  //! Close the registry.
  bool Close();

  //! Read from local or global scope. On Windows this mean from local machine
  // or local user. On unix this will read from $HOME/.Projectrc or
  // /etc/Project
  void GlobalScopeOn() { this->SetGlobalScope(1); }
  void GlobalScopeOff() { this->SetGlobalScope(0); }
  void SetGlobalScope(bool b);
  bool GetGlobalScope();

  // Set or get the toplevel registry key.
  void SetTopLevel(const char* tl);
  const char* GetTopLevel();

  // Return true if registry opened
  bool GetOpened() { return m_Opened; }

  // Should the registry be locked?
  bool GetLocked() { return m_Locked; }

  enum {
    READONLY,
    READWRITE
  };

  // Return true if the character is space.
  int IsSpace(char c);

private:
  RegistryHelper* Helper;

  bool m_Opened;

  bool m_Locked;
}; // End Class: Registry

} // namespace @KWSYS_NAMESPACE@

#endif