1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _REGISTRY_HXX_
30 #define _REGISTRY_HXX_
33 #pragma warning(push, 1) /* disable warnings within system headers */
44 #include "registryvalueimpl.hxx"
46 //---------------------------------------
47 // forward declaration
48 //---------------------------------------
50 class RegistryKeyImpl
;
52 //---------------------------------------
54 //---------------------------------------
56 typedef std::auto_ptr
<RegistryKeyImpl
> RegistryKey
;
57 typedef std::vector
<std::wstring
> StringList
;
58 typedef std::auto_ptr
<StringList
> StringListPtr
;
64 //############################################
66 //############################################
68 virtual ~RegistryKeyImpl();
71 //############################################
73 //############################################
76 /** The name of the key at hand, maybe empty
77 if this is any of the root keys
79 std::wstring
GetName() const;
81 /** The number of sub values of the key at hand
83 @precond IsOpen = true
87 virtual size_t GetSubValueCount() const = 0;
89 /** The number of sub-keys of the key at hand
91 @precond IsOpen = true
95 virtual size_t GetSubKeyCount() const = 0;
99 /** Do we have write access on the key at hand
101 bool IsWriteable() const;
103 /** The StringList will be allocated on the heap,
104 so this is in fact a transfer of ownership
107 @precond IsOpen = true
109 @throws RegistryIOException
111 virtual StringListPtr
GetSubKeyNames() const = 0;
113 /** The StringList will be allocated on the heap,
114 so this is in fact a transfer of ownership
117 @precond IsOpen = true
119 @throws RegistryIOException
121 virtual StringListPtr
GetSubValueNames() const = 0;
123 /** Get the specified registry value
125 @precond IsOpen = true
127 virtual RegistryValue
GetValue(const std::wstring
& Name
) const = 0;
129 /** Get the specified registry value, return the given
130 default value if value not found
132 @precond IsOpen = true
134 virtual RegistryValue
GetValue(const std::wstring
& Name
, const RegistryValue
& Default
) const = 0;
136 /** Convenience function to determine if the
137 Registry key at hand has the specified
140 @precond IsOpen = true
142 throws RegistryAccessDenyException
144 bool HasValue(const std::wstring
& Name
) const;
146 /** Convenience function to determine if the
147 Registry key at hand has the specified
150 @precond IsOpen = true
152 throws RegistryAccessDenyException
154 bool HasSubKey(const std::wstring
& Name
) const;
157 //############################################
159 //############################################
162 /** Open the registry key, has no effect if
163 the key is already open
165 @precond IsOpen = false
167 @throws RegistryWriteAccessDenyException
168 RegistryAccessDenyException
170 virtual void Open(bool Writeable
= true) = 0;
172 /** Close the registry key at hand, further
173 using it without re-opening may cause
174 RegistryIOExceptions to be thrown
176 This is a template method that calls
177 ImplClose which has to be overwritten
182 /** Open the specified sub-key of the registry key
185 @precond IsOpen = true
186 HasSubKey(Name) = true
188 @throws RegistryIOException
189 RegistryKeyNotFoundException
190 RegistryAccessDeniedException
192 virtual RegistryKey
OpenSubKey(const std::wstring
& Name
, bool Writeable
= true) = 0;
194 /** Creates a new sub-key below the key at hand
196 @precond IsOpen = true
199 @throws RegistryIOException
200 RegistryWriteAccessDenyException
202 virtual RegistryKey
CreateSubKey(const std::wstring
& Name
) = 0;
204 /** Deletes a sub-key below the key at hand, the
205 key must not have sub-keys
207 @precond IsOpen = true
210 @throws RegistryIOException
211 RegistryWriteAccessDenyException
213 virtual void DeleteSubKey(const std::wstring
& Name
) = 0;
215 /** Deletes a sub-key below the key at hand with all
218 @precond IsOpen = true
221 @throws RegistryIOException
222 RegistryWriteAccessDenyException
224 virtual void DeleteSubKeyTree(const std::wstring
& Name
) = 0;
226 /** Delete the specified value
228 @precond IsOpen = true
230 HasValue(Name) = true
232 @throws RegistryIOException
233 RegistryWriteAccessDeniedException
234 RegistryValueNotFoundException
236 virtual void DeleteValue(const std::wstring
& Name
) = 0;
238 /** Set the specified registry value
240 @precond IsOpen = true
243 @throws RegistryIOException
244 RegistryWriteAccessDenyException
246 virtual void SetValue(const RegistryValue
& Value
) = 0;
249 /** Copies the specified value from RegistryKey to
250 the registry key at hand, if a value with this
251 name already exist under the registry key at hand
252 it will be overwritten
254 @precond IsOpen = true
256 RegistryKey.HasSubValue(Name) = true
258 @throws RegistryIOException
259 RegistryWriteAccessDeniedException
260 RegistryValueNotFoundException
262 virtual void CopyValue(const RegistryKey
& RegistryKey
, const std::wstring
& Name
);
264 /** Copies the specified value from RegistryKey to
265 the registry key at hand under a new name,
266 if a value with this name already exist there
267 it will be overwritten
269 @precond IsOpen = true
271 RegistryKey.HasSubValue(Name) = true
273 @throws RegistryIOException
274 RegistryWriteAccessDeniedException
275 RegistryValueNotFoundException
277 virtual void CopyValue(const RegistryKey
& RegistryKey
, const std::wstring
& Name
, const std::wstring
& NewName
);
279 //############################################
281 // only possible through WindowsRegistry class
282 //############################################
286 /** Create instance of the specified Registry key
288 @throws RegistryWriteAccessDenyException
289 RegistryAccessDenyException
290 RegistryKeyNotFoundException
292 RegistryKeyImpl(HKEY RootKey
, const std::wstring
& KeyName
);
294 /** Create instance of the specified Registry key.
295 RootKey should only one of the predefined
296 keys HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
297 HKEY_LOCAL_MACHINE, HKEY_USERS
299 @throws RegistryWriteAccessDenyException
300 RegistryAccessDenyException
301 RegistryKeyNotFoundException
303 RegistryKeyImpl(HKEY RootKey
);
305 /** Create an instances of the specified Registry key,
306 the key is assumed to be already opened.
308 RegistryKeyImpl(HKEY RootKey
, HKEY SubKey
, const std::wstring
& KeyName
, bool Writeable
= true);
310 /** Is this one of the root keys
315 bool IsRootKey() const;
320 std::wstring m_KeyName
;
323 // prevent copy and assignment
325 RegistryKeyImpl(const RegistryKeyImpl
&);
326 RegistryKeyImpl
& operator=(const RegistryKeyImpl
&);
328 //######################################
329 // Friend declarations
330 //######################################
332 friend class WindowsRegistry
;
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */