Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / reg4msdoc / registry.hxx
blob48260b9b8ae179122030a44db768301701e98f8e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registry.hxx,v $
10 * $Revision: 1.5 $
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_
34 #ifdef _MSC_VER
35 #pragma warning(push, 1) /* disable warnings within system headers */
36 #endif
37 #include <windows.h>
38 #ifdef _MSC_VER
39 #pragma warning(pop)
40 #endif
42 #include <memory>
43 #include <vector>
44 #include <string>
46 #include "registryvalueimpl.hxx"
48 //---------------------------------------
49 // forward declaration
50 //---------------------------------------
52 class RegistryKeyImpl;
54 //---------------------------------------
55 // typedefs
56 //---------------------------------------
58 typedef std::auto_ptr<RegistryKeyImpl> RegistryKey;
59 typedef std::vector<std::wstring> StringList;
60 typedef std::auto_ptr<StringList> StringListPtr;
62 //---------------------------------------
63 //
64 //---------------------------------------
66 class RegistryKeyImpl
68 public:
70 //############################################
71 // Destruction
72 //############################################
74 virtual ~RegistryKeyImpl();
77 //############################################
78 // Queries
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
91 @throws
93 virtual size_t GetSubValueCount() const = 0;
95 /** The number of sub-keys of the key at hand
97 @precond IsOpen = true
99 @throws
101 virtual size_t GetSubKeyCount() const = 0;
103 bool IsOpen() const;
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
111 to the caller
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
121 to the caller
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
144 value
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
154 sub-key
156 @precond IsOpen = true
158 throws RegistryAccessDenyException
160 bool HasSubKey(const std::wstring& Name) const;
163 //############################################
164 // Commands
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
184 by sub-classes
186 void Close();
188 /** Open the specified sub-key of the registry key
189 at hand
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
203 IsWriteable = 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
214 IsWriteable = 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
222 its sub-keys
224 @precond IsOpen = true
225 IsWriteable = true;
227 @throws RegistryIOException
228 RegistryWriteAccessDenyException
230 virtual void DeleteSubKeyTree(const std::wstring& Name) = 0;
232 /** Delete the specified value
234 @precond IsOpen = true
235 IsWriteable = 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
247 IsWriteable = 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
261 IsWriteable = 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
276 IsWriteable = 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 //############################################
286 // Creation
287 // only possible through WindowsRegistry class
288 //############################################
291 protected:
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
317 HKEY_CLASSES_ROOT
318 HKEY_CURRENT_USER
319 etc.
321 bool IsRootKey() const;
323 protected:
324 HKEY m_hRootKey;
325 HKEY m_hSubKey;
326 std::wstring m_KeyName;
327 bool m_IsWriteable;
329 // prevent copy and assignment
330 private:
331 RegistryKeyImpl(const RegistryKeyImpl&);
332 RegistryKeyImpl& operator=(const RegistryKeyImpl&);
334 //######################################
335 // Friend declarations
336 //######################################
338 friend class WindowsRegistry;
341 #endif