registry_key.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 #ifdef WIN32
33 
34 #include "../api_core.h"
35 #include "databuffer.h"
36 #include <vector>
37 
38 namespace clan
39 {
42 
43 class RegistryKey_Impl;
44 
46 
48 class CL_API_CORE RegistryKey
49 {
52 
53 public:
54  enum PredefinedKey
55  {
56  key_classes_root,
57  key_current_config,
58  key_current_user,
59  key_local_machine,
60  key_users
61  };
62 
63  enum CreateFlags
64  {
65  create_always = 0,
66  create_new = 1,
67  create_volatile = 2
68  };
69 
70  // Construct a null instance
71  RegistryKey();
72 
73  RegistryKey(PredefinedKey key, const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS, unsigned int create_flags = create_always);
74 
75  RegistryKey(HKEY key);
76 
77  ~RegistryKey();
78 
79 
83 
84 public:
86  bool is_null() const { return !impl; }
87 
89  void throw_if_null() const;
90 
91  HKEY get_key() const;
92 
93  std::vector<std::string> get_subkey_names() const;
94 
95  std::vector<std::string> get_value_names() const;
96 
97  int get_value_int(const std::string &name, int default_value = 0) const;
98 
99  DataBuffer get_value_binary(const std::string &name, const DataBuffer &default_value = DataBuffer()) const;
100 
101  std::string get_value_string(const std::string &name, const std::string &default_value = std::string()) const;
102 
103  std::vector<std::string> get_value_multi_string(const std::string &name, const std::vector<std::string> &default_value = std::vector<std::string>()) const;
104 
105 
109 
110 public:
111  RegistryKey open_key(const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS);
112 
113  RegistryKey create_key(const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS, CreateFlags create_flags = create_always);
114 
115  void delete_key(const std::string &subkey, bool recursive);
116 
117  static void delete_key(PredefinedKey key, const std::string &subkey, bool recursive);
118 
119  void set_value_int(const std::string &name, int value);
120 
121  void set_value_binary(const std::string &name, const DataBuffer &value);
122 
123  void set_value_string(const std::string &name, const std::string &value);
124 
125 // void set_value_multi_string(const std::string &name, const std::vector<std::string> &value);
126 
127  void delete_value(const std::string &name);
128 
129 
133 
134 private:
135  std::shared_ptr<RegistryKey_Impl> impl;
137 };
138 
139 
140 }
141 
142 #endif
143