1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <registry/regdllapi.h>
23 #include <registry/regtype.h>
24 #include <rtl/ustring.hxx>
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.
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 void (REGISTRY_CALLTYPE
*acquireKey
) (RegKeyHandle
);
44 void (REGISTRY_CALLTYPE
*releaseKey
) (RegKeyHandle
);
45 sal_Bool (REGISTRY_CALLTYPE
*isKeyReadOnly
) (RegKeyHandle
);
46 RegError (REGISTRY_CALLTYPE
*getKeyName
) (RegKeyHandle
, rtl_uString
**);
47 RegError (REGISTRY_CALLTYPE
*createKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
48 RegError (REGISTRY_CALLTYPE
*openKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
49 RegError (REGISTRY_CALLTYPE
*openSubKeys
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
**, sal_uInt32
*);
50 RegError (REGISTRY_CALLTYPE
*closeSubKeys
) (RegKeyHandle
*, sal_uInt32
);
51 RegError (REGISTRY_CALLTYPE
*deleteKey
) (RegKeyHandle
, rtl_uString
*);
52 RegError (REGISTRY_CALLTYPE
*closeKey
) (RegKeyHandle
);
53 RegError (REGISTRY_CALLTYPE
*setValue
) (RegKeyHandle
, rtl_uString
*, RegValueType
, RegValue
, sal_uInt32
);
54 RegError (REGISTRY_CALLTYPE
*setLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
const *, sal_uInt32
);
55 RegError (REGISTRY_CALLTYPE
*setStringListValue
) (RegKeyHandle
, rtl_uString
*, char**, sal_uInt32
);
56 RegError (REGISTRY_CALLTYPE
*setUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
**, sal_uInt32
);
57 RegError (REGISTRY_CALLTYPE
*getValueInfo
) (RegKeyHandle
, rtl_uString
*, RegValueType
*, sal_uInt32
*);
58 RegError (REGISTRY_CALLTYPE
*getValue
) (RegKeyHandle
, rtl_uString
*, RegValue
);
59 RegError (REGISTRY_CALLTYPE
*getLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
**, sal_uInt32
*);
60 RegError (REGISTRY_CALLTYPE
*getStringListValue
) (RegKeyHandle
, rtl_uString
*, char***, sal_uInt32
*);
61 RegError (REGISTRY_CALLTYPE
*getUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
***, sal_uInt32
*);
62 RegError (REGISTRY_CALLTYPE
*freeValueList
) (RegValueType
, RegValue
, sal_uInt32
);
63 RegError (REGISTRY_CALLTYPE
*getResolvedKeyName
) (RegKeyHandle
, rtl_uString
*, sal_Bool
, rtl_uString
**);
64 RegError (REGISTRY_CALLTYPE
*getKeyNames
) (RegKeyHandle
, rtl_uString
*, rtl_uString
***, sal_uInt32
*);
65 RegError (REGISTRY_CALLTYPE
*freeKeyNames
) (rtl_uString
**, sal_uInt32
);
68 /** the API initialization function.
70 REG_DLLPUBLIC Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api();
77 /** The Registry provides the functionality to read and write information in a registry file.
79 The class is implemented inline and use a C-Api.
84 /** Default constructor.
89 inline Registry(const Registry
& toCopy
);
91 Registry(Registry
&& other
) noexcept
: m_pApi(other
.m_pApi
), m_hImpl(other
.m_hImpl
)
92 { other
.m_hImpl
= nullptr; }
94 /// Destructor. The Destructor close the registry if it is open.
98 inline Registry
& operator = (const Registry
& toAssign
);
100 Registry
& operator =(Registry
&& other
) {
101 if (m_hImpl
!= nullptr) {
102 m_pApi
->release(m_hImpl
);
104 m_hImpl
= other
.m_hImpl
;
105 other
.m_hImpl
= nullptr;
109 /// checks if the registry points to a valid registry data file.
110 inline bool isValid() const;
112 /** returns the access mode of the registry.
114 @return TRUE if the access mode is readonly else FALSE.
116 inline bool isReadOnly() const;
118 /** opens the root key of the registry.
120 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
121 @return RegError::NO_ERROR if succeeds else an error code.
123 inline RegError
openRootKey(RegistryKey
& rRootKey
);
125 /// returns the name of the current registry data file.
126 inline OUString
getName();
128 /** creates a new registry with the specified name and creates a root key.
130 @param registryName specifies the name of the new registry.
131 @return RegError::NO_ERROR if succeeds else an error code.
133 inline RegError
create(const OUString
& registryName
);
135 /** opens a registry with the specified name.
137 If the registry already points to a valid registry, the old registry will be closed.
138 @param registryName specifies a registry name.
139 @param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
140 @return RegError::NO_ERROR if succeeds else an error code.
142 inline RegError
open(const OUString
& registryName
,
143 RegAccessMode accessMode
);
145 /// closes explicitly the current registry data file.
146 inline RegError
close();
148 /** destroys a registry.
150 @param registryName specifies a registry name, if the name is an empty string the registry
151 itself will be destroyed.
152 @return RegError::NO_ERROR if succeeds else an error code.
154 inline RegError
destroy(const OUString
& registryName
);
156 friend class RegistryKey
;
157 friend class RegistryKeyArray
;
158 friend class RegistryKeyNames
;
160 /// returns the used registry Api.
161 const Registry_Api
* getApi() const { return m_pApi
; }
164 /// stores the used and initialized registry Api.
165 const Registry_Api
* m_pApi
;
166 /// stores the handle of the underlying registry file on which most of the functions work.
171 /** RegistryKeyArray represents an array of open keys.
173 RegistryKeyArray is a helper class to work with an array of keys.
175 class RegistryKeyArray
178 /// Default constructor
179 inline RegistryKeyArray();
181 /// Destructor, all subkeys will be closed.
182 inline ~RegistryKeyArray();
184 /// returns the open key specified by index.
185 inline RegistryKey
getElement(sal_uInt32 index
);
187 /// returns the length of the array.
188 inline sal_uInt32
getLength() const;
190 friend class RegistryKey
;
193 /** sets the data of the key array.
195 @param registry specifies the registry files where the keys are located.
196 @param phKeys points to an array of open keys.
197 @param length specifies the length of the array specified by phKeys.
199 inline void setKeyHandles(Registry
const & registry
, RegKeyHandle
* phKeys
, sal_uInt32 length
);
201 /// stores the number of open subkeys, the number of elements.
203 /// stores an array of open subkeys.
204 RegKeyHandle
* m_phKeys
;
205 /// stores the handle to the registry file where the appropriate keys are located.
210 /** RegistryKeyNames represents an array of key names.
212 RegistryKeyNames is a helper class to work with an array of key names.
214 class RegistryKeyNames
217 /// Default constructor
218 inline RegistryKeyNames();
220 /// Destructor, the internal array with key names will be deleted.
221 inline ~RegistryKeyNames();
223 /// returns the name of the key specified by index.
224 inline OUString
getElement(sal_uInt32 index
);
226 /// returns the length of the array.
227 inline sal_uInt32
getLength() const;
229 friend class RegistryKey
;
232 /** sets the data of the array.
234 @param registry specifies the registry files where the keys are located.
235 @param pKeyNames points to an array of key names.
236 @param length specifies the length of the array specified by pKeyNames.
238 inline void setKeyNames(Registry
const & registry
, rtl_uString
** pKeyNames
, sal_uInt32 length
);
240 /// stores the number of key names, the number of elements.
242 /// stores an array of key names.
243 rtl_uString
** m_pKeyNames
;
244 /// stores the handle to the registry file where the appropriate keys are located.
249 /** RegistryValueList represents a value list of the specified type.
251 RegistryValueList is a helper class to work with a list value.
253 template<class ValueType
>
254 class RegistryValueList final
257 /// Default constructor
260 , m_pValueList(nullptr)
261 , m_valueType(RegValueType::NOT_DEFINED
)
264 /// Destructor, the internal value list will be freed.
269 m_registry
.getApi()->freeValueList(m_valueType
, m_pValueList
, m_length
);
273 /// returns the value of the list specified by index.
274 ValueType
getElement(sal_uInt32 index
)
276 if (m_registry
.isValid() && index
< m_length
)
278 return m_pValueList
[index
];
285 /// returns the length of the list.
286 sal_uInt32
getLength()
291 friend class RegistryKey
;
294 /** sets the data of the value list.
296 @param registry specifies the registry files where the appropriate key is located.
297 @param valueType specifies the type of the list values.
298 @param pValueList points to a value list.
299 @param length specifies the length of the list.
301 void setValueList(const Registry
& registry
, RegValueType valueType
,
302 ValueType
* pValueList
, sal_uInt32 length
)
305 m_pValueList
= pValueList
;
306 m_valueType
= valueType
;
307 m_registry
= registry
;
310 /// stores the length of the list, the number of elements.
312 /// stores the value list.
313 ValueType
* m_pValueList
;
314 /// stores the type of the list elements
315 RegValueType m_valueType
;
316 /** stores the handle to the registry file where the appropriate key to this
323 /** RegistryKey reads or writes information of the underlying key in a registry.
325 Class is inline and use a load on call C-Api.
330 /// Default constructor
331 inline RegistryKey();
334 inline RegistryKey(const RegistryKey
& toCopy
);
336 /// Destructor, close the key if it references an open one.
337 inline ~RegistryKey();
340 inline RegistryKey
& operator = (const RegistryKey
& toAssign
);
342 /// checks if the key points to a valid registry key.
343 inline bool isValid() const;
345 /** returns the access mode of the key.
347 @return TRUE if access mode is read only else FALSE.
349 inline bool isReadOnly() const;
351 /// returns the full qualified name of the key beginning with the rootkey.
352 inline OUString
getName();
354 /** creates a new key or opens a key if the specified key already exists.
356 The specified keyname is relative to this key.
357 @param keyName specifies the name of the key which will be opened or created.
358 @param rNewKey references a RegistryKey which will be filled with the new or open key.
359 @return RegError::NO_ERROR if succeeds else an error code.
361 inline RegError
createKey(const OUString
& keyName
,
362 RegistryKey
& rNewKey
);
364 /** opens the specified key.
366 The specified keyname is relative to this key.
367 @param keyName specifies the name of the key which will be opened.
368 @param rOpenKey references a RegistryKey which will be filled with the open key.
369 @return RegError::NO_ERROR if succeeds else an error code.
371 inline RegError
openKey(const OUString
& keyName
,
372 RegistryKey
& rOpenKey
);
374 /** opens all subkeys of the specified key.
376 The specified keyname is relative to this key.
377 @param keyName specifies the name of the key which subkeys will be opened.
378 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
379 @return RegError::NO_ERROR if succeeds else an error code.
381 inline RegError
openSubKeys(const OUString
& keyName
,
382 RegistryKeyArray
& rSubKeys
);
384 /** returns an array with the names of all subkeys of the specified key.
386 The specified keyname is relative to this key.
387 @param keyName specifies the name of the key which subkey names will be returned.
388 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
389 @return RegError::NO_ERROR if succeeds else an error code.
391 inline RegError
getKeyNames(const OUString
& keyName
,
392 RegistryKeyNames
& rSubKeyNames
);
394 /** deletes the specified key.
396 @param keyName specifies the name of the key which will be deleted.
397 @return RegError::NO_ERROR if succeeds else an error code.
399 inline RegError
deleteKey(const OUString
& keyName
);
401 /// closes explicitly the current key
402 inline RegError
closeKey();
404 /** sets a value of a key.
406 @param keyName specifies the name of the key which value will be set.
407 If keyName is an empty string, the value will be set for the key
409 @param valueType specifies the type of the value.
410 @param pValue points to a memory block containing the data for the value.
411 @param valueSize specifies the size of pData in bytes
412 @return RegError::NO_ERROR if succeeds else an error code.
414 inline RegError
setValue(const OUString
& keyName
,
415 RegValueType valueType
,
417 sal_uInt32 valueSize
);
419 /** sets a long list value of a key.
421 @param keyName specifies the name of the key which value will be set.
422 If keyName is an empty string, the value will be set for the key
424 @param pValueList points to an array of longs containing the data for the value.
425 @param len specifies the length of the list (the array referenced by pValueList).
426 @return RegError::NO_ERROR if succeeds else an error code.
428 inline RegError
setLongListValue(const OUString
& keyName
,
429 sal_Int32
const * pValueList
,
432 /** sets an ascii list value of a key.
434 @param keyName specifies the name of the key which value will be set.
435 If keyName is an empty string, the value will be set for the key
437 @param pValueList points to an array of char* containing the data for the value.
438 @param len specifies the length of the list (the array referenced by pValueList).
439 @return RegError::NO_ERROR if succeeds else an error code.
441 inline RegError
setStringListValue(const OUString
& keyName
,
445 /** sets a unicode string list value of a key.
447 @param keyName specifies the name of the key which value will be set.
448 If keyName is an empty string, the value will be set for the key
450 @param pValueList points to an array of sal_Unicode* containing the data for the value.
451 @param len specifies the length of the list (the array referenced by pValueList).
452 @return RegError::NO_ERROR if succeeds else an error code.
454 inline RegError
setUnicodeListValue(const OUString
& keyName
,
455 sal_Unicode
** pValueList
,
458 /** gets info about type and size of a value.
460 @param keyName specifies the name of the key which value info will be returned.
461 If keyName is an empty string, the value info of the key
462 specified by hKey will be returned.
463 @param pValueType returns the type of the value.
464 @param pValueSize returns the size of the value in bytes or the length of a list value.
465 @return RegError::NO_ERROR if succeeds else an error code.
467 inline RegError
getValueInfo(const OUString
& keyName
,
468 RegValueType
* pValueType
,
469 sal_uInt32
* pValueSize
);
471 /** gets the value of a key.
473 @param keyName specifies the name of the key which value will be returned.
474 If keyName is an empty string, the value is get from the key
476 @param pValue points to an allocated memory block receiving the data of the value.
477 @return RegError::NO_ERROR if succeeds else an error code.
479 inline RegError
getValue(const OUString
& keyName
,
482 /** gets a long list value of a key.
484 @param keyName specifies the name of the key which value will be returned.
485 If keyName is an empty string, the value is get from the key
487 @param rValueList references a RegistryValueList which will be filled with the long values.
488 @return RegError::NO_ERROR if succeeds else an error code.
490 inline RegError
getLongListValue(const OUString
& keyName
,
491 RegistryValueList
<sal_Int32
>& rValueList
);
493 /** gets an ascii list value of a key.
495 @param keyName specifies the name of the key which value will be returned.
496 If keyName is an empty string, the value is get from the key
498 @param rValueList references a RegistryValueList which will be filled with the ascii values.
499 @return RegError::NO_ERROR if succeeds else an error code.
501 inline RegError
getStringListValue(const OUString
& keyName
,
502 RegistryValueList
<char*>& rValueList
);
504 /** gets a unicode value of a key.
506 @param keyName specifies the name of the key which value will be returned.
507 If keyName is an empty string, the value is get from the key
509 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
510 @return RegError::NO_ERROR if succeeds else an error code.
512 inline RegError
getUnicodeListValue(const OUString
& keyName
,
513 RegistryValueList
<sal_Unicode
*>& rValueList
);
515 /** resolves a keyname.
517 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
518 The resolved name will be prefixed with the name of this key.
519 @param[out] rResolvedName the resolved name.
520 @return RegError::NO_ERROR if succeeds else an error code.
522 inline RegError
getResolvedKeyName(const OUString
& keyName
,
523 OUString
& rResolvedName
) const;
525 /// returns the name of the registry in which the key is defined.
526 inline OUString
getRegistryName();
528 friend class Registry
;
532 /** Constructor, which initialize a RegistryKey with registry and a valid key handle.
534 This constructor is internal only.
536 inline RegistryKey(Registry
const & registry
,
540 /** sets the internal registry on which this key should work.
542 inline void setRegistry(Registry
const & registry
);
546 /// stores the registry on which this key works
548 /// stores the current key handle of this key
549 RegKeyHandle m_hImpl
;
553 inline RegistryKeyArray::RegistryKeyArray()
559 inline RegistryKeyArray::~RegistryKeyArray()
562 m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
565 inline RegistryKey
RegistryKeyArray::getElement(sal_uInt32 index
)
567 if (m_registry
.isValid() && index
< m_length
)
568 return RegistryKey(m_registry
, m_phKeys
[index
]);
570 return RegistryKey();
573 inline sal_uInt32
RegistryKeyArray::getLength() const
578 inline void RegistryKeyArray::setKeyHandles(Registry
const & registry
,
579 RegKeyHandle
* phKeys
,
584 m_registry
= registry
;
587 inline RegistryKeyNames::RegistryKeyNames()
589 , m_pKeyNames(nullptr)
593 inline RegistryKeyNames::~RegistryKeyNames()
596 m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
599 inline OUString
RegistryKeyNames::getElement(sal_uInt32 index
)
602 if (m_pKeyNames
&& index
< m_length
)
603 return m_pKeyNames
[index
];
608 inline sal_uInt32
RegistryKeyNames::getLength() const
613 inline void RegistryKeyNames::setKeyNames(Registry
const & registry
,
614 rtl_uString
** pKeyNames
,
617 m_pKeyNames
= pKeyNames
;
619 m_registry
= registry
;
622 inline RegistryKey::RegistryKey()
627 inline RegistryKey::RegistryKey(Registry
const & registry
, RegKeyHandle hKey
)
628 : m_registry(registry
)
632 m_registry
.m_pApi
->acquireKey(m_hImpl
);
636 inline RegistryKey::RegistryKey(const RegistryKey
& toCopy
)
637 : m_registry(toCopy
.m_registry
)
638 , m_hImpl(toCopy
.m_hImpl
)
641 m_registry
.m_pApi
->acquireKey(m_hImpl
);
645 inline void RegistryKey::setRegistry(Registry
const & registry
)
647 m_registry
= registry
;
651 inline RegistryKey::~RegistryKey()
654 m_registry
.m_pApi
->releaseKey(m_hImpl
);
657 inline RegistryKey
& RegistryKey::operator = (const RegistryKey
& toAssign
)
659 m_registry
= toAssign
.m_registry
;
661 if (toAssign
.m_hImpl
)
662 m_registry
.m_pApi
->acquireKey(toAssign
.m_hImpl
);
664 m_registry
.m_pApi
->releaseKey(m_hImpl
);
665 m_hImpl
= toAssign
.m_hImpl
;
670 inline bool RegistryKey::isValid() const
671 { return (m_hImpl
!= nullptr); }
673 inline bool RegistryKey::isReadOnly() const
675 if (m_registry
.isValid())
676 return m_registry
.m_pApi
->isKeyReadOnly(m_hImpl
);
681 inline OUString
RegistryKey::getName()
684 if (m_registry
.isValid())
685 m_registry
.m_pApi
->getKeyName(m_hImpl
, &sRet
.pData
);
689 inline RegError
RegistryKey::createKey(const OUString
& keyName
,
690 RegistryKey
& rNewKey
)
692 if (rNewKey
.isValid()) rNewKey
.closeKey();
693 if (m_registry
.isValid())
695 RegError ret
= m_registry
.m_pApi
->createKey(m_hImpl
, keyName
.pData
, &rNewKey
.m_hImpl
);
696 if (ret
== RegError::NO_ERROR
) rNewKey
.setRegistry(m_registry
);
699 return RegError::INVALID_KEY
;
702 inline RegError
RegistryKey::openKey(const OUString
& keyName
,
703 RegistryKey
& rOpenKey
)
705 if (rOpenKey
.isValid()) rOpenKey
.closeKey();
706 if (m_registry
.isValid())
708 RegError ret
= m_registry
.m_pApi
->openKey(m_hImpl
, keyName
.pData
,
710 if (ret
== RegError::NO_ERROR
) rOpenKey
.setRegistry(m_registry
);
713 return RegError::INVALID_KEY
;
716 inline RegError
RegistryKey::openSubKeys(const OUString
& keyName
,
717 RegistryKeyArray
& rSubKeys
)
719 if (m_registry
.isValid())
721 RegError ret
= RegError::NO_ERROR
;
722 RegKeyHandle
* pSubKeys
;
724 ret
= m_registry
.m_pApi
->openSubKeys(m_hImpl
, keyName
.pData
,
725 &pSubKeys
, &nSubKeys
);
726 if ( ret
!= RegError::NO_ERROR
)
731 rSubKeys
.setKeyHandles(m_registry
, pSubKeys
, nSubKeys
);
735 return RegError::INVALID_KEY
;
738 inline RegError
RegistryKey::getKeyNames(const OUString
& keyName
,
739 RegistryKeyNames
& rSubKeyNames
)
741 if (m_registry
.isValid())
743 RegError ret
= RegError::NO_ERROR
;
744 rtl_uString
** pSubKeyNames
;
746 ret
= m_registry
.m_pApi
->getKeyNames(m_hImpl
, keyName
.pData
,
747 &pSubKeyNames
, &nSubKeys
);
748 if ( ret
!= RegError::NO_ERROR
)
753 rSubKeyNames
.setKeyNames(m_registry
, pSubKeyNames
, nSubKeys
);
757 return RegError::INVALID_KEY
;
760 inline RegError
RegistryKey::deleteKey(const OUString
& keyName
)
762 if (m_registry
.isValid())
763 return m_registry
.m_pApi
->deleteKey(m_hImpl
, keyName
.pData
);
765 return RegError::INVALID_KEY
;
768 inline RegError
RegistryKey::closeKey()
770 if (m_registry
.isValid())
772 RegError ret
= m_registry
.m_pApi
->closeKey(m_hImpl
);
773 if (ret
== RegError::NO_ERROR
)
776 m_registry
= Registry();
780 return RegError::INVALID_KEY
;
783 inline RegError
RegistryKey::setValue(const OUString
& keyName
,
784 RegValueType valueType
,
786 sal_uInt32 valueSize
)
788 if (m_registry
.isValid())
789 return m_registry
.m_pApi
->setValue(m_hImpl
, keyName
.pData
, valueType
,
792 return RegError::INVALID_KEY
;
795 inline RegError
RegistryKey::setLongListValue(const OUString
& keyName
,
796 sal_Int32
const * pValueList
,
799 if (m_registry
.isValid())
800 return m_registry
.m_pApi
->setLongListValue(m_hImpl
, keyName
.pData
,
803 return RegError::INVALID_KEY
;
806 inline RegError
RegistryKey::setStringListValue(const OUString
& keyName
,
810 if (m_registry
.isValid())
811 return m_registry
.m_pApi
->setStringListValue(m_hImpl
, keyName
.pData
,
814 return RegError::INVALID_KEY
;
817 inline RegError
RegistryKey::setUnicodeListValue(const OUString
& keyName
,
818 sal_Unicode
** pValueList
,
821 if (m_registry
.isValid())
822 return m_registry
.m_pApi
->setUnicodeListValue(m_hImpl
, keyName
.pData
,
825 return RegError::INVALID_KEY
;
828 inline RegError
RegistryKey::getValueInfo(const OUString
& keyName
,
829 RegValueType
* pValueType
,
830 sal_uInt32
* pValueSize
)
832 if (m_registry
.isValid())
833 return m_registry
.m_pApi
->getValueInfo(m_hImpl
, keyName
.pData
, pValueType
, pValueSize
);
835 return RegError::INVALID_KEY
;
838 inline RegError
RegistryKey::getValue(const OUString
& keyName
,
841 if (m_registry
.isValid())
842 return m_registry
.m_pApi
->getValue(m_hImpl
, keyName
.pData
, pValue
);
844 return RegError::INVALID_KEY
;
847 inline RegError
RegistryKey::getLongListValue(const OUString
& keyName
,
848 RegistryValueList
<sal_Int32
>& rValueList
)
850 if (m_registry
.isValid())
852 RegError ret
= RegError::NO_ERROR
;
853 sal_Int32
* pValueList
;
855 ret
= m_registry
.m_pApi
->getLongListValue(m_hImpl
, keyName
.pData
,
856 &pValueList
, &length
);
857 if ( ret
!= RegError::NO_ERROR
)
862 rValueList
.setValueList(m_registry
, RegValueType::LONGLIST
,
867 return RegError::INVALID_KEY
;
870 inline RegError
RegistryKey::getStringListValue(const OUString
& keyName
,
871 RegistryValueList
<char*>& rValueList
)
873 if (m_registry
.isValid())
875 RegError ret
= RegError::NO_ERROR
;
878 ret
= m_registry
.m_pApi
->getStringListValue(m_hImpl
, keyName
.pData
,
879 &pValueList
, &length
);
880 if ( ret
!= RegError::NO_ERROR
)
885 rValueList
.setValueList(m_registry
, RegValueType::STRINGLIST
,
890 return RegError::INVALID_KEY
;
893 inline RegError
RegistryKey::getUnicodeListValue(const OUString
& keyName
,
894 RegistryValueList
<sal_Unicode
*>& rValueList
)
896 if (m_registry
.isValid())
898 RegError ret
= RegError::NO_ERROR
;
899 sal_Unicode
** pValueList
;
901 ret
= m_registry
.m_pApi
->getUnicodeListValue(m_hImpl
, keyName
.pData
,
902 &pValueList
, &length
);
903 if ( ret
!= RegError::NO_ERROR
)
908 rValueList
.setValueList(m_registry
, RegValueType::UNICODELIST
,
913 return RegError::INVALID_KEY
;
916 inline RegError
RegistryKey::getResolvedKeyName(const OUString
& keyName
,
917 OUString
& rResolvedName
) const
919 if (m_registry
.isValid())
920 return m_registry
.m_pApi
->getResolvedKeyName(m_hImpl
,
923 &rResolvedName
.pData
);
925 return RegError::INVALID_KEY
;
928 inline OUString
RegistryKey::getRegistryName()
930 if (m_registry
.isValid())
932 return m_registry
.getName();
938 inline Registry::Registry()
939 : m_pApi(initRegistry_Api())
943 inline Registry::Registry(const Registry
& toCopy
)
944 : m_pApi(toCopy
.m_pApi
)
945 , m_hImpl(toCopy
.m_hImpl
)
948 m_pApi
->acquire(m_hImpl
);
952 inline Registry::~Registry()
955 m_pApi
->release(m_hImpl
);
958 inline Registry
& Registry::operator = (const Registry
& toAssign
)
960 if (toAssign
.m_hImpl
)
961 toAssign
.m_pApi
->acquire(toAssign
.m_hImpl
);
963 m_pApi
->release(m_hImpl
);
965 m_pApi
= toAssign
.m_pApi
;
966 m_hImpl
= toAssign
.m_hImpl
;
971 inline bool Registry::isValid() const
972 { return ( m_hImpl
!= nullptr ); }
974 inline bool Registry::isReadOnly() const
975 { return m_pApi
->isReadOnly(m_hImpl
); }
977 inline RegError
Registry::openRootKey(RegistryKey
& rRootKey
)
979 rRootKey
.setRegistry(*this);
980 return m_pApi
->openRootKey(m_hImpl
, &rRootKey
.m_hImpl
);
983 inline OUString
Registry::getName()
986 m_pApi
->getName(m_hImpl
, &sRet
.pData
);
990 inline RegError
Registry::create(const OUString
& registryName
)
993 m_pApi
->release(m_hImpl
);
994 return m_pApi
->createRegistry(registryName
.pData
, &m_hImpl
);
997 inline RegError
Registry::open(const OUString
& registryName
,
998 RegAccessMode accessMode
)
1001 m_pApi
->release(m_hImpl
);
1002 return m_pApi
->openRegistry(registryName
.pData
, &m_hImpl
, accessMode
);
1005 inline RegError
Registry::close()
1007 RegError ret
= m_pApi
->closeRegistry(m_hImpl
);
1008 if (ret
== RegError::NO_ERROR
)
1013 inline RegError
Registry::destroy(const OUString
& registryName
)
1015 RegError ret
= m_pApi
->destroyRegistry(m_hImpl
, registryName
.pData
);
1016 if ( ret
== RegError::NO_ERROR
&& registryName
.isEmpty() )
1021 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */