1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registry.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _REGISTRY_HXX_
32 #define _REGISTRY_HXX_
35 #pragma warning(push, 1) /* disable warnings within system headers */
46 #include "registryvalueimpl.hxx"
48 //---------------------------------------
49 // forward declaration
50 //---------------------------------------
52 class RegistryKeyImpl
;
54 //---------------------------------------
56 //---------------------------------------
58 typedef std::auto_ptr
<RegistryKeyImpl
> RegistryKey
;
59 typedef std::vector
<std::wstring
> StringList
;
60 typedef std::auto_ptr
<StringList
> StringListPtr
;
62 //---------------------------------------
64 //---------------------------------------
70 //############################################
72 //############################################
74 virtual ~RegistryKeyImpl();
77 //############################################
79 //############################################
82 /** The name of the key at hand, maybe empty
83 if this is any of the root keys
85 std::wstring
GetName() const;
87 /** The number of sub values of the key at hand
89 @precond IsOpen = true
93 virtual size_t GetSubValueCount() const = 0;
95 /** The number of sub-keys of the key at hand
97 @precond IsOpen = true
101 virtual size_t GetSubKeyCount() const = 0;
105 /** Do we have write access on the key at hand
107 bool IsWriteable() const;
109 /** The StringList will be allocated on the heap,
110 so this is in fact a transfer of ownership
113 @precond IsOpen = true
115 @throws RegistryIOException
117 virtual StringListPtr
GetSubKeyNames() const = 0;
119 /** The StringList will be allocated on the heap,
120 so this is in fact a transfer of ownership
123 @precond IsOpen = true
125 @throws RegistryIOException
127 virtual StringListPtr
GetSubValueNames() const = 0;
129 /** Get the specified registry value
131 @precond IsOpen = true
133 virtual RegistryValue
GetValue(const std::wstring
& Name
) const = 0;
135 /** Get the specified registry value, return the given
136 default value if value not found
138 @precond IsOpen = true
140 virtual RegistryValue
GetValue(const std::wstring
& Name
, const RegistryValue
& Default
) const = 0;
142 /** Convenience function to determine if the
143 Registry key at hand has the specified
146 @precond IsOpen = true
148 throws RegistryAccessDenyException
150 bool HasValue(const std::wstring
& Name
) const;
152 /** Convenience function to determine if the
153 Registry key at hand has the specified
156 @precond IsOpen = true
158 throws RegistryAccessDenyException
160 bool HasSubKey(const std::wstring
& Name
) const;
163 //############################################
165 //############################################
168 /** Open the registry key, has no effect if
169 the key is already open
171 @precond IsOpen = false
173 @throws RegistryWriteAccessDenyException
174 RegistryAccessDenyException
176 virtual void Open(bool Writeable
= true) = 0;
178 /** Close the registry key at hand, further
179 using it without re-opening may cause
180 RegistryIOExceptions to be thrown
182 This is a template method that calls
183 ImplClose which has to be overwritten
188 /** Open the specified sub-key of the registry key
191 @precond IsOpen = true
192 HasSubKey(Name) = true
194 @throws RegistryIOException
195 RegistryKeyNotFoundException
196 RegistryAccessDeniedException
198 virtual RegistryKey
OpenSubKey(const std::wstring
& Name
, bool Writeable
= true) = 0;
200 /** Creates a new sub-key below the key at hand
202 @precond IsOpen = true
205 @throws RegistryIOException
206 RegistryWriteAccessDenyException
208 virtual RegistryKey
CreateSubKey(const std::wstring
& Name
) = 0;
210 /** Deletes a sub-key below the key at hand, the
211 key must not have sub-keys
213 @precond IsOpen = true
216 @throws RegistryIOException
217 RegistryWriteAccessDenyException
219 virtual void DeleteSubKey(const std::wstring
& Name
) = 0;
221 /** Deletes a sub-key below the key at hand with all
224 @precond IsOpen = true
227 @throws RegistryIOException
228 RegistryWriteAccessDenyException
230 virtual void DeleteSubKeyTree(const std::wstring
& Name
) = 0;
232 /** Delete the specified value
234 @precond IsOpen = true
236 HasValue(Name) = true
238 @throws RegistryIOException
239 RegistryWriteAccessDeniedException
240 RegistryValueNotFoundException
242 virtual void DeleteValue(const std::wstring
& Name
) = 0;
244 /** Set the specified registry value
246 @precond IsOpen = true
249 @throws RegistryIOException
250 RegistryWriteAccessDenyException
252 virtual void SetValue(const RegistryValue
& Value
) = 0;
255 /** Copies the specified value from RegistryKey to
256 the registry key at hand, if a value with this
257 name already exist under the registry key at hand
258 it will be overwritten
260 @precond IsOpen = true
262 RegistryKey.HasSubValue(Name) = true
264 @throws RegistryIOException
265 RegistryWriteAccessDeniedException
266 RegistryValueNotFoundException
268 virtual void CopyValue(const RegistryKey
& RegistryKey
, const std::wstring
& Name
);
270 /** Copies the specified value from RegistryKey to
271 the registry key at hand under a new name,
272 if a value with this name already exist there
273 it will be overwritten
275 @precond IsOpen = true
277 RegistryKey.HasSubValue(Name) = true
279 @throws RegistryIOException
280 RegistryWriteAccessDeniedException
281 RegistryValueNotFoundException
283 virtual void CopyValue(const RegistryKey
& RegistryKey
, const std::wstring
& Name
, const std::wstring
& NewName
);
285 //############################################
287 // only possible through WindowsRegistry class
288 //############################################
292 /** Create instance of the specified Registry key
294 @throws RegistryWriteAccessDenyException
295 RegistryAccessDenyException
296 RegistryKeyNotFoundException
298 RegistryKeyImpl(HKEY RootKey
, const std::wstring
& KeyName
);
300 /** Create instance of the specified Registry key.
301 RootKey should only one of the predefined
302 keys HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
303 HKEY_LOCAL_MACHINE, HKEY_USERS
305 @throws RegistryWriteAccessDenyException
306 RegistryAccessDenyException
307 RegistryKeyNotFoundException
309 RegistryKeyImpl(HKEY RootKey
);
311 /** Create an instances of the specified Registry key,
312 the key is assumed to be already opened.
314 RegistryKeyImpl(HKEY RootKey
, HKEY SubKey
, const std::wstring
& KeyName
, bool Writeable
= true);
316 /** Is this one of the root keys
321 bool IsRootKey() const;
326 std::wstring m_KeyName
;
329 // prevent copy and assignment
331 RegistryKeyImpl(const RegistryKeyImpl
&);
332 RegistryKeyImpl
& operator=(const RegistryKeyImpl
&);
334 //######################################
335 // Friend declarations
336 //######################################
338 friend class WindowsRegistry
;