registry_key.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29
30 #pragma once
31
32 #if defined(WIN32) || defined(DOXYGEN)
33
34 #include "databuffer.h"
35 #include <vector>
36
37 namespace clan
38 {
41
42 class RegistryKey_Impl;
43
45
47 class RegistryKey
48 {
51
52 public:
53 enum PredefinedKey
54 {
55 key_classes_root,
56 key_current_config,
57 key_current_user,
58 key_local_machine,
59 key_users
60 };
61
62 enum CreateFlags
63 {
64 create_always = 0,
65 create_new = 1,
66 create_volatile = 2
67 };
68
69 // Construct a null instance
70 RegistryKey();
71
72 RegistryKey(PredefinedKey key, const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS, unsigned int create_flags = create_always);
73
74 RegistryKey(HKEY key);
75
76 ~RegistryKey();
77
78
82
83 public:
85 bool is_null() const { return !impl; }
86
88 void throw_if_null() const;
89
90 HKEY get_key() const;
91
92 std::vector<std::string> get_subkey_names() const;
93
94 std::vector<std::string> get_value_names() const;
95
96 int get_value_int(const std::string &name, int default_value = 0) const;
97
98 DataBuffer get_value_binary(const std::string &name, const DataBuffer &default_value = DataBuffer()) const;
99
100 std::string get_value_string(const std::string &name, const std::string &default_value = std::string()) const;
101
102 std::vector<std::string> get_value_multi_string(const std::string &name, const std::vector<std::string> &default_value = std::vector<std::string>()) const;
103
104
108
109 public:
110 RegistryKey open_key(const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS);
111
112 RegistryKey create_key(const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS, CreateFlags create_flags = create_always);
113
114 void delete_key(const std::string &subkey, bool recursive);
115
116 static void delete_key(PredefinedKey key, const std::string &subkey, bool recursive);
117
118 void set_value_int(const std::string &name, int value);
119
120 void set_value_binary(const std::string &name, const DataBuffer &value);
121
122 void set_value_string(const std::string &name, const std::string &value);
123
124 // void set_value_multi_string(const std::string &name, const std::vector<std::string> &value);
125
126 void delete_value(const std::string &name);
127
128
132
133 private:
134 std::shared_ptr<RegistryKey_Impl> impl;
136 };
137
138
139 }
140
141 #endif
142
clan
Definition: clanapp.h:35
clan::RegistryKey::set_value_binary
void set_value_binary(const std::string &name, const DataBuffer &value)
clan::RegistryKey::delete_key
void delete_key(const std::string &subkey, bool recursive)
clan::RegistryKey::get_value_names
std::vector< std::string > get_value_names() const
clan::RegistryKey::key_users
Definition: registry_key.h:59
clan::RegistryKey::delete_value
void delete_value(const std::string &name)
clan::RegistryKey::create_always
Definition: registry_key.h:64
clan::RegistryKey::get_key
HKEY get_key() const
clan::RegistryKey::get_value_string
std::string get_value_string(const std::string &name, const std::string &default_value=std::string()) const
clan::RegistryKey::key_current_user
Definition: registry_key.h:57
clan::RegistryKey::PredefinedKey
PredefinedKey
Definition: registry_key.h:53
clan::RegistryKey::get_value_multi_string
std::vector< std::string > get_value_multi_string(const std::string &name, const std::vector< std::string > &default_value=std::vector< std::string >()) const
clan::RegistryKey
Registry key class.
Definition: registry_key.h:47
clan::StyleTokenType::string
@ keyword
clan::RegistryKey::CreateFlags
CreateFlags
Definition: registry_key.h:62
clan::RegistryKey::get_value_int
int get_value_int(const std::string &name, int default_value=0) const
clan::RegistryKey::get_subkey_names
std::vector< std::string > get_subkey_names() const
clan::RegistryKey::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: registry_key.h:85
clan::RegistryKey::set_value_string
void set_value_string(const std::string &name, const std::string &value)
clan::RegistryKey::set_value_int
void set_value_int(const std::string &name, int value)
clan::RegistryKey::open_key
RegistryKey open_key(const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS)
clan::RegistryKey::key_local_machine
Definition: registry_key.h:58
clan::RegistryKey::get_value_binary
DataBuffer get_value_binary(const std::string &name, const DataBuffer &default_value=DataBuffer()) const
clan::RegistryKey::key_classes_root
Definition: registry_key.h:55
clan::RegistryKey::create_key
RegistryKey create_key(const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS, CreateFlags create_flags=create_always)
clan::RegistryKey::create_new
Definition: registry_key.h:65
clan::RegistryKey::key_current_config
Definition: registry_key.h:56
clan::RegistryKey::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::DataBuffer
General purpose data buffer.
Definition: databuffer.h:42
clan::RegistryKey::create_volatile
Definition: registry_key.h:66
clan::RegistryKey::~RegistryKey
~RegistryKey()
clan::RegistryKey::RegistryKey
RegistryKey()