registry_key.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 
00033 #pragma once
00034 
00035 #ifdef WIN32
00036 
00037 #include "../api_core.h"
00038 #include "databuffer.h"
00039 #include <vector>
00040 
00041 class CL_RegistryKey_Impl;
00042 
00044 
00046 class CL_API_CORE CL_RegistryKey
00047 {
00050 
00051 public:
00052         enum PredefinedKey
00053         {
00054                 key_classes_root,
00055                 key_current_config,
00056                 key_current_user,
00057                 key_local_machine,
00058                 key_users
00059         };
00060 
00061         enum CreateFlags
00062         {
00063                 create_always    = 0,
00064                 create_new       = 1,
00065                 create_volatile  = 2
00066         };
00067 
00068         // Construct a null instance
00069         CL_RegistryKey();
00070 
00071         CL_RegistryKey(PredefinedKey key, const CL_StringRef &subkey, unsigned int access_rights = KEY_ALL_ACCESS, unsigned int create_flags = create_always);
00072 
00073         CL_RegistryKey(HKEY key);
00074 
00075         ~CL_RegistryKey();
00076 
00077 
00081 
00082 public:
00084         bool is_null() const { return !impl; }
00085 
00087         void throw_if_null() const;
00088 
00089         HKEY get_key() const;
00090 
00091         std::vector<CL_String> get_subkey_names() const;
00092 
00093         std::vector<CL_String> get_value_names() const;
00094 
00095         int get_value_int(const CL_StringRef &name, int default_value = 0) const;
00096 
00097         CL_DataBuffer get_value_binary(const CL_StringRef &name, const CL_DataBuffer &default_value = CL_DataBuffer()) const;
00098 
00099         CL_String get_value_string(const CL_StringRef &name, const CL_StringRef &default_value = CL_StringRef()) const;
00100 
00101         std::vector<CL_String> get_value_multi_string(const CL_StringRef &name, const std::vector<CL_String> &default_value = std::vector<CL_String>()) const;
00102 
00103 
00107 
00108 public:
00109         CL_RegistryKey open_key(const CL_StringRef &subkey, unsigned int access_rights = KEY_ALL_ACCESS);
00110 
00111         CL_RegistryKey create_key(const CL_StringRef &subkey, unsigned int access_rights = KEY_ALL_ACCESS, CreateFlags create_flags = create_always);
00112 
00113         void delete_key(const CL_StringRef &subkey, bool recursive);
00114 
00115         static void delete_key(PredefinedKey key, const CL_StringRef &subkey, bool recursive);
00116 
00117         void set_value_int(const CL_StringRef &name, int value);
00118 
00119         void set_value_binary(const CL_StringRef &name, const CL_DataBuffer &value);
00120 
00121         void set_value_string(const CL_StringRef &name, const CL_StringRef &value);
00122 
00123 //      void set_value_multi_string(const CL_StringRef &name, const std::vector<CL_String> &value);
00124 
00125         void delete_value(const CL_StringRef &name);
00126 
00127 
00131 
00132 private:
00133         CL_SharedPtr<CL_RegistryKey_Impl> impl;
00135 };
00136 
00137 #endif
00138