Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / reg4msdoc / registry.hxx
blobd993060ae560823b5c73e4dfea96322171a8f83d
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_
32 #ifdef _MSC_VER
33 #pragma warning(push, 1) /* disable warnings within system headers */
34 #endif
35 #include <windows.h>
36 #ifdef _MSC_VER
37 #pragma warning(pop)
38 #endif
40 #include <memory>
41 #include <vector>
42 #include <string>
44 #include "registryvalueimpl.hxx"
46 //---------------------------------------
47 // forward declaration
48 //---------------------------------------
50 class RegistryKeyImpl;
52 //---------------------------------------
53 // typedefs
54 //---------------------------------------
56 typedef std::auto_ptr<RegistryKeyImpl> RegistryKey;
57 typedef std::vector<std::wstring> StringList;
58 typedef std::auto_ptr<StringList> StringListPtr;
60 class RegistryKeyImpl
62 public:
64 //############################################
65 // Destruction
66 //############################################
68 virtual ~RegistryKeyImpl();
71 //############################################
72 // Queries
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
85 @throws
87 virtual size_t GetSubValueCount() const = 0;
89 /** The number of sub-keys of the key at hand
91 @precond IsOpen = true
93 @throws
95 virtual size_t GetSubKeyCount() const = 0;
97 bool IsOpen() const;
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
105 to the caller
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
115 to the caller
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
138 value
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
148 sub-key
150 @precond IsOpen = true
152 throws RegistryAccessDenyException
154 bool HasSubKey(const std::wstring& Name) const;
157 //############################################
158 // Commands
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
178 by sub-classes
180 void Close();
182 /** Open the specified sub-key of the registry key
183 at hand
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
197 IsWriteable = 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
208 IsWriteable = 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
216 its sub-keys
218 @precond IsOpen = true
219 IsWriteable = true;
221 @throws RegistryIOException
222 RegistryWriteAccessDenyException
224 virtual void DeleteSubKeyTree(const std::wstring& Name) = 0;
226 /** Delete the specified value
228 @precond IsOpen = true
229 IsWriteable = 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
241 IsWriteable = 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
255 IsWriteable = 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
270 IsWriteable = 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 //############################################
280 // Creation
281 // only possible through WindowsRegistry class
282 //############################################
285 protected:
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
311 HKEY_CLASSES_ROOT
312 HKEY_CURRENT_USER
313 etc.
315 bool IsRootKey() const;
317 protected:
318 HKEY m_hRootKey;
319 HKEY m_hSubKey;
320 std::wstring m_KeyName;
321 bool m_IsWriteable;
323 // prevent copy and assignment
324 private:
325 RegistryKeyImpl(const RegistryKeyImpl&);
326 RegistryKeyImpl& operator=(const RegistryKeyImpl&);
328 //######################################
329 // Friend declarations
330 //######################################
332 friend class WindowsRegistry;
335 #endif
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */