ClanLib  2.3.7
registry_key.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 
31 
32 
33 #pragma once
34 
35 #ifdef WIN32
36 
37 #include "../api_core.h"
38 #include "databuffer.h"
39 #include <vector>
40 
41 class CL_RegistryKey_Impl;
42 
44 
46 class CL_API_CORE CL_RegistryKey
47 {
50 
51 public:
52  enum PredefinedKey
53  {
54  key_classes_root,
55  key_current_config,
56  key_current_user,
57  key_local_machine,
58  key_users
59  };
60 
61  enum CreateFlags
62  {
63  create_always = 0,
64  create_new = 1,
65  create_volatile = 2
66  };
67 
68  // Construct a null instance
69  CL_RegistryKey();
70 
71  CL_RegistryKey(PredefinedKey key, const CL_StringRef &subkey, unsigned int access_rights = KEY_ALL_ACCESS, unsigned int create_flags = create_always);
72 
73  CL_RegistryKey(HKEY key);
74 
75  ~CL_RegistryKey();
76 
77 
81 
82 public:
84  bool is_null() const { return !impl; }
85 
87  void throw_if_null() const;
88 
89  HKEY get_key() const;
90 
91  std::vector<CL_String> get_subkey_names() const;
92 
93  std::vector<CL_String> get_value_names() const;
94 
95  int get_value_int(const CL_StringRef &name, int default_value = 0) const;
96 
97  CL_DataBuffer get_value_binary(const CL_StringRef &name, const CL_DataBuffer &default_value = CL_DataBuffer()) const;
98 
99  CL_String get_value_string(const CL_StringRef &name, const CL_StringRef &default_value = CL_StringRef()) const;
100 
101  std::vector<CL_String> get_value_multi_string(const CL_StringRef &name, const std::vector<CL_String> &default_value = std::vector<CL_String>()) const;
102 
103 
107 
108 public:
109  CL_RegistryKey open_key(const CL_StringRef &subkey, unsigned int access_rights = KEY_ALL_ACCESS);
110 
111  CL_RegistryKey create_key(const CL_StringRef &subkey, unsigned int access_rights = KEY_ALL_ACCESS, CreateFlags create_flags = create_always);
112 
113  void delete_key(const CL_StringRef &subkey, bool recursive);
114 
115  static void delete_key(PredefinedKey key, const CL_StringRef &subkey, bool recursive);
116 
117  void set_value_int(const CL_StringRef &name, int value);
118 
119  void set_value_binary(const CL_StringRef &name, const CL_DataBuffer &value);
120 
121  void set_value_string(const CL_StringRef &name, const CL_StringRef &value);
122 
123 // void set_value_multi_string(const CL_StringRef &name, const std::vector<CL_String> &value);
124 
125  void delete_value(const CL_StringRef &name);
126 
127 
131 
132 private:
133  CL_SharedPtr<CL_RegistryKey_Impl> impl;
135 };
136 
137 #endif
138