Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / registry / registry.hxx
blob9309e7ff03110c480ea2d573c33c9bc6f89c3199
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_REGISTRY_REGISTRY_HXX
21 #define INCLUDED_REGISTRY_REGISTRY_HXX
23 #include <registry/regdllapi.h>
24 #include <registry/regtype.h>
25 #include <rtl/ustring.hxx>
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 /** specifies a collection of function pointers which represents the complete registry C-API.
33 These function pointers are used by the C++ wrapper to call the C-API.
35 struct Registry_Api
37 void (REGISTRY_CALLTYPE *acquire) (RegHandle);
38 void (REGISTRY_CALLTYPE *release) (RegHandle);
39 sal_Bool (REGISTRY_CALLTYPE *isReadOnly) (RegHandle);
40 RegError (REGISTRY_CALLTYPE *openRootKey) (RegHandle, RegKeyHandle*);
41 RegError (REGISTRY_CALLTYPE *getName) (RegHandle, rtl_uString**);
42 RegError (REGISTRY_CALLTYPE *createRegistry) (rtl_uString*, RegHandle*);
43 RegError (REGISTRY_CALLTYPE *openRegistry) (rtl_uString*, RegHandle*, RegAccessMode);
44 RegError (REGISTRY_CALLTYPE *closeRegistry) (RegHandle);
45 RegError (REGISTRY_CALLTYPE *destroyRegistry) (RegHandle, rtl_uString*);
46 RegError (REGISTRY_CALLTYPE *mergeKey) (RegHandle, RegKeyHandle, rtl_uString*, rtl_uString*, sal_Bool, sal_Bool);
47 void (REGISTRY_CALLTYPE *acquireKey) (RegKeyHandle);
48 void (REGISTRY_CALLTYPE *releaseKey) (RegKeyHandle);
49 sal_Bool (REGISTRY_CALLTYPE *isKeyReadOnly) (RegKeyHandle);
50 RegError (REGISTRY_CALLTYPE *getKeyName) (RegKeyHandle, rtl_uString**);
51 RegError (REGISTRY_CALLTYPE *createKey) (RegKeyHandle, rtl_uString*, RegKeyHandle*);
52 RegError (REGISTRY_CALLTYPE *openKey) (RegKeyHandle, rtl_uString*, RegKeyHandle*);
53 RegError (REGISTRY_CALLTYPE *openSubKeys) (RegKeyHandle, rtl_uString*, RegKeyHandle**, sal_uInt32*);
54 RegError (REGISTRY_CALLTYPE *closeSubKeys) (RegKeyHandle*, sal_uInt32);
55 RegError (REGISTRY_CALLTYPE *deleteKey) (RegKeyHandle, rtl_uString*);
56 RegError (REGISTRY_CALLTYPE *closeKey) (RegKeyHandle);
57 RegError (REGISTRY_CALLTYPE *setValue) (RegKeyHandle, rtl_uString*, RegValueType, RegValue, sal_uInt32);
58 RegError (REGISTRY_CALLTYPE *setLongListValue) (RegKeyHandle, rtl_uString*, sal_Int32*, sal_uInt32);
59 RegError (REGISTRY_CALLTYPE *setStringListValue) (RegKeyHandle, rtl_uString*, sal_Char**, sal_uInt32);
60 RegError (REGISTRY_CALLTYPE *setUnicodeListValue)(RegKeyHandle, rtl_uString*, sal_Unicode**, sal_uInt32);
61 RegError (REGISTRY_CALLTYPE *getValueInfo) (RegKeyHandle, rtl_uString*, RegValueType*, sal_uInt32*);
62 RegError (REGISTRY_CALLTYPE *getValue) (RegKeyHandle, rtl_uString*, RegValue);
63 RegError (REGISTRY_CALLTYPE *getLongListValue) (RegKeyHandle, rtl_uString*, sal_Int32**, sal_uInt32*);
64 RegError (REGISTRY_CALLTYPE *getStringListValue) (RegKeyHandle, rtl_uString*, sal_Char***, sal_uInt32*);
65 RegError (REGISTRY_CALLTYPE *getUnicodeListValue)(RegKeyHandle, rtl_uString*, sal_Unicode***, sal_uInt32*);
66 RegError (REGISTRY_CALLTYPE *freeValueList) (RegValueType, RegValue, sal_uInt32);
67 RegError (REGISTRY_CALLTYPE *getResolvedKeyName) (RegKeyHandle, rtl_uString*, sal_Bool, rtl_uString**);
68 RegError (REGISTRY_CALLTYPE *getKeyNames) (RegKeyHandle, rtl_uString*, rtl_uString***, sal_uInt32*);
69 RegError (REGISTRY_CALLTYPE *freeKeyNames) (rtl_uString**, sal_uInt32);
72 /** the API initialization function.
74 REG_DLLPUBLIC Registry_Api* REGISTRY_CALLTYPE initRegistry_Api();
76 #ifdef __cplusplus
78 #endif
81 class RegistryKey;
84 /** The Registry provides the functionality to read and write information in a registry file.
86 The class is implemented inline and use a C-Api.
88 class Registry
90 public:
91 /** Default constructor.
93 inline Registry();
95 /// Copy constructor
96 inline Registry(const Registry& toCopy);
98 /// Destructor. The Destructor close the registry if it is open.
99 inline ~Registry();
101 /// Assign operator
102 inline Registry& operator = (const Registry& toAssign);
104 /// checks if the registry points to a valid registry data file.
105 inline bool isValid() const;
107 /** returns the access mode of the registry.
109 @return TRUE if the access mode is readonly else FALSE.
111 inline bool isReadOnly() const;
113 /** opens the root key of the registry.
115 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
116 @return RegError::NO_ERROR if succeeds else an error code.
118 inline RegError openRootKey(RegistryKey& rRootKey);
120 /// returns the name of the current registry data file.
121 inline rtl::OUString getName();
123 /** creates a new registry with the specified name and creates a root key.
125 @param registryName specifies the name of the new registry.
126 @return RegError::NO_ERROR if succeeds else an error code.
128 inline RegError create(const rtl::OUString& registryName);
130 /** opens a registry with the specified name.
132 If the registry already points to a valid registry, the old registry will be closed.
133 @param registryName specifies a registry name.
134 @param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
135 @return RegError::NO_ERROR if succeeds else an error code.
137 inline RegError open(const rtl::OUString& registryName,
138 RegAccessMode accessMode);
140 /// closes explicitly the current registry data file.
141 inline RegError close();
143 /** destroys a registry.
145 @param registryName specifies a registry name, if the name is an empty string the registry
146 itself will be destroyed.
147 @return RegError::NO_ERROR if succeeds else an error code.
149 inline RegError destroy(const rtl::OUString& registryName);
151 /** merges the registry information of the specified key with the registry
152 information of the specified file.
154 All existing keys will be extended and existing key values will be overwritten.
155 @param rKey references a currently open key. The key which information is merged by this
156 function is a subkey of this key
157 @param keyName specifies the name of the key which will be merged.
158 If keyName is an empty string the registry information under the key specified
159 by rKey is merged with the information from the specified file.
160 @param regFileName specifies the file containing the registry information.
161 @param bWarnings if TRUE the function returns an error if a key already exists.
162 @param bReport if TRUE the function reports warnings on stdout if a key already exists.
163 @return RegError::NO_ERROR if succeeds else an error code. If it returns an error the registry will
164 restore the state before merging.
166 inline RegError mergeKey(RegistryKey& rKey,
167 const rtl::OUString& keyName,
168 const rtl::OUString& regFileName,
169 bool bWarnings = false,
170 bool bReport = false);
172 friend class RegistryKey;
173 friend class RegistryKeyArray;
174 friend class RegistryKeyNames;
176 /// returns the used registry Api.
177 const Registry_Api* getApi() { return m_pApi; }
178 protected:
180 /// stores the used and initialized registry Api.
181 const Registry_Api* m_pApi;
182 /// stores the handle of the underlying registry file on which most of the functions work.
183 RegHandle m_hImpl;
187 /** RegistryKeyArray represents an array of open keys.
189 RegistryKeyArray is a helper class to work with an array of keys.
191 class RegistryKeyArray
193 public:
194 /// Default constructor
195 inline RegistryKeyArray();
197 /// Destructor, all subkeys will be closed.
198 inline ~RegistryKeyArray();
200 /// returns the open key specified by index.
201 inline RegistryKey getElement(sal_uInt32 index);
203 /// returns the length of the array.
204 inline sal_uInt32 getLength();
206 friend class RegistryKey;
207 protected:
208 /** sets the data of the key array.
210 @param registry specifies the registry files where the keys are located.
211 @param phKeys points to an array of open keys.
212 @param length specifies the length of the array specified by phKeys.
214 inline void setKeyHandles(Registry& registry, RegKeyHandle* phKeys, sal_uInt32 length);
216 /// stores the number of open subkeys, the number of elements.
217 sal_uInt32 m_length;
218 /// stores an array of open subkeys.
219 RegKeyHandle* m_phKeys;
220 /// stores the handle to the registry file where the appropriate keys are located.
221 Registry m_registry;
225 /** RegistryKeyNames represents an array of key names.
227 RegistryKeyNames is a helper class to work with an array of key names.
229 class RegistryKeyNames
231 public:
232 /// Default constructor
233 inline RegistryKeyNames();
235 /// Destructor, the internal array with key names will be deleted.
236 inline ~RegistryKeyNames();
238 /// returns the name of the key sepecified by index.
239 inline rtl::OUString getElement(sal_uInt32 index);
241 /// returns the length of the array.
242 inline sal_uInt32 getLength();
244 friend class RegistryKey;
245 protected:
246 /** sets the data of the array.
248 @param registry specifies the registry files where the keys are located.
249 @param pKeyNames points to an array of key names.
250 @param length specifies the length of the array specified by pKeyNames.
252 inline void setKeyNames(Registry& registry, rtl_uString** pKeyNames, sal_uInt32 length);
254 /// stores the number of key names, the number of elements.
255 sal_uInt32 m_length;
256 /// stores an array of key names.
257 rtl_uString** m_pKeyNames;
258 /// stores the handle to the registry file where the appropriate keys are located.
259 Registry m_registry;
263 /** RegistryValueList represents a value list of the specified type.
265 RegistryValueList is a helper class to work with a list value.
267 template<class ValueType>
268 class RegistryValueList
270 public:
271 /// Default constructor
272 RegistryValueList()
273 : m_length(0)
274 , m_pValueList(nullptr)
275 , m_valueType(RegValueType::NOT_DEFINED)
278 /// Destructor, the internal value list will be freed.
279 ~RegistryValueList()
281 if (m_pValueList)
283 m_registry.getApi()->freeValueList(m_valueType, m_pValueList, m_length);
287 /// returns the value of the list specified by index.
288 ValueType getElement(sal_uInt32 index)
290 if (m_registry.isValid() && index < m_length)
292 return m_pValueList[index];
293 } else
295 return 0;
299 /// returns the length of the list.
300 sal_uInt32 getLength()
302 return m_length;
305 friend class RegistryKey;
306 protected:
307 /** sets the data of the value list.
309 @param registry specifies the registry files where the appropriate key is located.
310 @param valueType specifies the type of the list values.
311 @param pValueList points to a value list.
312 @param length specifies the length of the list.
314 void setValueList(Registry& registry, RegValueType valueType,
315 ValueType* pValueList, sal_uInt32 length)
317 m_length = length;
318 m_pValueList = pValueList;
319 m_valueType = valueType;
320 m_registry = registry;
323 /// stores the length of the list, the number of elements.
324 sal_uInt32 m_length;
325 /// stores the value list.
326 ValueType* m_pValueList;
327 /// stores the type of the list elements
328 RegValueType m_valueType;
329 /** stores the handle to the registry file where the appropriate key to this
330 value is located.
332 Registry m_registry;
336 /** RegistryKey reads or writes information of the underlying key in a registry.
338 Class is inline and use a load on call C-Api.
340 class RegistryKey
342 public:
343 /// Default constructor
344 inline RegistryKey();
346 /// Copy constructor
347 inline RegistryKey(const RegistryKey& toCopy);
349 /// Destructor, close the key if it references an open one.
350 inline ~RegistryKey();
352 /// Assign operator
353 inline RegistryKey& operator = (const RegistryKey& toAssign);
355 /// checks if the key points to a valid registry key.
356 inline bool isValid() const;
358 /** returns the access mode of the key.
360 @return TRUE if access mode is read only else FALSE.
362 inline bool isReadOnly() const;
364 /// returns the full qualified name of the key beginning with the rootkey.
365 inline rtl::OUString getName();
367 /** creates a new key or opens a key if the specified key already exists.
369 The specified keyname is relativ to this key.
370 @param keyName specifies the name of the key which will be opened or created.
371 @param rNewKey references a RegistryKey which will be filled with the new or open key.
372 @return RegError::NO_ERROR if succeeds else an error code.
374 inline RegError createKey(const rtl::OUString& keyName,
375 RegistryKey& rNewKey);
377 /** opens the specified key.
379 The specified keyname is relativ to this key.
380 @param keyName specifies the name of the key which will be opened.
381 @param rOpenKey references a RegistryKey which will be filled with the open key.
382 @return RegError::NO_ERROR if succeeds else an error code.
384 inline RegError openKey(const rtl::OUString& keyName,
385 RegistryKey& rOpenKey);
387 /** opens all subkeys of the specified key.
389 The specified keyname is relativ to this key.
390 @param keyName specifies the name of the key which subkeys will be opened.
391 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
392 @return RegError::NO_ERROR if succeeds else an error code.
394 inline RegError openSubKeys(const rtl::OUString& keyName,
395 RegistryKeyArray& rSubKeys);
397 /** returns an array with the names of all subkeys of the specified key.
399 The specified keyname is relativ to this key.
400 @param keyName specifies the name of the key which subkey names will be returned.
401 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
402 @return RegError::NO_ERROR if succeeds else an error code.
404 inline RegError getKeyNames(const rtl::OUString& keyName,
405 RegistryKeyNames& rSubKeyNames);
407 /** deletes the specified key.
409 @param keyName specifies the name of the key which will be deleted.
410 @return RegError::NO_ERROR if succeeds else an error code.
412 inline RegError deleteKey(const rtl::OUString& keyName);
414 /// closes explicitly the current key
415 inline RegError closeKey();
417 /// releases the current key
418 inline void releaseKey();
420 /** sets a value of a key.
422 @param keyName specifies the name of the key which value will be set.
423 If keyName is an empty string, the value will be set for the key
424 specified by hKey.
425 @param valueType specifies the type of the value.
426 @param pValue points to a memory block containing the data for the value.
427 @param valueSize specifies the size of pData in bytes
428 @return RegError::NO_ERROR if succeeds else an error code.
430 inline RegError setValue(const rtl::OUString& keyName,
431 RegValueType valueType,
432 RegValue pValue,
433 sal_uInt32 valueSize);
435 /** sets a long list value of a key.
437 @param keyName specifies the name of the key which value will be set.
438 If keyName is an empty string, the value will be set for the key
439 specified by hKey.
440 @param pValueList points to an array of longs containing the data for the value.
441 @param len specifies the length of the list (the array referenced by pValueList).
442 @return RegError::NO_ERROR if succeeds else an error code.
444 inline RegError setLongListValue(const rtl::OUString& keyName,
445 sal_Int32* pValueList,
446 sal_uInt32 len);
448 /** sets an ascii list value of a key.
450 @param keyName specifies the name of the key which value will be set.
451 If keyName is an empty string, the value will be set for the key
452 specified by hKey.
453 @param pValueList points to an array of sal_Char* containing the data for the value.
454 @param len specifies the length of the list (the array referenced by pValueList).
455 @return RegError::NO_ERROR if succeeds else an error code.
457 inline RegError setStringListValue(const rtl::OUString& keyName,
458 sal_Char** pValueList,
459 sal_uInt32 len);
461 /** sets an unicode string list value of a key.
463 @param keyName specifies the name of the key which value will be set.
464 If keyName is an empty string, the value will be set for the key
465 specified by hKey.
466 @param pValueList points to an array of sal_Unicode* containing the data for the value.
467 @param len specifies the length of the list (the array referenced by pValueList).
468 @return RegError::NO_ERROR if succeeds else an error code.
470 inline RegError setUnicodeListValue(const rtl::OUString& keyName,
471 sal_Unicode** pValueList,
472 sal_uInt32 len);
474 /** gets info about type and size of a value.
476 @param keyName specifies the name of the key which value info will be returned.
477 If keyName is an empty string, the value info of the key
478 specified by hKey will be returned.
479 @param pValueType returns the type of the value.
480 @param pValueSize returns the size of the value in bytes or the length of a list value.
481 @return RegError::NO_ERROR if succeeds else an error code.
483 inline RegError getValueInfo(const rtl::OUString& keyName,
484 RegValueType* pValueType,
485 sal_uInt32* pValueSize);
487 /** gets the value of a key.
489 @param keyName specifies the name of the key which value will be returned.
490 If keyName is an empty string, the value is get from the key
491 specified by hKey.
492 @param pValue points to an allocated memory block receiving the data of the value.
493 @return RegError::NO_ERROR if succeeds else an error code.
495 inline RegError getValue(const rtl::OUString& keyName,
496 RegValue pValue);
498 /** gets a long list value of a key.
500 @param keyName specifies the name of the key which value will be returned.
501 If keyName is an empty string, the value is get from the key
502 specified by hKey.
503 @param rValueList references a RegistryValueList which will be filled with the long values.
504 @return RegError::NO_ERROR if succeeds else an error code.
506 inline RegError getLongListValue(const rtl::OUString& keyName,
507 RegistryValueList<sal_Int32>& rValueList);
509 /** gets an ascii list value of a key.
511 @param keyName specifies the name of the key which value will be returned.
512 If keyName is an empty string, the value is get from the key
513 specified by hKey.
514 @param rValueList references a RegistryValueList which will be filled with the ascii values.
515 @return RegError::NO_ERROR if succeeds else an error code.
517 inline RegError getStringListValue(const rtl::OUString& keyName,
518 RegistryValueList<sal_Char*>& rValueList);
520 /** gets a unicode value of a key.
522 @param keyName specifies the name of the key which value will be returned.
523 If keyName is an empty string, the value is get from the key
524 specified by hKey.
525 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
526 @return RegError::NO_ERROR if succeeds else an error code.
528 inline RegError getUnicodeListValue(const rtl::OUString& keyName,
529 RegistryValueList<sal_Unicode*>& rValueList);
531 /** used to create a link.
533 @deprecated Links are no longer supported.
535 @return RegError::INVALID_LINK
537 inline RegError createLink(const rtl::OUString& linkName,
538 const rtl::OUString& linkTarget);
540 /** used to delete a link.
542 @deprecated Links are no longer supported.
544 @return RegError::INVALID_LINK
546 inline RegError deleteLink(const rtl::OUString& linkName);
548 /** used to return the target of a link.
550 @deprecated Links are no longer supported.
552 @return RegError::INVALID_LINK
554 inline RegError getLinkTarget(const rtl::OUString& linkName,
555 rtl::OUString& rLinkTarget) const;
557 /** resolves a keyname.
559 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
560 The resolved name will be prefixed with the name of this key.
561 @param[out] rResolvedName the resolved name.
562 @return RegError::NO_ERROR if succeeds else an error code.
564 inline RegError getResolvedKeyName(const rtl::OUString& keyName,
565 rtl::OUString& rResolvedName) const;
567 /// returns the name of the registry in which the key is defined.
568 inline rtl::OUString getRegistryName();
570 friend class Registry;
571 public:
572 /// @cond INTERNAL
574 /** Constructor, which initialize a RegistryKey with registry and an valid key handle.
576 This constructor is internal only.
578 inline RegistryKey(Registry& registry,
579 RegKeyHandle hKey);
581 protected:
582 /** sets the internal registry on which this key should work.
584 inline void setRegistry(Registry& registry);
586 /// @endcond
588 /// stores the registry on which this key works
589 Registry m_registry;
590 /// stores the current key handle of this key
591 RegKeyHandle m_hImpl;
595 inline RegistryKeyArray::RegistryKeyArray()
596 : m_length(0)
597 , m_phKeys(nullptr)
601 inline RegistryKeyArray::~RegistryKeyArray()
603 if (m_phKeys)
604 m_registry.m_pApi->closeSubKeys(m_phKeys, m_length);
607 inline RegistryKey RegistryKeyArray::getElement(sal_uInt32 index)
609 if (m_registry.isValid() && index < m_length)
610 return RegistryKey(m_registry, m_phKeys[index]);
611 else
612 return RegistryKey();
615 inline sal_uInt32 RegistryKeyArray::getLength()
617 return m_length;
620 inline void RegistryKeyArray::setKeyHandles(Registry& registry,
621 RegKeyHandle* phKeys,
622 sal_uInt32 length)
624 m_phKeys = phKeys;
625 m_length = length;
626 m_registry = registry;
629 inline RegistryKeyNames::RegistryKeyNames()
630 : m_length(0)
631 , m_pKeyNames(nullptr)
635 inline RegistryKeyNames::~RegistryKeyNames()
637 if (m_pKeyNames)
638 m_registry.m_pApi->freeKeyNames(m_pKeyNames, m_length);
641 inline rtl::OUString RegistryKeyNames::getElement(sal_uInt32 index)
644 if (m_pKeyNames && index < m_length)
645 return m_pKeyNames[index];
646 else
647 return rtl::OUString();
650 inline sal_uInt32 RegistryKeyNames::getLength()
652 return m_length;
655 inline void RegistryKeyNames::setKeyNames(Registry& registry,
656 rtl_uString** pKeyNames,
657 sal_uInt32 length)
659 m_pKeyNames = pKeyNames;
660 m_length = length;
661 m_registry = registry;
664 inline RegistryKey::RegistryKey()
665 : m_hImpl(nullptr)
668 /// @cond INTERNAL
669 inline RegistryKey::RegistryKey(Registry& registry, RegKeyHandle hKey)
670 : m_registry(registry)
671 , m_hImpl(hKey)
673 if (m_hImpl)
674 m_registry.m_pApi->acquireKey(m_hImpl);
676 /// @endcond
678 inline RegistryKey::RegistryKey(const RegistryKey& toCopy)
679 : m_registry(toCopy.m_registry)
680 , m_hImpl(toCopy.m_hImpl)
682 if (m_hImpl)
683 m_registry.m_pApi->acquireKey(m_hImpl);
686 /// @cond INTERNAL
687 inline void RegistryKey::setRegistry(Registry& registry)
689 m_registry = registry;
691 /// @endcond
693 inline RegistryKey::~RegistryKey()
695 if (m_hImpl)
696 m_registry.m_pApi->releaseKey(m_hImpl);
699 inline RegistryKey& RegistryKey::operator = (const RegistryKey& toAssign)
701 m_registry = toAssign.m_registry;
703 if (toAssign.m_hImpl)
704 m_registry.m_pApi->acquireKey(toAssign.m_hImpl);
705 if (m_hImpl)
706 m_registry.m_pApi->releaseKey(m_hImpl);
707 m_hImpl = toAssign.m_hImpl;
709 return *this;
712 inline bool RegistryKey::isValid() const
713 { return (m_hImpl != nullptr); }
715 inline bool RegistryKey::isReadOnly() const
717 if (m_registry.isValid())
718 return (m_registry.m_pApi)->isKeyReadOnly(m_hImpl);
719 else
720 return false;
723 inline rtl::OUString RegistryKey::getName()
725 rtl::OUString sRet;
726 if (m_registry.isValid())
727 m_registry.m_pApi->getKeyName(m_hImpl, &sRet.pData);
728 return sRet;
731 inline RegError RegistryKey::createKey(const rtl::OUString& keyName,
732 RegistryKey& rNewKey)
734 if (rNewKey.isValid()) rNewKey.closeKey();
735 if (m_registry.isValid())
737 RegError ret = m_registry.m_pApi->createKey(m_hImpl, keyName.pData, &rNewKey.m_hImpl);
738 if (ret == RegError::NO_ERROR) rNewKey.setRegistry(m_registry);
739 return ret;
740 } else
741 return RegError::INVALID_KEY;
744 inline RegError RegistryKey::openKey(const rtl::OUString& keyName,
745 RegistryKey& rOpenKey)
747 if (rOpenKey.isValid()) rOpenKey.closeKey();
748 if (m_registry.isValid())
750 RegError ret = m_registry.m_pApi->openKey(m_hImpl, keyName.pData,
751 &rOpenKey.m_hImpl);
752 if (ret == RegError::NO_ERROR) rOpenKey.setRegistry(m_registry);
753 return ret;
754 } else
755 return RegError::INVALID_KEY;
758 inline RegError RegistryKey::openSubKeys(const rtl::OUString& keyName,
759 RegistryKeyArray& rSubKeys)
761 if (m_registry.isValid())
763 RegError ret = RegError::NO_ERROR;
764 RegKeyHandle* pSubKeys;
765 sal_uInt32 nSubKeys;
766 ret = m_registry.m_pApi->openSubKeys(m_hImpl, keyName.pData,
767 &pSubKeys, &nSubKeys);
768 if ( ret != RegError::NO_ERROR)
770 return ret;
771 } else
773 rSubKeys.setKeyHandles(m_registry, pSubKeys, nSubKeys);
774 return ret;
776 } else
777 return RegError::INVALID_KEY;
780 inline RegError RegistryKey::getKeyNames(const rtl::OUString& keyName,
781 RegistryKeyNames& rSubKeyNames)
783 if (m_registry.isValid())
785 RegError ret = RegError::NO_ERROR;
786 rtl_uString** pSubKeyNames;
787 sal_uInt32 nSubKeys;
788 ret = m_registry.m_pApi->getKeyNames(m_hImpl, keyName.pData,
789 &pSubKeyNames, &nSubKeys);
790 if ( ret != RegError::NO_ERROR)
792 return ret;
793 } else
795 rSubKeyNames.setKeyNames(m_registry, pSubKeyNames, nSubKeys);
796 return ret;
798 } else
799 return RegError::INVALID_KEY;
802 inline RegError RegistryKey::deleteKey(const rtl::OUString& keyName)
804 if (m_registry.isValid())
805 return m_registry.m_pApi->deleteKey(m_hImpl, keyName.pData);
806 else
807 return RegError::INVALID_KEY;
810 inline RegError RegistryKey::closeKey()
812 if (m_registry.isValid())
814 RegError ret = m_registry.m_pApi->closeKey(m_hImpl);
815 if (ret == RegError::NO_ERROR)
817 m_hImpl = nullptr;
818 m_registry = Registry();
820 return ret;
821 } else
822 return RegError::INVALID_KEY;
825 inline void RegistryKey::releaseKey()
827 if (m_registry.isValid() && (m_hImpl != nullptr))
829 m_registry.m_pApi->releaseKey(m_hImpl);
830 m_hImpl = nullptr;
834 inline RegError RegistryKey::setValue(const rtl::OUString& keyName,
835 RegValueType valueType,
836 RegValue pValue,
837 sal_uInt32 valueSize)
839 if (m_registry.isValid())
840 return m_registry.m_pApi->setValue(m_hImpl, keyName.pData, valueType,
841 pValue, valueSize);
842 else
843 return RegError::INVALID_KEY;
846 inline RegError RegistryKey::setLongListValue(const rtl::OUString& keyName,
847 sal_Int32* pValueList,
848 sal_uInt32 len)
850 if (m_registry.isValid())
851 return m_registry.m_pApi->setLongListValue(m_hImpl, keyName.pData,
852 pValueList, len);
853 else
854 return RegError::INVALID_KEY;
857 inline RegError RegistryKey::setStringListValue(const rtl::OUString& keyName,
858 sal_Char** pValueList,
859 sal_uInt32 len)
861 if (m_registry.isValid())
862 return m_registry.m_pApi->setStringListValue(m_hImpl, keyName.pData,
863 pValueList, len);
864 else
865 return RegError::INVALID_KEY;
868 inline RegError RegistryKey::setUnicodeListValue(const rtl::OUString& keyName,
869 sal_Unicode** pValueList,
870 sal_uInt32 len)
872 if (m_registry.isValid())
873 return m_registry.m_pApi->setUnicodeListValue(m_hImpl, keyName.pData,
874 pValueList, len);
875 else
876 return RegError::INVALID_KEY;
879 inline RegError RegistryKey::getValueInfo(const rtl::OUString& keyName,
880 RegValueType* pValueType,
881 sal_uInt32* pValueSize)
883 if (m_registry.isValid())
884 return m_registry.m_pApi->getValueInfo(m_hImpl, keyName.pData, pValueType, pValueSize);
885 else
886 return RegError::INVALID_KEY;
889 inline RegError RegistryKey::getValue(const rtl::OUString& keyName,
890 RegValue pValue)
892 if (m_registry.isValid())
893 return m_registry.m_pApi->getValue(m_hImpl, keyName.pData, pValue);
894 else
895 return RegError::INVALID_KEY;
898 inline RegError RegistryKey::getLongListValue(const rtl::OUString& keyName,
899 RegistryValueList<sal_Int32>& rValueList)
901 if (m_registry.isValid())
903 RegError ret = RegError::NO_ERROR;
904 sal_Int32* pValueList;
905 sal_uInt32 length;
906 ret = m_registry.m_pApi->getLongListValue(m_hImpl, keyName.pData,
907 &pValueList, &length);
908 if ( ret != RegError::NO_ERROR)
910 return ret;
911 } else
913 rValueList.setValueList(m_registry, RegValueType::LONGLIST,
914 pValueList, length);
915 return ret;
917 } else
918 return RegError::INVALID_KEY;
921 inline RegError RegistryKey::getStringListValue(const rtl::OUString& keyName,
922 RegistryValueList<sal_Char*>& rValueList)
924 if (m_registry.isValid())
926 RegError ret = RegError::NO_ERROR;
927 sal_Char** pValueList;
928 sal_uInt32 length;
929 ret = m_registry.m_pApi->getStringListValue(m_hImpl, keyName.pData,
930 &pValueList, &length);
931 if ( ret != RegError::NO_ERROR )
933 return ret;
934 } else
936 rValueList.setValueList(m_registry, RegValueType::STRINGLIST,
937 pValueList, length);
938 return ret;
940 } else
941 return RegError::INVALID_KEY;
944 inline RegError RegistryKey::getUnicodeListValue(const rtl::OUString& keyName,
945 RegistryValueList<sal_Unicode*>& rValueList)
947 if (m_registry.isValid())
949 RegError ret = RegError::NO_ERROR;
950 sal_Unicode** pValueList;
951 sal_uInt32 length;
952 ret = m_registry.m_pApi->getUnicodeListValue(m_hImpl, keyName.pData,
953 &pValueList, &length);
954 if ( ret != RegError::NO_ERROR )
956 return ret;
957 } else
959 rValueList.setValueList(m_registry, RegValueType::UNICODELIST,
960 pValueList, length);
961 return ret;
963 } else
964 return RegError::INVALID_KEY;
967 inline RegError RegistryKey::createLink(const rtl::OUString& ,
968 const rtl::OUString& )
970 if (m_registry.isValid())
971 return RegError::INVALID_LINK; // links are no longer supported
972 else
973 return RegError::INVALID_KEY;
976 inline RegError RegistryKey::deleteLink(const rtl::OUString& )
978 if (m_registry.isValid())
979 return RegError::INVALID_LINK; // links are no longer supported
980 else
981 return RegError::INVALID_KEY;
984 inline RegError RegistryKey::getLinkTarget(const rtl::OUString& ,
985 rtl::OUString& ) const
987 if (m_registry.isValid())
988 return RegError::INVALID_LINK; // links are no longer supported
989 else
990 return RegError::INVALID_KEY;
994 inline RegError RegistryKey::getResolvedKeyName(const rtl::OUString& keyName,
995 rtl::OUString& rResolvedName) const
997 if (m_registry.isValid())
998 return m_registry.m_pApi->getResolvedKeyName(m_hImpl,
999 keyName.pData,
1000 true,
1001 &rResolvedName.pData);
1002 else
1003 return RegError::INVALID_KEY;
1006 inline rtl::OUString RegistryKey::getRegistryName()
1008 if (m_registry.isValid())
1010 return m_registry.getName();
1011 } else
1012 return rtl::OUString();
1016 inline Registry::Registry()
1017 : m_pApi(initRegistry_Api())
1018 , m_hImpl(nullptr)
1021 inline Registry::Registry(const Registry& toCopy)
1022 : m_pApi(toCopy.m_pApi)
1023 , m_hImpl(toCopy.m_hImpl)
1025 if (m_hImpl)
1026 m_pApi->acquire(m_hImpl);
1030 inline Registry::~Registry()
1032 if (m_hImpl)
1033 m_pApi->release(m_hImpl);
1036 inline Registry& Registry::operator = (const Registry& toAssign)
1038 if (toAssign.m_hImpl)
1039 toAssign.m_pApi->acquire(toAssign.m_hImpl);
1040 if (m_hImpl)
1041 m_pApi->release(m_hImpl);
1043 m_pApi = toAssign.m_pApi;
1044 m_hImpl = toAssign.m_hImpl;
1046 return *this;
1049 inline bool Registry::isValid() const
1050 { return ( m_hImpl != nullptr ); }
1052 inline bool Registry::isReadOnly() const
1053 { return m_pApi->isReadOnly(m_hImpl); }
1055 inline RegError Registry::openRootKey(RegistryKey& rRootKey)
1057 rRootKey.setRegistry(*this);
1058 return m_pApi->openRootKey(m_hImpl, &rRootKey.m_hImpl);
1061 inline rtl::OUString Registry::getName()
1063 rtl::OUString sRet;
1064 m_pApi->getName(m_hImpl, &sRet.pData);
1065 return sRet;
1068 inline RegError Registry::create(const rtl::OUString& registryName)
1070 if (m_hImpl)
1071 m_pApi->release(m_hImpl);
1072 return m_pApi->createRegistry(registryName.pData, &m_hImpl);
1075 inline RegError Registry::open(const rtl::OUString& registryName,
1076 RegAccessMode accessMode)
1078 if (m_hImpl)
1079 m_pApi->release(m_hImpl);
1080 return m_pApi->openRegistry(registryName.pData, &m_hImpl, accessMode);
1083 inline RegError Registry::close()
1085 RegError ret = m_pApi->closeRegistry(m_hImpl);
1086 if (ret == RegError::NO_ERROR)
1087 m_hImpl = nullptr;
1088 return ret;
1091 inline RegError Registry::destroy(const rtl::OUString& registryName)
1093 RegError ret = m_pApi->destroyRegistry(m_hImpl, registryName.pData);
1094 if ( ret == RegError::NO_ERROR && registryName.isEmpty() )
1095 m_hImpl = nullptr;
1096 return ret;
1099 inline RegError Registry::mergeKey(RegistryKey& rKey,
1100 const rtl::OUString& keyName,
1101 const rtl::OUString& regFileName,
1102 bool bWarnings,
1103 bool bReport)
1104 { return m_pApi->mergeKey(m_hImpl, rKey.m_hImpl, keyName.pData, regFileName.pData, bWarnings, bReport); }
1107 #endif
1109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */