Ocean
Registry.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_WIN_REGISTRY_H
9 #define META_OCEAN_PLATFORM_WIN_REGISTRY_H
10 
11 #include "ocean/platform/win/Win.h"
12 
13 #include <vector>
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace Win
22 {
23 
24 /**
25  * This class provides windows registry functionalities.
26  * @ingroup platformwin
27  */
28 class OCEAN_PLATFORM_WIN_EXPORT Registry
29 {
30  public:
31 
32  /**
33  * Definition of different registry root types.
34  */
35  enum RootType
36  {
37  /// Classes root type.
39  /// Current user root type.
41  /// Local machine root type.
43  /// Users root type.
44  ROOT_USERS
45  };
46 
47  /**
48  * Definition of different registry value types.
49  */
50  enum ValueType
51  {
52  /// Invalid value type.
54  /// Data value type.
56  /// 32 bit integer value type.
58  /// 64 bit integer value type.
60  /// String value type.
62  /// Multi string value type.
63  VALUE_STRINGS
64  };
65 
66  /**
67  * Definition of a vector holding key or value names.
68  */
69  typedef std::vector<std::string> Names;
70 
71  public:
72 
73  /**
74  * Translates a root type.
75  * @param root Root type to translate
76  * @return Translated root type as key handle
77  */
78  static HKEY translateRoot(const RootType root);
79 
80  /**
81  * Opens a registry key and returns the received key handle.
82  * @param root Key root to open
83  * @param path Path and name of the key to open
84  * @return Received key handle
85  */
86  static HKEY openKey(const RootType root, const std::string& path);
87 
88  /**
89  * Opens a registry key and returns the received key handle.
90  * @param key Base registry key
91  * @param name The name of the new sub key
92  * @return Received key handle
93  */
94  static HKEY openKey(const HKEY key, const std::string& name);
95 
96  /**
97  * Closes a registry key.
98  * @param key Key to close
99  * @return True, if succeeded
100  */
101  static bool closeKey(const HKEY key);
102 
103  /**
104  * Creates a new key.
105  * @param root Key root
106  * @param path Path and name of the new key
107  * @return True, if succeeded
108  */
109  static bool createKey(const RootType root, const std::string& path);
110 
111  /**
112  * Returns the type of a value
113  * @param key Base registry key
114  * @param name Value name
115  * @return Value type
116  */
117  static ValueType valueType(const HKEY key, const std::string& name);
118 
119  /**
120  * Sets a value of a key.
121  * @param root Key root
122  * @param path Path and name of the key to set the value for
123  * @param name The name of the value to set
124  * @param value Value to set
125  * @return True, if succeeded
126  */
127  static bool setValue(const RootType root, const std::string& path, const std::string& name, const int value);
128 
129  /**
130  * Sets a value of a key.
131  * @param key Base registry key
132  * @param name The name of the value to set
133  * @param value Value to set
134  * @return True, if succeeded
135  */
136  static bool setValue(const HKEY key, const std::string& name, const int value);
137 
138  /**
139  * Sets a value of a key.
140  * @param root Key root
141  * @param path Path and name of the key to set the value for
142  * @param name The name of the value to set
143  * @param value Value to set
144  * @return True, if succeeded
145  */
146  static bool setValue(const RootType root, const std::string& path, const std::string& name, const long long value);
147 
148  /**
149  * Sets a value of a key.
150  * @param key Base registry key
151  * @param name The name of the value to set
152  * @param value Value to set
153  * @return True, if succeeded
154  */
155  static bool setValue(const HKEY key, const std::string& name, const long long value);
156 
157  /**
158  * Sets a value of a key.
159  * @param root Key root
160  * @param path Path and name of the key to set the value for
161  * @param name The name of the value to set
162  * @param value Value to set
163  * @return True, if succeeded
164  */
165  static bool setValue(const RootType root, const std::string& path, const std::string& name, const std::string& value);
166 
167  /**
168  * Sets a value of a key.
169  * @param key Base registry key
170  * @param name The name of the value to set
171  * @param value Value to set
172  * @return True, if succeeded
173  */
174  static bool setValue(const HKEY key, const std::string& name, const std::string& value);
175 
176  /**
177  * Sets a value of a key.
178  * @param root Key root
179  * @param path Path and name of the key to set the value for
180  * @param name The name of the value to set
181  * @param value Value to set
182  * @return True, if succeeded
183  */
184  static bool setValue(const RootType root, const std::string& path, const std::string& name, const Names& value);
185 
186  /**
187  * Sets a value of a key.
188  * @param key Base registry key
189  * @param name The name of the value to set
190  * @param value Value to set
191  * @return True, if succeeded
192  */
193  static bool setValue(const HKEY key, const std::string& name, const Names& value);
194 
195  /**
196  * Sets a value of a key.
197  * @param root Key root
198  * @param path Path and name of the key to set the value for
199  * @param name The name of the value to set
200  * @param value Value buffer to set
201  * @param size Size of the value to set in bytes
202  * @return True, if succeeded
203  */
204  static bool setValue(const RootType root, const std::string& path, const std::string& name, const unsigned char* value, const unsigned int size);
205 
206  /**
207  * Sets a value of a key.
208  * @param key Base registry key
209  * @param name The name of the value to set
210  * @param value Value buffer to set
211  * @param size Size of the value to set in bytes
212  * @return True, if succeeded
213  */
214  static bool setValue(const HKEY key, const std::string& name, const unsigned char* value, const unsigned int size);
215 
216  /**
217  * Returns a key value.
218  * @param root Key root
219  * @param path Path and name of the key to return the value from
220  * @param name The name of the value to return
221  * @param value Default value top return if the key does not hold the specified value
222  * @return Key value or specified default value
223  */
224  static int value(const RootType root, const std::string& path, const std::string& name, const int value);
225 
226  /**
227  * Returns a key value.
228  * @param key Base registry key
229  * @param name The name of the value to return
230  * @param value Default value top return if the key does not hold the specified value
231  * @return Key value or specified default value
232  */
233  static int value(const HKEY key, const std::string& name, const int value);
234 
235  /**
236  * Returns a key value.
237  * @param root Key root
238  * @param path Path and name of the key to return the value from
239  * @param name The name of the value to return
240  * @param value Default value top return if the key does not hold the specified value
241  * @return Key value or specified default value
242  */
243  static long long value(const RootType root, const std::string& path, const std::string& name, const long long value);
244 
245  /**
246  * Returns a key value.
247  * @param key Base registry key
248  * @param name The name of the value to return
249  * @param value Default value top return if the key does not hold the specified value
250  * @return Key value or specified default value
251  */
252  static long long value(const HKEY key, const std::string& name, const long long value);
253 
254  /**
255  * Returns a key value.
256  * @param root Key root
257  * @param path Path and name of the key to return the value from
258  * @param name The name of the value to return
259  * @param value Default value top return if the key does not hold the specified value
260  * @return Key value or specified default value
261  */
262  static std::string value(const RootType root, const std::string& path, const std::string& name, const std::string& value);
263 
264  /**
265  * Returns a key value.
266  * @param key Base registry key
267  * @param name The name of the value to return
268  * @param value Default value top return if the key does not hold the specified value
269  * @return Key value or specified default value
270  */
271  static std::string value(const HKEY key, const std::string& name, const std::string& value);
272 
273  /**
274  * Returns a key value.
275  * @param root Key root
276  * @param path Path and name of the key to return the value from
277  * @param name The name of the value to return
278  * @param value Default value top return if the key does not hold the specified value
279  * @return Key value or specified default value
280  */
281  static Names value(const RootType root, const std::string& path, const std::string& name, const Names& value);
282 
283  /**
284  * Returns a key value.
285  * @param key Base registry key
286  * @param name The name of the value to return
287  * @param value Default value top return if the key does not hold the specified value
288  * @return Key value or specified default value
289  */
290  static Names value(const HKEY key, const std::string& name, const Names& value);
291 
292  /**
293  * Returns all values specified for a key.
294  * @param root Key root
295  * @param path Path and name of the key to return the values from
296  * @return Value names
297  */
298  static Names values(const RootType root, const std::string& path);
299 
300  /**
301  * Returns all values specified for a key.
302  * @param key Key to return the values from
303  * @return Value names
304  */
305  static Names values(const HKEY key);
306 
307  /**
308  * Returns all sub keys specified for a key.
309  * @param root Key root
310  * @param path Path and name of the key to return the keys from
311  * @return Sub key names
312  */
313  static Names keys(const RootType root, const std::string& path);
314 
315  /**
316  * Returns all sub keys specified for a key.
317  * @param key Key to return the sub keys from
318  * @return Sub key names
319  */
320  static Names keys(const HKEY key);
321 };
322 
323 }
324 
325 }
326 
327 }
328 
329 #endif // META_OCEAN_PLATFORM_WIN_REGISTRY_H
This class provides windows registry functionalities.
Definition: Registry.h:29
static Names keys(const RootType root, const std::string &path)
Returns all sub keys specified for a key.
static Names keys(const HKEY key)
Returns all sub keys specified for a key.
static ValueType valueType(const HKEY key, const std::string &name)
Returns the type of a value.
static Names values(const RootType root, const std::string &path)
Returns all values specified for a key.
static bool setValue(const HKEY key, const std::string &name, const int value)
Sets a value of a key.
RootType
Definition of different registry root types.
Definition: Registry.h:36
@ ROOT_CLASSES_ROOT
Classes root type.
Definition: Registry.h:38
@ ROOT_LOCAL_MACHINE
Local machine root type.
Definition: Registry.h:42
@ ROOT_CURRENT_USER
Current user root type.
Definition: Registry.h:40
static std::string value(const HKEY key, const std::string &name, const std::string &value)
Returns a key value.
static HKEY openKey(const HKEY key, const std::string &name)
Opens a registry key and returns the received key handle.
static bool setValue(const RootType root, const std::string &path, const std::string &name, const long long value)
Sets a value of a key.
static bool setValue(const HKEY key, const std::string &name, const long long value)
Sets a value of a key.
static Names value(const RootType root, const std::string &path, const std::string &name, const Names &value)
Returns a key value.
static bool closeKey(const HKEY key)
Closes a registry key.
static Names value(const HKEY key, const std::string &name, const Names &value)
Returns a key value.
static bool setValue(const HKEY key, const std::string &name, const Names &value)
Sets a value of a key.
ValueType
Definition of different registry value types.
Definition: Registry.h:51
@ VALUE_STRING
String value type.
Definition: Registry.h:61
@ VALUE_INVALID
Invalid value type.
Definition: Registry.h:53
@ VALUE_INTEGER64
64 bit integer value type.
Definition: Registry.h:59
@ VALUE_DATA
Data value type.
Definition: Registry.h:55
@ VALUE_INTEGER32
32 bit integer value type.
Definition: Registry.h:57
static HKEY translateRoot(const RootType root)
Translates a root type.
static long long value(const RootType root, const std::string &path, const std::string &name, const long long value)
Returns a key value.
std::vector< std::string > Names
Definition of a vector holding key or value names.
Definition: Registry.h:69
static int value(const RootType root, const std::string &path, const std::string &name, const int value)
Returns a key value.
static bool setValue(const RootType root, const std::string &path, const std::string &name, const int value)
Sets a value of a key.
static bool createKey(const RootType root, const std::string &path)
Creates a new key.
static int value(const HKEY key, const std::string &name, const int value)
Returns a key value.
static bool setValue(const RootType root, const std::string &path, const std::string &name, const Names &value)
Sets a value of a key.
static bool setValue(const HKEY key, const std::string &name, const unsigned char *value, const unsigned int size)
Sets a value of a key.
static std::string value(const RootType root, const std::string &path, const std::string &name, const std::string &value)
Returns a key value.
static bool setValue(const RootType root, const std::string &path, const std::string &name, const std::string &value)
Sets a value of a key.
static long long value(const HKEY key, const std::string &name, const long long value)
Returns a key value.
static bool setValue(const HKEY key, const std::string &name, const std::string &value)
Sets a value of a key.
static HKEY openKey(const RootType root, const std::string &path)
Opens a registry key and returns the received key handle.
static Names values(const HKEY key)
Returns all values specified for a key.
static bool setValue(const RootType root, const std::string &path, const std::string &name, const unsigned char *value, const unsigned int size)
Sets a value of a key.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15