Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/shared/Registry.h

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Left Patch Set: reformatted Created July 26, 2014, 3:52 p.m.
Right Patch Set: Final (?) 2 Created Jan. 5, 2015, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 #ifndef REGISTRY_H
2 #define REGISTRY_H
3
1 #include <string> 4 #include <string>
2 #include <Windows.h> 5 #include <Windows.h>
3 6
4 namespace AdblockPlus 7 namespace AdblockPlus
5 { 8 {
6 /** 9 /**
7 * An open key in the system registry. 10 * An open key in the system registry.
11 *
12 * This class is not completely general.
13 * In particular, it cannot encapsulate the predefined registry keys
14 * such as HKEY_CLASSES_ROOT.
15 * These classes are considered "always open",
16 * and the destructor should not close them.
17 * Rather than trying to detect these predefined keys,
18 * we simply don't allow them to be constructed.
19 * In practice, this is a limitation without much consequence.
20 * If this were a library designed for standalone use,
21 * this limitation might not be appropriate, but it's fine here.
8 */ 22 */
9 class Registry_Key 23 class RegistryKey
10 { 24 {
11 /** 25 /**
12 * Handle to an open registry key. 26 * Handle to registry key that is open and not predefined.
13 */ 27 */
14 HKEY key; 28 HKEY key;
15 29
16 /**
17 * Flag whether the registry key is predefined or not.
18 *
19 * Predefined key values are considered "always open" and should not be clos ed in the destructor.
20 */
21 bool is_predefined;
22
23 public: 30 public:
24 /** 31 /**
25 * Enumeration for predefined root keys. 32 * Constructor to open a key as a subkey key of an existing parent.
33 * Opens the key with read-only access.
34 *
35 * The constructor throws if 'key_name' is not found,
36 * to preserve the invariant that the registry key is open.
37 * The constructor also throws if 'key_name' is empty,
38 * to preserve the invariant the the registry key is not predefinded.
39 *
40 * \param parent
41 * An open registry key. This may be one of the predefined keys.
42 * \param key_name
43 * Name of the subkey to be opened under the parent.
26 */ 44 */
27 enum class Predefined 45 RegistryKey(HKEY parent, const std::wstring& key_name);
28 : unsigned int
29 {
30 HKCR = 0, // HKEY_CLASSES_ROOT
31 HKCC, // HKEY_CURRENT_CONFIG
32 HKCU, // HKEY_CURRENT_USER
33 HKLM, // HKEY_LOCAL_MACHINE
34 HKU // HKEY_USERS
35 };
36 46
37 /** 47 /**
38 * Constructor to open a key under one of the predefined roots. 48 * Destructor always closes the key.
39 * Opens the key with read-only access.
40 *
41 * Because the invariant of this class is that the underlying registry key i s open,
42 * this constructor throws if 'key_name' is not found.
43 */ 49 */
44 Registry_Key(Predefined root, std::wstring key_name); 50 ~RegistryKey();
45
46 /**
47 * Constructor for one of the predefined roots.
48 */
49 Registry_Key(Predefined root);
50
51 /**
52 * Destructor closes the key if it's not a predefined one.
53 */
54 ~Registry_Key();
55 51
56 /** 52 /**
57 * Retrieve a value from a name-value pair within the present key. 53 * Retrieve a value from a name-value pair within the present key.
58 * 54 *
59 * Throws if the name is not found within the dictionary. 55 * Throws if the name is not found within the dictionary.
60 * Throws if the name is found but is not a string. 56 * Throws if the name is found but is not a string.
61 */ 57 */
62 std::wstring value_wstring(std::wstring name) const; 58 std::wstring value_wstring(const std::wstring& name) const;
63 }; 59 };
64 } 60 }
65 61
62 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld