registry_key.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
30
31#if defined(WIN32) || defined(DOXYGEN)
32
33#include "databuffer.h"
34#include <vector>
35
36namespace clan
37{
40
41 class RegistryKey_Impl;
42
44
47 {
48 public:
57
64
66 RegistryKey(PredefinedKey key, const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS, unsigned int create_flags = create_always);
67 RegistryKey(HKEY key);
69
71 bool is_null() const { return !impl; }
72
74 void throw_if_null() const;
75
76 HKEY get_key() const;
77 std::vector<std::string> get_subkey_names() const;
78 std::vector<std::string> get_value_names() const;
79 int get_value_int(const std::string &name, int default_value = 0) const;
80 DataBuffer get_value_binary(const std::string &name, const DataBuffer &default_value = DataBuffer()) const;
81 std::string get_value_string(const std::string &name, const std::string &default_value = std::string()) const;
82 std::vector<std::string> get_value_multi_string(const std::string &name, const std::vector<std::string> &default_value = std::vector<std::string>()) const;
83
84 RegistryKey open_key(const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS);
85 RegistryKey create_key(const std::string &subkey, unsigned int access_rights = KEY_ALL_ACCESS, CreateFlags create_flags = create_always);
86 void delete_key(const std::string &subkey, bool recursive);
87 static void delete_key(PredefinedKey key, const std::string &subkey, bool recursive);
88 void set_value_int(const std::string &name, int value);
89 void set_value_binary(const std::string &name, const DataBuffer &value);
90 void set_value_string(const std::string &name, const std::string &value);
91 // void set_value_multi_string(const std::string &name, const std::vector<std::string> &value);
92 void delete_value(const std::string &name);
93
94 private:
95 std::shared_ptr<RegistryKey_Impl> impl;
96 };
97
99}
100
101#endif
General purpose data buffer.
Definition databuffer.h:42
Registry key class.
Definition registry_key.h:47
CreateFlags
Definition registry_key.h:59
@ create_volatile
Definition registry_key.h:62
@ create_always
Definition registry_key.h:60
@ create_new
Definition registry_key.h:61
void set_value_string(const std::string &name, const std::string &value)
RegistryKey(PredefinedKey key, const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS, unsigned int create_flags=create_always)
DataBuffer get_value_binary(const std::string &name, const DataBuffer &default_value=DataBuffer()) const
int get_value_int(const std::string &name, int default_value=0) const
HKEY get_key() const
std::string get_value_string(const std::string &name, const std::string &default_value=std::string()) const
RegistryKey open_key(const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS)
PredefinedKey
Definition registry_key.h:50
@ key_current_config
Definition registry_key.h:52
@ key_local_machine
Definition registry_key.h:54
@ key_users
Definition registry_key.h:55
@ key_classes_root
Definition registry_key.h:51
@ key_current_user
Definition registry_key.h:53
void set_value_int(const std::string &name, int value)
RegistryKey create_key(const std::string &subkey, unsigned int access_rights=KEY_ALL_ACCESS, CreateFlags create_flags=create_always)
bool is_null() const
Returns true if this object is invalid.
Definition registry_key.h:71
RegistryKey(HKEY key)
std::vector< std::string > get_value_multi_string(const std::string &name, const std::vector< std::string > &default_value=std::vector< std::string >()) const
void set_value_binary(const std::string &name, const DataBuffer &value)
void throw_if_null() const
Throw an exception if this object is invalid.
void delete_value(const std::string &name)
std::vector< std::string > get_value_names() const
std::vector< std::string > get_subkey_names() const
static void delete_key(PredefinedKey key, const std::string &subkey, bool recursive)
void delete_key(const std::string &subkey, bool recursive)
Definition clanapp.h:36