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 
48 {
51 
52 public:
54  {
59  key_users
60  };
61 
63  {
66  create_volatile = 2
67  };
68 
69  // Construct a null instance
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 
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 
void delete_key(const std::string &subkey, bool recursive)
RegistryKey(HKEY key)
void throw_if_null() const
Throw an exception if this object is invalid.
std::vector< std::string > get_value_multi_string(const std::string &name, const std::vector< std::string > &default_value=std::vector< std::string >()) const
@ create_always
Definition: registry_key.h:64
@ key_users
Definition: registry_key.h:59
General purpose data buffer.
Definition: databuffer.h:43
RegistryKey(PredefinedKey key, const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS, unsigned int create_flags=create_always)
std::vector< std::string > get_subkey_names() const
void set_value_int(const std::string &name, int value)
void delete_value(const std::string &name)
@ key_current_user
Definition: registry_key.h:57
std::vector< std::string > get_value_names() const
CreateFlags
Definition: registry_key.h:63
Registry key class.
Definition: registry_key.h:48
RegistryKey open_key(const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS)
void set_value_string(const std::string &name, const std::string &value)
int get_value_int(const std::string &name, int default_value=0) const
bool is_null() const
Returns true if this object is invalid.
Definition: registry_key.h:85
RegistryKey create_key(const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS, CreateFlags create_flags=create_always)
std::string get_value_string(const std::string &name, const std::string &default_value=std::string()) const
@ key_classes_root
Definition: registry_key.h:55
static void delete_key(PredefinedKey key, const std::string &subkey, bool recursive)
@ key_local_machine
Definition: registry_key.h:58
PredefinedKey
Definition: registry_key.h:54
Definition: clanapp.h:36
DataBuffer get_value_binary(const std::string &name, const DataBuffer &default_value=DataBuffer()) const
@ key_current_config
Definition: registry_key.h:56
@ create_new
Definition: registry_key.h:65
void set_value_binary(const std::string &name, const DataBuffer &value)
HKEY get_key() const
@ create_volatile
Definition: registry_key.h:66