make ValueTransfer easier to understand
[LibreOffice.git] / include / registry / registry.hxx
blob3190b13ca66cd889063c456e6aad9d692428f0df
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 #pragma once
22 #include <registry/regdllapi.h>
23 #include <registry/regtype.h>
24 #include <rtl/ustring.hxx>
26 extern "C" {
28 /** specifies a collection of function pointers which represents the complete registry C-API.
30 These function pointers are used by the C++ wrapper to call the C-API.
32 struct Registry_Api
34 void (REGISTRY_CALLTYPE *acquire) (RegHandle);
35 void (REGISTRY_CALLTYPE *release) (RegHandle);
36 sal_Bool (REGISTRY_CALLTYPE *isReadOnly) (RegHandle);
37 RegError (REGISTRY_CALLTYPE *openRootKey) (RegHandle, RegKeyHandle*);
38 RegError (REGISTRY_CALLTYPE *getName) (RegHandle, rtl_uString**);
39 RegError (REGISTRY_CALLTYPE *createRegistry) (rtl_uString*, RegHandle*);
40 RegError (REGISTRY_CALLTYPE *openRegistry) (rtl_uString*, RegHandle*, RegAccessMode);
41 RegError (REGISTRY_CALLTYPE *closeRegistry) (RegHandle);
42 RegError (REGISTRY_CALLTYPE *destroyRegistry) (RegHandle, rtl_uString*);
43 RegError (REGISTRY_CALLTYPE *mergeKey) (RegHandle, RegKeyHandle, rtl_uString*, rtl_uString*, sal_Bool, sal_Bool);
44 void (REGISTRY_CALLTYPE *acquireKey) (RegKeyHandle);
45 void (REGISTRY_CALLTYPE *releaseKey) (RegKeyHandle);
46 sal_Bool (REGISTRY_CALLTYPE *isKeyReadOnly) (RegKeyHandle);
47 RegError (REGISTRY_CALLTYPE *getKeyName) (RegKeyHandle, rtl_uString**);
48 RegError (REGISTRY_CALLTYPE *createKey) (RegKeyHandle, rtl_uString*, RegKeyHandle*);
49 RegError (REGISTRY_CALLTYPE *openKey) (RegKeyHandle, rtl_uString*, RegKeyHandle*);
50 RegError (REGISTRY_CALLTYPE *openSubKeys) (RegKeyHandle, rtl_uString*, RegKeyHandle**, sal_uInt32*);
51 RegError (REGISTRY_CALLTYPE *closeSubKeys) (RegKeyHandle*, sal_uInt32);
52 RegError (REGISTRY_CALLTYPE *deleteKey) (RegKeyHandle, rtl_uString*);
53 RegError (REGISTRY_CALLTYPE *closeKey) (RegKeyHandle);
54 RegError (REGISTRY_CALLTYPE *setValue) (RegKeyHandle, rtl_uString*, RegValueType, RegValue, sal_uInt32);
55 RegError (REGISTRY_CALLTYPE *setLongListValue) (RegKeyHandle, rtl_uString*, sal_Int32 const *, sal_uInt32);
56 RegError (REGISTRY_CALLTYPE *setStringListValue) (RegKeyHandle, rtl_uString*, char**, sal_uInt32);
57 RegError (REGISTRY_CALLTYPE *setUnicodeListValue)(RegKeyHandle, rtl_uString*, sal_Unicode**, sal_uInt32);
58 RegError (REGISTRY_CALLTYPE *getValueInfo) (RegKeyHandle, rtl_uString*, RegValueType*, sal_uInt32*);
59 RegError (REGISTRY_CALLTYPE *getValue) (RegKeyHandle, rtl_uString*, RegValue);
60 RegError (REGISTRY_CALLTYPE *getLongListValue) (RegKeyHandle, rtl_uString*, sal_Int32**, sal_uInt32*);
61 RegError (REGISTRY_CALLTYPE *getStringListValue) (RegKeyHandle, rtl_uString*, char***, sal_uInt32*);
62 RegError (REGISTRY_CALLTYPE *getUnicodeListValue)(RegKeyHandle, rtl_uString*, sal_Unicode***, sal_uInt32*);
63 RegError (REGISTRY_CALLTYPE *freeValueList) (RegValueType, RegValue, sal_uInt32);
64 RegError (REGISTRY_CALLTYPE *getResolvedKeyName) (RegKeyHandle, rtl_uString*, sal_Bool, rtl_uString**);
65 RegError (REGISTRY_CALLTYPE *getKeyNames) (RegKeyHandle, rtl_uString*, rtl_uString***, sal_uInt32*);
66 RegError (REGISTRY_CALLTYPE *freeKeyNames) (rtl_uString**, sal_uInt32);
69 /** the API initialization function.
71 REG_DLLPUBLIC Registry_Api* REGISTRY_CALLTYPE initRegistry_Api();
75 class RegistryKey;
78 /** The Registry provides the functionality to read and write information in a registry file.
80 The class is implemented inline and use a C-Api.
82 class Registry final
84 public:
85 /** Default constructor.
87 inline Registry();
89 /// Copy constructor
90 inline Registry(const Registry& toCopy);
92 Registry(Registry && other) noexcept : m_pApi(other.m_pApi), m_hImpl(other.m_hImpl)
93 { other.m_hImpl = nullptr; }
95 /// Destructor. The Destructor close the registry if it is open.
96 inline ~Registry();
98 /// Assign operator
99 inline Registry& operator = (const Registry& toAssign);
101 Registry & operator =(Registry && other) {
102 if (m_hImpl != nullptr) {
103 m_pApi->release(m_hImpl);
105 m_hImpl = other.m_hImpl;
106 other.m_hImpl = nullptr;
107 return *this;
110 /// checks if the registry points to a valid registry data file.
111 inline bool isValid() const;
113 /** returns the access mode of the registry.
115 @return TRUE if the access mode is readonly else FALSE.
117 inline bool isReadOnly() const;
119 /** opens the root key of the registry.
121 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
122 @return RegError::NO_ERROR if succeeds else an error code.
124 inline RegError openRootKey(RegistryKey& rRootKey);
126 /// returns the name of the current registry data file.
127 inline OUString getName();
129 /** creates a new registry with the specified name and creates a root key.
131 @param registryName specifies the name of the new registry.
132 @return RegError::NO_ERROR if succeeds else an error code.
134 inline RegError create(const OUString& registryName);
136 /** opens a registry with the specified name.
138 If the registry already points to a valid registry, the old registry will be closed.
139 @param registryName specifies a registry name.
140 @param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
141 @return RegError::NO_ERROR if succeeds else an error code.
143 inline RegError open(const OUString& registryName,
144 RegAccessMode accessMode);
146 /// closes explicitly the current registry data file.
147 inline RegError close();
149 /** destroys a registry.
151 @param registryName specifies a registry name, if the name is an empty string the registry
152 itself will be destroyed.
153 @return RegError::NO_ERROR if succeeds else an error code.
155 inline RegError destroy(const OUString& registryName);
157 /** merges the registry information of the specified key with the registry
158 information of the specified file.
160 All existing keys will be extended and existing key values will be overwritten.
161 @param rKey references a currently open key. The key which information is merged by this
162 function is a subkey of this key
163 @param keyName specifies the name of the key which will be merged.
164 If keyName is an empty string the registry information under the key specified
165 by rKey is merged with the information from the specified file.
166 @param regFileName specifies the file containing the registry information.
167 @param bReport if TRUE the function reports warnings on stdout if a key already exists.
168 @return RegError::NO_ERROR if succeeds else an error code. If it returns an error the registry will
169 restore the state before merging.
171 inline RegError mergeKey(RegistryKey& rKey,
172 const OUString& keyName,
173 const OUString& regFileName,
174 bool bReport);
176 friend class RegistryKey;
177 friend class RegistryKeyArray;
178 friend class RegistryKeyNames;
180 /// returns the used registry Api.
181 const Registry_Api* getApi() const { return m_pApi; }
183 private:
184 /// stores the used and initialized registry Api.
185 const Registry_Api* m_pApi;
186 /// stores the handle of the underlying registry file on which most of the functions work.
187 RegHandle m_hImpl;
191 /** RegistryKeyArray represents an array of open keys.
193 RegistryKeyArray is a helper class to work with an array of keys.
195 class RegistryKeyArray
197 public:
198 /// Default constructor
199 inline RegistryKeyArray();
201 /// Destructor, all subkeys will be closed.
202 inline ~RegistryKeyArray();
204 /// returns the open key specified by index.
205 inline RegistryKey getElement(sal_uInt32 index);
207 /// returns the length of the array.
208 inline sal_uInt32 getLength() const;
210 friend class RegistryKey;
212 private:
213 /** sets the data of the key array.
215 @param registry specifies the registry files where the keys are located.
216 @param phKeys points to an array of open keys.
217 @param length specifies the length of the array specified by phKeys.
219 inline void setKeyHandles(Registry const & registry, RegKeyHandle* phKeys, sal_uInt32 length);
221 /// stores the number of open subkeys, the number of elements.
222 sal_uInt32 m_length;
223 /// stores an array of open subkeys.
224 RegKeyHandle* m_phKeys;
225 /// stores the handle to the registry file where the appropriate keys are located.
226 Registry m_registry;
230 /** RegistryKeyNames represents an array of key names.
232 RegistryKeyNames is a helper class to work with an array of key names.
234 class RegistryKeyNames
236 public:
237 /// Default constructor
238 inline RegistryKeyNames();
240 /// Destructor, the internal array with key names will be deleted.
241 inline ~RegistryKeyNames();
243 /// returns the name of the key specified by index.
244 inline OUString getElement(sal_uInt32 index);
246 /// returns the length of the array.
247 inline sal_uInt32 getLength() const;
249 friend class RegistryKey;
251 private:
252 /** sets the data of the array.
254 @param registry specifies the registry files where the keys are located.
255 @param pKeyNames points to an array of key names.
256 @param length specifies the length of the array specified by pKeyNames.
258 inline void setKeyNames(Registry const & registry, rtl_uString** pKeyNames, sal_uInt32 length);
260 /// stores the number of key names, the number of elements.
261 sal_uInt32 m_length;
262 /// stores an array of key names.
263 rtl_uString** m_pKeyNames;
264 /// stores the handle to the registry file where the appropriate keys are located.
265 Registry m_registry;
269 /** RegistryValueList represents a value list of the specified type.
271 RegistryValueList is a helper class to work with a list value.
273 template<class ValueType>
274 class RegistryValueList final
276 public:
277 /// Default constructor
278 RegistryValueList()
279 : m_length(0)
280 , m_pValueList(nullptr)
281 , m_valueType(RegValueType::NOT_DEFINED)
284 /// Destructor, the internal value list will be freed.
285 ~RegistryValueList()
287 if (m_pValueList)
289 m_registry.getApi()->freeValueList(m_valueType, m_pValueList, m_length);
293 /// returns the value of the list specified by index.
294 ValueType getElement(sal_uInt32 index)
296 if (m_registry.isValid() && index < m_length)
298 return m_pValueList[index];
299 } else
301 return 0;
305 /// returns the length of the list.
306 sal_uInt32 getLength()
308 return m_length;
311 friend class RegistryKey;
313 private:
314 /** sets the data of the value list.
316 @param registry specifies the registry files where the appropriate key is located.
317 @param valueType specifies the type of the list values.
318 @param pValueList points to a value list.
319 @param length specifies the length of the list.
321 void setValueList(const Registry& registry, RegValueType valueType,
322 ValueType* pValueList, sal_uInt32 length)
324 m_length = length;
325 m_pValueList = pValueList;
326 m_valueType = valueType;
327 m_registry = registry;
330 /// stores the length of the list, the number of elements.
331 sal_uInt32 m_length;
332 /// stores the value list.
333 ValueType* m_pValueList;
334 /// stores the type of the list elements
335 RegValueType m_valueType;
336 /** stores the handle to the registry file where the appropriate key to this
337 value is located.
339 Registry m_registry;
343 /** RegistryKey reads or writes information of the underlying key in a registry.
345 Class is inline and use a load on call C-Api.
347 class RegistryKey
349 public:
350 /// Default constructor
351 inline RegistryKey();
353 /// Copy constructor
354 inline RegistryKey(const RegistryKey& toCopy);
356 /// Destructor, close the key if it references an open one.
357 inline ~RegistryKey();
359 /// Assign operator
360 inline RegistryKey& operator = (const RegistryKey& toAssign);
362 /// checks if the key points to a valid registry key.
363 inline bool isValid() const;
365 /** returns the access mode of the key.
367 @return TRUE if access mode is read only else FALSE.
369 inline bool isReadOnly() const;
371 /// returns the full qualified name of the key beginning with the rootkey.
372 inline OUString getName();
374 /** creates a new key or opens a key if the specified key already exists.
376 The specified keyname is relative to this key.
377 @param keyName specifies the name of the key which will be opened or created.
378 @param rNewKey references a RegistryKey which will be filled with the new or open key.
379 @return RegError::NO_ERROR if succeeds else an error code.
381 inline RegError createKey(const OUString& keyName,
382 RegistryKey& rNewKey);
384 /** opens the specified key.
386 The specified keyname is relative to this key.
387 @param keyName specifies the name of the key which will be opened.
388 @param rOpenKey references a RegistryKey which will be filled with the open key.
389 @return RegError::NO_ERROR if succeeds else an error code.
391 inline RegError openKey(const OUString& keyName,
392 RegistryKey& rOpenKey);
394 /** opens all subkeys of the specified key.
396 The specified keyname is relative to this key.
397 @param keyName specifies the name of the key which subkeys will be opened.
398 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
399 @return RegError::NO_ERROR if succeeds else an error code.
401 inline RegError openSubKeys(const OUString& keyName,
402 RegistryKeyArray& rSubKeys);
404 /** returns an array with the names of all subkeys of the specified key.
406 The specified keyname is relative to this key.
407 @param keyName specifies the name of the key which subkey names will be returned.
408 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
409 @return RegError::NO_ERROR if succeeds else an error code.
411 inline RegError getKeyNames(const OUString& keyName,
412 RegistryKeyNames& rSubKeyNames);
414 /** deletes the specified key.
416 @param keyName specifies the name of the key which will be deleted.
417 @return RegError::NO_ERROR if succeeds else an error code.
419 inline RegError deleteKey(const OUString& keyName);
421 /// closes explicitly the current key
422 inline RegError closeKey();
424 /// releases the current key
425 inline void releaseKey();
427 /** sets a value of a key.
429 @param keyName specifies the name of the key which value will be set.
430 If keyName is an empty string, the value will be set for the key
431 specified by hKey.
432 @param valueType specifies the type of the value.
433 @param pValue points to a memory block containing the data for the value.
434 @param valueSize specifies the size of pData in bytes
435 @return RegError::NO_ERROR if succeeds else an error code.
437 inline RegError setValue(const OUString& keyName,
438 RegValueType valueType,
439 RegValue pValue,
440 sal_uInt32 valueSize);
442 /** sets a long list value of a key.
444 @param keyName specifies the name of the key which value will be set.
445 If keyName is an empty string, the value will be set for the key
446 specified by hKey.
447 @param pValueList points to an array of longs containing the data for the value.
448 @param len specifies the length of the list (the array referenced by pValueList).
449 @return RegError::NO_ERROR if succeeds else an error code.
451 inline RegError setLongListValue(const OUString& keyName,
452 sal_Int32 const * pValueList,
453 sal_uInt32 len);
455 /** sets an ascii list value of a key.
457 @param keyName specifies the name of the key which value will be set.
458 If keyName is an empty string, the value will be set for the key
459 specified by hKey.
460 @param pValueList points to an array of char* containing the data for the value.
461 @param len specifies the length of the list (the array referenced by pValueList).
462 @return RegError::NO_ERROR if succeeds else an error code.
464 inline RegError setStringListValue(const OUString& keyName,
465 char** pValueList,
466 sal_uInt32 len);
468 /** sets a unicode string list value of a key.
470 @param keyName specifies the name of the key which value will be set.
471 If keyName is an empty string, the value will be set for the key
472 specified by hKey.
473 @param pValueList points to an array of sal_Unicode* containing the data for the value.
474 @param len specifies the length of the list (the array referenced by pValueList).
475 @return RegError::NO_ERROR if succeeds else an error code.
477 inline RegError setUnicodeListValue(const OUString& keyName,
478 sal_Unicode** pValueList,
479 sal_uInt32 len);
481 /** gets info about type and size of a value.
483 @param keyName specifies the name of the key which value info will be returned.
484 If keyName is an empty string, the value info of the key
485 specified by hKey will be returned.
486 @param pValueType returns the type of the value.
487 @param pValueSize returns the size of the value in bytes or the length of a list value.
488 @return RegError::NO_ERROR if succeeds else an error code.
490 inline RegError getValueInfo(const OUString& keyName,
491 RegValueType* pValueType,
492 sal_uInt32* pValueSize);
494 /** gets the value of a key.
496 @param keyName specifies the name of the key which value will be returned.
497 If keyName is an empty string, the value is get from the key
498 specified by hKey.
499 @param pValue points to an allocated memory block receiving the data of the value.
500 @return RegError::NO_ERROR if succeeds else an error code.
502 inline RegError getValue(const OUString& keyName,
503 RegValue pValue);
505 /** gets a long list value of a key.
507 @param keyName specifies the name of the key which value will be returned.
508 If keyName is an empty string, the value is get from the key
509 specified by hKey.
510 @param rValueList references a RegistryValueList which will be filled with the long values.
511 @return RegError::NO_ERROR if succeeds else an error code.
513 inline RegError getLongListValue(const OUString& keyName,
514 RegistryValueList<sal_Int32>& rValueList);
516 /** gets an ascii list value of a key.
518 @param keyName specifies the name of the key which value will be returned.
519 If keyName is an empty string, the value is get from the key
520 specified by hKey.
521 @param rValueList references a RegistryValueList which will be filled with the ascii values.
522 @return RegError::NO_ERROR if succeeds else an error code.
524 inline RegError getStringListValue(const OUString& keyName,
525 RegistryValueList<char*>& rValueList);
527 /** gets a unicode value of a key.
529 @param keyName specifies the name of the key which value will be returned.
530 If keyName is an empty string, the value is get from the key
531 specified by hKey.
532 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
533 @return RegError::NO_ERROR if succeeds else an error code.
535 inline RegError getUnicodeListValue(const OUString& keyName,
536 RegistryValueList<sal_Unicode*>& rValueList);
538 /** resolves a keyname.
540 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
541 The resolved name will be prefixed with the name of this key.
542 @param[out] rResolvedName the resolved name.
543 @return RegError::NO_ERROR if succeeds else an error code.
545 inline RegError getResolvedKeyName(const OUString& keyName,
546 OUString& rResolvedName) const;
548 /// returns the name of the registry in which the key is defined.
549 inline OUString getRegistryName();
551 friend class Registry;
552 public:
553 /// @cond INTERNAL
555 /** Constructor, which initialize a RegistryKey with registry and a valid key handle.
557 This constructor is internal only.
559 inline RegistryKey(Registry const & registry,
560 RegKeyHandle hKey);
562 private:
563 /** sets the internal registry on which this key should work.
565 inline void setRegistry(Registry const & registry);
567 /// @endcond
569 /// stores the registry on which this key works
570 Registry m_registry;
571 /// stores the current key handle of this key
572 RegKeyHandle m_hImpl;
576 inline RegistryKeyArray::RegistryKeyArray()
577 : m_length(0)
578 , m_phKeys(nullptr)
582 inline RegistryKeyArray::~RegistryKeyArray()
584 if (m_phKeys)
585 m_registry.m_pApi->closeSubKeys(m_phKeys, m_length);
588 inline RegistryKey RegistryKeyArray::getElement(sal_uInt32 index)
590 if (m_registry.isValid() && index < m_length)
591 return RegistryKey(m_registry, m_phKeys[index]);
592 else
593 return RegistryKey();
596 inline sal_uInt32 RegistryKeyArray::getLength() const
598 return m_length;
601 inline void RegistryKeyArray::setKeyHandles(Registry const & registry,
602 RegKeyHandle* phKeys,
603 sal_uInt32 length)
605 m_phKeys = phKeys;
606 m_length = length;
607 m_registry = registry;
610 inline RegistryKeyNames::RegistryKeyNames()
611 : m_length(0)
612 , m_pKeyNames(nullptr)
616 inline RegistryKeyNames::~RegistryKeyNames()
618 if (m_pKeyNames)
619 m_registry.m_pApi->freeKeyNames(m_pKeyNames, m_length);
622 inline OUString RegistryKeyNames::getElement(sal_uInt32 index)
625 if (m_pKeyNames && index < m_length)
626 return m_pKeyNames[index];
627 else
628 return OUString();
631 inline sal_uInt32 RegistryKeyNames::getLength() const
633 return m_length;
636 inline void RegistryKeyNames::setKeyNames(Registry const & registry,
637 rtl_uString** pKeyNames,
638 sal_uInt32 length)
640 m_pKeyNames = pKeyNames;
641 m_length = length;
642 m_registry = registry;
645 inline RegistryKey::RegistryKey()
646 : m_hImpl(nullptr)
649 /// @cond INTERNAL
650 inline RegistryKey::RegistryKey(Registry const & registry, RegKeyHandle hKey)
651 : m_registry(registry)
652 , m_hImpl(hKey)
654 if (m_hImpl)
655 m_registry.m_pApi->acquireKey(m_hImpl);
657 /// @endcond
659 inline RegistryKey::RegistryKey(const RegistryKey& toCopy)
660 : m_registry(toCopy.m_registry)
661 , m_hImpl(toCopy.m_hImpl)
663 if (m_hImpl)
664 m_registry.m_pApi->acquireKey(m_hImpl);
667 /// @cond INTERNAL
668 inline void RegistryKey::setRegistry(Registry const & registry)
670 m_registry = registry;
672 /// @endcond
674 inline RegistryKey::~RegistryKey()
676 if (m_hImpl)
677 m_registry.m_pApi->releaseKey(m_hImpl);
680 inline RegistryKey& RegistryKey::operator = (const RegistryKey& toAssign)
682 m_registry = toAssign.m_registry;
684 if (toAssign.m_hImpl)
685 m_registry.m_pApi->acquireKey(toAssign.m_hImpl);
686 if (m_hImpl)
687 m_registry.m_pApi->releaseKey(m_hImpl);
688 m_hImpl = toAssign.m_hImpl;
690 return *this;
693 inline bool RegistryKey::isValid() const
694 { return (m_hImpl != nullptr); }
696 inline bool RegistryKey::isReadOnly() const
698 if (m_registry.isValid())
699 return m_registry.m_pApi->isKeyReadOnly(m_hImpl);
700 else
701 return false;
704 inline OUString RegistryKey::getName()
706 OUString sRet;
707 if (m_registry.isValid())
708 m_registry.m_pApi->getKeyName(m_hImpl, &sRet.pData);
709 return sRet;
712 inline RegError RegistryKey::createKey(const OUString& keyName,
713 RegistryKey& rNewKey)
715 if (rNewKey.isValid()) rNewKey.closeKey();
716 if (m_registry.isValid())
718 RegError ret = m_registry.m_pApi->createKey(m_hImpl, keyName.pData, &rNewKey.m_hImpl);
719 if (ret == RegError::NO_ERROR) rNewKey.setRegistry(m_registry);
720 return ret;
721 } else
722 return RegError::INVALID_KEY;
725 inline RegError RegistryKey::openKey(const OUString& keyName,
726 RegistryKey& rOpenKey)
728 if (rOpenKey.isValid()) rOpenKey.closeKey();
729 if (m_registry.isValid())
731 RegError ret = m_registry.m_pApi->openKey(m_hImpl, keyName.pData,
732 &rOpenKey.m_hImpl);
733 if (ret == RegError::NO_ERROR) rOpenKey.setRegistry(m_registry);
734 return ret;
735 } else
736 return RegError::INVALID_KEY;
739 inline RegError RegistryKey::openSubKeys(const OUString& keyName,
740 RegistryKeyArray& rSubKeys)
742 if (m_registry.isValid())
744 RegError ret = RegError::NO_ERROR;
745 RegKeyHandle* pSubKeys;
746 sal_uInt32 nSubKeys;
747 ret = m_registry.m_pApi->openSubKeys(m_hImpl, keyName.pData,
748 &pSubKeys, &nSubKeys);
749 if ( ret != RegError::NO_ERROR)
751 return ret;
752 } else
754 rSubKeys.setKeyHandles(m_registry, pSubKeys, nSubKeys);
755 return ret;
757 } else
758 return RegError::INVALID_KEY;
761 inline RegError RegistryKey::getKeyNames(const OUString& keyName,
762 RegistryKeyNames& rSubKeyNames)
764 if (m_registry.isValid())
766 RegError ret = RegError::NO_ERROR;
767 rtl_uString** pSubKeyNames;
768 sal_uInt32 nSubKeys;
769 ret = m_registry.m_pApi->getKeyNames(m_hImpl, keyName.pData,
770 &pSubKeyNames, &nSubKeys);
771 if ( ret != RegError::NO_ERROR)
773 return ret;
774 } else
776 rSubKeyNames.setKeyNames(m_registry, pSubKeyNames, nSubKeys);
777 return ret;
779 } else
780 return RegError::INVALID_KEY;
783 inline RegError RegistryKey::deleteKey(const OUString& keyName)
785 if (m_registry.isValid())
786 return m_registry.m_pApi->deleteKey(m_hImpl, keyName.pData);
787 else
788 return RegError::INVALID_KEY;
791 inline RegError RegistryKey::closeKey()
793 if (m_registry.isValid())
795 RegError ret = m_registry.m_pApi->closeKey(m_hImpl);
796 if (ret == RegError::NO_ERROR)
798 m_hImpl = nullptr;
799 m_registry = Registry();
801 return ret;
802 } else
803 return RegError::INVALID_KEY;
806 inline void RegistryKey::releaseKey()
808 if (m_registry.isValid() && (m_hImpl != nullptr))
810 m_registry.m_pApi->releaseKey(m_hImpl);
811 m_hImpl = nullptr;
815 inline RegError RegistryKey::setValue(const OUString& keyName,
816 RegValueType valueType,
817 RegValue pValue,
818 sal_uInt32 valueSize)
820 if (m_registry.isValid())
821 return m_registry.m_pApi->setValue(m_hImpl, keyName.pData, valueType,
822 pValue, valueSize);
823 else
824 return RegError::INVALID_KEY;
827 inline RegError RegistryKey::setLongListValue(const OUString& keyName,
828 sal_Int32 const * pValueList,
829 sal_uInt32 len)
831 if (m_registry.isValid())
832 return m_registry.m_pApi->setLongListValue(m_hImpl, keyName.pData,
833 pValueList, len);
834 else
835 return RegError::INVALID_KEY;
838 inline RegError RegistryKey::setStringListValue(const OUString& keyName,
839 char** pValueList,
840 sal_uInt32 len)
842 if (m_registry.isValid())
843 return m_registry.m_pApi->setStringListValue(m_hImpl, keyName.pData,
844 pValueList, len);
845 else
846 return RegError::INVALID_KEY;
849 inline RegError RegistryKey::setUnicodeListValue(const OUString& keyName,
850 sal_Unicode** pValueList,
851 sal_uInt32 len)
853 if (m_registry.isValid())
854 return m_registry.m_pApi->setUnicodeListValue(m_hImpl, keyName.pData,
855 pValueList, len);
856 else
857 return RegError::INVALID_KEY;
860 inline RegError RegistryKey::getValueInfo(const OUString& keyName,
861 RegValueType* pValueType,
862 sal_uInt32* pValueSize)
864 if (m_registry.isValid())
865 return m_registry.m_pApi->getValueInfo(m_hImpl, keyName.pData, pValueType, pValueSize);
866 else
867 return RegError::INVALID_KEY;
870 inline RegError RegistryKey::getValue(const OUString& keyName,
871 RegValue pValue)
873 if (m_registry.isValid())
874 return m_registry.m_pApi->getValue(m_hImpl, keyName.pData, pValue);
875 else
876 return RegError::INVALID_KEY;
879 inline RegError RegistryKey::getLongListValue(const OUString& keyName,
880 RegistryValueList<sal_Int32>& rValueList)
882 if (m_registry.isValid())
884 RegError ret = RegError::NO_ERROR;
885 sal_Int32* pValueList;
886 sal_uInt32 length;
887 ret = m_registry.m_pApi->getLongListValue(m_hImpl, keyName.pData,
888 &pValueList, &length);
889 if ( ret != RegError::NO_ERROR)
891 return ret;
892 } else
894 rValueList.setValueList(m_registry, RegValueType::LONGLIST,
895 pValueList, length);
896 return ret;
898 } else
899 return RegError::INVALID_KEY;
902 inline RegError RegistryKey::getStringListValue(const OUString& keyName,
903 RegistryValueList<char*>& rValueList)
905 if (m_registry.isValid())
907 RegError ret = RegError::NO_ERROR;
908 char** pValueList;
909 sal_uInt32 length;
910 ret = m_registry.m_pApi->getStringListValue(m_hImpl, keyName.pData,
911 &pValueList, &length);
912 if ( ret != RegError::NO_ERROR )
914 return ret;
915 } else
917 rValueList.setValueList(m_registry, RegValueType::STRINGLIST,
918 pValueList, length);
919 return ret;
921 } else
922 return RegError::INVALID_KEY;
925 inline RegError RegistryKey::getUnicodeListValue(const OUString& keyName,
926 RegistryValueList<sal_Unicode*>& rValueList)
928 if (m_registry.isValid())
930 RegError ret = RegError::NO_ERROR;
931 sal_Unicode** pValueList;
932 sal_uInt32 length;
933 ret = m_registry.m_pApi->getUnicodeListValue(m_hImpl, keyName.pData,
934 &pValueList, &length);
935 if ( ret != RegError::NO_ERROR )
937 return ret;
938 } else
940 rValueList.setValueList(m_registry, RegValueType::UNICODELIST,
941 pValueList, length);
942 return ret;
944 } else
945 return RegError::INVALID_KEY;
948 inline RegError RegistryKey::getResolvedKeyName(const OUString& keyName,
949 OUString& rResolvedName) const
951 if (m_registry.isValid())
952 return m_registry.m_pApi->getResolvedKeyName(m_hImpl,
953 keyName.pData,
954 true,
955 &rResolvedName.pData);
956 else
957 return RegError::INVALID_KEY;
960 inline OUString RegistryKey::getRegistryName()
962 if (m_registry.isValid())
964 return m_registry.getName();
965 } else
966 return OUString();
970 inline Registry::Registry()
971 : m_pApi(initRegistry_Api())
972 , m_hImpl(nullptr)
975 inline Registry::Registry(const Registry& toCopy)
976 : m_pApi(toCopy.m_pApi)
977 , m_hImpl(toCopy.m_hImpl)
979 if (m_hImpl)
980 m_pApi->acquire(m_hImpl);
984 inline Registry::~Registry()
986 if (m_hImpl)
987 m_pApi->release(m_hImpl);
990 inline Registry& Registry::operator = (const Registry& toAssign)
992 if (toAssign.m_hImpl)
993 toAssign.m_pApi->acquire(toAssign.m_hImpl);
994 if (m_hImpl)
995 m_pApi->release(m_hImpl);
997 m_pApi = toAssign.m_pApi;
998 m_hImpl = toAssign.m_hImpl;
1000 return *this;
1003 inline bool Registry::isValid() const
1004 { return ( m_hImpl != nullptr ); }
1006 inline bool Registry::isReadOnly() const
1007 { return m_pApi->isReadOnly(m_hImpl); }
1009 inline RegError Registry::openRootKey(RegistryKey& rRootKey)
1011 rRootKey.setRegistry(*this);
1012 return m_pApi->openRootKey(m_hImpl, &rRootKey.m_hImpl);
1015 inline OUString Registry::getName()
1017 OUString sRet;
1018 m_pApi->getName(m_hImpl, &sRet.pData);
1019 return sRet;
1022 inline RegError Registry::create(const OUString& registryName)
1024 if (m_hImpl)
1025 m_pApi->release(m_hImpl);
1026 return m_pApi->createRegistry(registryName.pData, &m_hImpl);
1029 inline RegError Registry::open(const OUString& registryName,
1030 RegAccessMode accessMode)
1032 if (m_hImpl)
1033 m_pApi->release(m_hImpl);
1034 return m_pApi->openRegistry(registryName.pData, &m_hImpl, accessMode);
1037 inline RegError Registry::close()
1039 RegError ret = m_pApi->closeRegistry(m_hImpl);
1040 if (ret == RegError::NO_ERROR)
1041 m_hImpl = nullptr;
1042 return ret;
1045 inline RegError Registry::destroy(const OUString& registryName)
1047 RegError ret = m_pApi->destroyRegistry(m_hImpl, registryName.pData);
1048 if ( ret == RegError::NO_ERROR && registryName.isEmpty() )
1049 m_hImpl = nullptr;
1050 return ret;
1053 inline RegError Registry::mergeKey(RegistryKey& rKey,
1054 const OUString& keyName,
1055 const OUString& regFileName,
1056 bool bReport)
1057 { return m_pApi->mergeKey(m_hImpl, rKey.m_hImpl, keyName.pData, regFileName.pData, false/*bWarnings*/, bReport); }
1059 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */