tdf#48459 sw inline heading: don't apply inside frames or over 120 chars
[LibreOffice.git] / include / registry / registry.hxx
blob57b7895cf97923df500bbf771b523c533f902036
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 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();
74 class RegistryKey;
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.
81 class Registry final
83 public:
84 /** Default constructor.
86 inline Registry();
88 /// Copy 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.
95 inline ~Registry();
97 /// Assign operator
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;
106 return *this;
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; }
163 private:
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.
167 RegHandle m_hImpl;
171 /** RegistryKeyArray represents an array of open keys.
173 RegistryKeyArray is a helper class to work with an array of keys.
175 class RegistryKeyArray
177 public:
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;
192 private:
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.
202 sal_uInt32 m_length;
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.
206 Registry m_registry;
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
216 public:
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;
231 private:
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.
241 sal_uInt32 m_length;
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.
245 Registry m_registry;
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
256 public:
257 /// Default constructor
258 RegistryValueList()
259 : m_length(0)
260 , m_pValueList(nullptr)
261 , m_valueType(RegValueType::NOT_DEFINED)
264 /// Destructor, the internal value list will be freed.
265 ~RegistryValueList()
267 if (m_pValueList)
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];
279 } else
281 return {};
285 /// returns the length of the list.
286 sal_uInt32 getLength()
288 return m_length;
291 friend class RegistryKey;
293 private:
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)
304 m_length = length;
305 m_pValueList = pValueList;
306 m_valueType = valueType;
307 m_registry = registry;
310 /// stores the length of the list, the number of elements.
311 sal_uInt32 m_length;
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
317 value is located.
319 Registry m_registry;
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.
327 class RegistryKey
329 public:
330 /// Default constructor
331 inline RegistryKey();
333 /// Copy constructor
334 inline RegistryKey(const RegistryKey& toCopy);
336 /// Destructor, close the key if it references an open one.
337 inline ~RegistryKey();
339 /// Assign operator
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
408 specified by hKey.
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,
416 RegValue pValue,
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
423 specified by hKey.
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,
430 sal_uInt32 len);
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
436 specified by hKey.
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,
442 char** pValueList,
443 sal_uInt32 len);
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
449 specified by hKey.
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,
456 sal_uInt32 len);
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
475 specified by hKey.
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,
480 RegValue pValue);
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
486 specified by hKey.
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
497 specified by hKey.
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
508 specified by hKey.
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;
529 public:
530 /// @cond INTERNAL
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,
537 RegKeyHandle hKey);
539 private:
540 /** sets the internal registry on which this key should work.
542 inline void setRegistry(Registry const & registry);
544 /// @endcond
546 /// stores the registry on which this key works
547 Registry m_registry;
548 /// stores the current key handle of this key
549 RegKeyHandle m_hImpl;
553 inline RegistryKeyArray::RegistryKeyArray()
554 : m_length(0)
555 , m_phKeys(nullptr)
559 inline RegistryKeyArray::~RegistryKeyArray()
561 if (m_phKeys)
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]);
569 else
570 return RegistryKey();
573 inline sal_uInt32 RegistryKeyArray::getLength() const
575 return m_length;
578 inline void RegistryKeyArray::setKeyHandles(Registry const & registry,
579 RegKeyHandle* phKeys,
580 sal_uInt32 length)
582 m_phKeys = phKeys;
583 m_length = length;
584 m_registry = registry;
587 inline RegistryKeyNames::RegistryKeyNames()
588 : m_length(0)
589 , m_pKeyNames(nullptr)
593 inline RegistryKeyNames::~RegistryKeyNames()
595 if (m_pKeyNames)
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];
604 else
605 return OUString();
608 inline sal_uInt32 RegistryKeyNames::getLength() const
610 return m_length;
613 inline void RegistryKeyNames::setKeyNames(Registry const & registry,
614 rtl_uString** pKeyNames,
615 sal_uInt32 length)
617 m_pKeyNames = pKeyNames;
618 m_length = length;
619 m_registry = registry;
622 inline RegistryKey::RegistryKey()
623 : m_hImpl(nullptr)
626 /// @cond INTERNAL
627 inline RegistryKey::RegistryKey(Registry const & registry, RegKeyHandle hKey)
628 : m_registry(registry)
629 , m_hImpl(hKey)
631 if (m_hImpl)
632 m_registry.m_pApi->acquireKey(m_hImpl);
634 /// @endcond
636 inline RegistryKey::RegistryKey(const RegistryKey& toCopy)
637 : m_registry(toCopy.m_registry)
638 , m_hImpl(toCopy.m_hImpl)
640 if (m_hImpl)
641 m_registry.m_pApi->acquireKey(m_hImpl);
644 /// @cond INTERNAL
645 inline void RegistryKey::setRegistry(Registry const & registry)
647 m_registry = registry;
649 /// @endcond
651 inline RegistryKey::~RegistryKey()
653 if (m_hImpl)
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);
663 if (m_hImpl)
664 m_registry.m_pApi->releaseKey(m_hImpl);
665 m_hImpl = toAssign.m_hImpl;
667 return *this;
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);
677 else
678 return false;
681 inline OUString RegistryKey::getName()
683 OUString sRet;
684 if (m_registry.isValid())
685 m_registry.m_pApi->getKeyName(m_hImpl, &sRet.pData);
686 return sRet;
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);
697 return ret;
698 } else
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,
709 &rOpenKey.m_hImpl);
710 if (ret == RegError::NO_ERROR) rOpenKey.setRegistry(m_registry);
711 return ret;
712 } else
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;
723 sal_uInt32 nSubKeys;
724 ret = m_registry.m_pApi->openSubKeys(m_hImpl, keyName.pData,
725 &pSubKeys, &nSubKeys);
726 if ( ret != RegError::NO_ERROR)
728 return ret;
729 } else
731 rSubKeys.setKeyHandles(m_registry, pSubKeys, nSubKeys);
732 return ret;
734 } else
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;
745 sal_uInt32 nSubKeys;
746 ret = m_registry.m_pApi->getKeyNames(m_hImpl, keyName.pData,
747 &pSubKeyNames, &nSubKeys);
748 if ( ret != RegError::NO_ERROR)
750 return ret;
751 } else
753 rSubKeyNames.setKeyNames(m_registry, pSubKeyNames, nSubKeys);
754 return ret;
756 } else
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);
764 else
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)
775 m_hImpl = nullptr;
776 m_registry = Registry();
778 return ret;
779 } else
780 return RegError::INVALID_KEY;
783 inline RegError RegistryKey::setValue(const OUString& keyName,
784 RegValueType valueType,
785 RegValue pValue,
786 sal_uInt32 valueSize)
788 if (m_registry.isValid())
789 return m_registry.m_pApi->setValue(m_hImpl, keyName.pData, valueType,
790 pValue, valueSize);
791 else
792 return RegError::INVALID_KEY;
795 inline RegError RegistryKey::setLongListValue(const OUString& keyName,
796 sal_Int32 const * pValueList,
797 sal_uInt32 len)
799 if (m_registry.isValid())
800 return m_registry.m_pApi->setLongListValue(m_hImpl, keyName.pData,
801 pValueList, len);
802 else
803 return RegError::INVALID_KEY;
806 inline RegError RegistryKey::setStringListValue(const OUString& keyName,
807 char** pValueList,
808 sal_uInt32 len)
810 if (m_registry.isValid())
811 return m_registry.m_pApi->setStringListValue(m_hImpl, keyName.pData,
812 pValueList, len);
813 else
814 return RegError::INVALID_KEY;
817 inline RegError RegistryKey::setUnicodeListValue(const OUString& keyName,
818 sal_Unicode** pValueList,
819 sal_uInt32 len)
821 if (m_registry.isValid())
822 return m_registry.m_pApi->setUnicodeListValue(m_hImpl, keyName.pData,
823 pValueList, len);
824 else
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);
834 else
835 return RegError::INVALID_KEY;
838 inline RegError RegistryKey::getValue(const OUString& keyName,
839 RegValue pValue)
841 if (m_registry.isValid())
842 return m_registry.m_pApi->getValue(m_hImpl, keyName.pData, pValue);
843 else
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;
854 sal_uInt32 length;
855 ret = m_registry.m_pApi->getLongListValue(m_hImpl, keyName.pData,
856 &pValueList, &length);
857 if ( ret != RegError::NO_ERROR)
859 return ret;
860 } else
862 rValueList.setValueList(m_registry, RegValueType::LONGLIST,
863 pValueList, length);
864 return ret;
866 } else
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;
876 char** pValueList;
877 sal_uInt32 length;
878 ret = m_registry.m_pApi->getStringListValue(m_hImpl, keyName.pData,
879 &pValueList, &length);
880 if ( ret != RegError::NO_ERROR )
882 return ret;
883 } else
885 rValueList.setValueList(m_registry, RegValueType::STRINGLIST,
886 pValueList, length);
887 return ret;
889 } else
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;
900 sal_uInt32 length;
901 ret = m_registry.m_pApi->getUnicodeListValue(m_hImpl, keyName.pData,
902 &pValueList, &length);
903 if ( ret != RegError::NO_ERROR )
905 return ret;
906 } else
908 rValueList.setValueList(m_registry, RegValueType::UNICODELIST,
909 pValueList, length);
910 return ret;
912 } else
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,
921 keyName.pData,
922 true,
923 &rResolvedName.pData);
924 else
925 return RegError::INVALID_KEY;
928 inline OUString RegistryKey::getRegistryName()
930 if (m_registry.isValid())
932 return m_registry.getName();
933 } else
934 return OUString();
938 inline Registry::Registry()
939 : m_pApi(initRegistry_Api())
940 , m_hImpl(nullptr)
943 inline Registry::Registry(const Registry& toCopy)
944 : m_pApi(toCopy.m_pApi)
945 , m_hImpl(toCopy.m_hImpl)
947 if (m_hImpl)
948 m_pApi->acquire(m_hImpl);
952 inline Registry::~Registry()
954 if (m_hImpl)
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);
962 if (m_hImpl)
963 m_pApi->release(m_hImpl);
965 m_pApi = toAssign.m_pApi;
966 m_hImpl = toAssign.m_hImpl;
968 return *this;
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()
985 OUString sRet;
986 m_pApi->getName(m_hImpl, &sRet.pData);
987 return sRet;
990 inline RegError Registry::create(const OUString& registryName)
992 if (m_hImpl)
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)
1000 if (m_hImpl)
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)
1009 m_hImpl = nullptr;
1010 return ret;
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() )
1017 m_hImpl = nullptr;
1018 return ret;
1021 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */