Kaydet (Commit) 1bdbe0b4 authored tarafından Noel Grandin's avatar Noel Grandin

convert REG_ constants to scoped enum

Change-Id: I11d92218c5e0678d497f8964723033e2bd8b3300
üst 1b0c1943
......@@ -1451,7 +1451,7 @@ void cppuhelper::ServiceManager::readRdbFile(
bool cppuhelper::ServiceManager::readLegacyRdbFile(rtl::OUString const & uri) {
Registry reg;
switch (reg.open(uri, REG_READONLY)) {
switch (reg.open(uri, RegAccessMode::READONLY)) {
case REG_NO_ERROR:
break;
case REG_REGISTRY_NOT_EXISTS:
......
......@@ -411,7 +411,7 @@ REG_DLLPUBLIC sal_Bool REGISTRY_CALLTYPE reg_isReadOnly(RegHandle hReg);
@param registryName points to a null terminated string specifying the name of the registry.
@param phRegistry points to a hanle of the opened registry if the function succeeds otherwise NULL.
@param accessMode specifies the accessmode of the registry, REG_READONLY or REG_READWRITE.
@param accessMode specifies the accessmode of the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
@return REG_NO_ERROR if succeeds else an error code.
*/
REG_DLLPUBLIC RegError REGISTRY_CALLTYPE reg_openRegistry(rtl_uString* registryName,
......
......@@ -136,7 +136,7 @@ public:
If the registry already points to a valid registry, the old registry will be closed.
@param registryName specifies a registry name.
@param accessMode specifies the access mode for the registry, REG_READONLY or REG_READWRITE.
@param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
@return REG_NO_ERROR if succeeds else an error code.
*/
inline RegError open(const rtl::OUString& registryName,
......
......@@ -21,6 +21,7 @@
#define INCLUDED_REGISTRY_REGTYPE_H
#include <sal/types.h>
#include <o3tl/typed_flags_set.hxx>
/// defines the type of a registry handle used in the C API.
typedef void* RegHandle;
......@@ -34,15 +35,18 @@ typedef void* RegValue;
/** defines the open/access mode of the registry.
Two modes are valid:
-REG_READONLY allows readonly access
-REG_READWRITE allows read and write access
-READONLY allows readonly access
-READWRITE allows read and write access
*/
typedef sal_uInt16 RegAccessMode;
/// Flag to specify the open mode of a registry. This mode allows readonly access.
#define REG_READONLY 0x0001
/// Flag to specify the open mode of a registry. This mode allows read and write access.
#define REG_READWRITE 0x0002
enum class RegAccessMode
{
READONLY = 0x0001, /// This mode allows readonly access.
READWRITE = 0x0002 /// This mode allows read and write access.
};
namespace o3tl
{
template<> struct typed_flags<RegAccessMode> : is_typed_flags<RegAccessMode, 0x07> {};
}
/** defines the type of a registry key.
......
......@@ -452,18 +452,18 @@ ORegistry::~ORegistry()
// initRegistry
RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode)
RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode, bool bCreate)
{
RegError eRet = REG_INVALID_REGISTRY;
OStoreFile rRegFile;
storeAccessMode sAccessMode = REG_MODE_OPEN;
storeError errCode;
if (accessMode & REG_CREATE)
if (bCreate)
{
sAccessMode = REG_MODE_CREATE;
}
else if (accessMode & REG_READONLY)
else if (accessMode & RegAccessMode::READONLY)
{
sAccessMode = REG_MODE_OPENREAD;
m_readOnly = true;
......@@ -547,7 +547,7 @@ RegError ORegistry::destroyRegistry(const OUString& regName)
{
std::unique_ptr<ORegistry> pReg(new ORegistry());
if (!pReg->initRegistry(regName, REG_READWRITE))
if (!pReg->initRegistry(regName, RegAccessMode::READWRITE))
{
pReg.reset();
......@@ -908,7 +908,7 @@ RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName,
ORegKey* pKey = static_cast< ORegKey* >(hKey);
std::unique_ptr< ORegistry > pReg (new ORegistry());
_ret = pReg->initRegistry(regFileName, REG_READONLY);
_ret = pReg->initRegistry(regFileName, RegAccessMode::READONLY);
if (_ret != REG_NO_ERROR)
return _ret;
ORegKey* pRootKey = pReg->getRootKey();
......@@ -956,7 +956,7 @@ RegError ORegistry::saveKey(RegKeyHandle hKey, const OUString& regFileName,
ORegKey* pKey = static_cast< ORegKey* >(hKey);
std::unique_ptr< ORegistry > pReg (new ORegistry());
_ret = pReg->initRegistry(regFileName, REG_CREATE);
_ret = pReg->initRegistry(regFileName, RegAccessMode::READWRITE, true/*bCreate*/);
if (_ret != REG_NO_ERROR)
return _ret;
ORegKey* pRootKey = pReg->getRootKey();
......
......@@ -48,8 +48,6 @@
#define VALUE_TYPEOFFSET 1
#define VALUE_HEADEROFFSET 5
#define REG_CREATE 0x0004 // allow write accesses
#define REG_GUARD(mutex) \
osl::Guard< osl::Mutex > aGuard( mutex );
......@@ -68,7 +66,8 @@ public:
{ return --m_refCount; }
RegError initRegistry(const OUString& name,
RegAccessMode accessMode);
RegAccessMode accessMode,
bool bCreate = false);
RegError closeRegistry();
......
......@@ -114,7 +114,7 @@ static RegError REGISTRY_CALLTYPE createRegistry(rtl_uString* registryName,
RegError ret;
ORegistry* pReg = new ORegistry();
if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)))
{
delete pReg;
*phRegistry = NULL;
......@@ -508,7 +508,7 @@ RegError REGISTRY_CALLTYPE reg_createRegistry(rtl_uString* registryName,
RegError ret;
ORegistry* pReg = new ORegistry();
if ((ret = pReg->initRegistry(registryName, REG_CREATE)))
if ((ret = pReg->initRegistry(registryName, RegAccessMode::READWRITE, true/*bCreate*/)))
{
delete pReg;
*phRegistry = NULL;
......
......@@ -619,7 +619,7 @@ void test_registry_CppApi()
REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 32");
REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 33");
REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 33");
REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 34");
REG_ENSURE(!myRegistry->loadKey(rootKey, OUString("allFromTest2"),
......@@ -659,7 +659,7 @@ void test_registry_CppApi()
REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 46");
REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 47");
REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 47");
REG_ENSURE(!myRegistry->destroy(OUString("test2.rdb")), "test_registry_CppApi error 48");
// REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49");
......@@ -672,7 +672,7 @@ void test_registry_CppApi()
REG_ENSURE(!myRegistry->create(OUString("destroytest.rdb")), "test_registry_CppApi error 51");
REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 52");
REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), REG_READONLY), "test_registry_CppApi error 53");
REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), RegAccessMode::READONLY), "test_registry_CppApi error 53");
REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 54");
REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
......@@ -681,10 +681,10 @@ void test_registry_CppApi()
REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 57");
REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 58");
REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), REG_READWRITE), "test_registry_CppApi error 59");
REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 59");
REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 60");
REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 61");
REG_ENSURE(!myRegistry->open(OUString("test.rdb"), RegAccessMode::READWRITE), "test_registry_CppApi error 61");
REG_ENSURE(!myRegistry->destroy(OUString("ucrtest.rdb")), "test_registry_CppApi error 62");
REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 63");
delete(myRegistry);
......
......@@ -1975,13 +1975,13 @@ int _cdecl main( int argc, char * argv[] )
OUString regName2( convertToFileUrl(options.getRegName2().c_str(), options.getRegName2().size()) );
Registry reg1, reg2;
if ( reg1.open(regName1, REG_READONLY) )
if ( reg1.open(regName1, RegAccessMode::READONLY) )
{
fprintf(stdout, "%s: open registry \"%s\" failed\n",
options.getProgramName().c_str(), options.getRegName1().c_str());
return 2;
}
if ( reg2.open(regName2, REG_READONLY) )
if ( reg2.open(regName2, RegAccessMode::READONLY) )
{
fprintf(stdout, "%s: open registry \"%s\" failed\n",
options.getProgramName().c_str(), options.getRegName2().c_str());
......
......@@ -109,7 +109,7 @@ int __cdecl main( int argc, char * argv[] )
Registry reg;
OUString regName( convertToFileUrl(args[0].c_str(), args[0].size()) );
if (reg.open(regName, REG_READWRITE) != REG_NO_ERROR)
if (reg.open(regName, RegAccessMode::READWRITE) != REG_NO_ERROR)
{
if (reg.create(regName) != REG_NO_ERROR)
{
......
......@@ -44,7 +44,7 @@ int __cdecl main( int argc, char * argv[] )
}
OUString regName( convertToFileUrl(argv[1], strlen(argv[1])) );
if (reg_openRegistry(regName.pData, &hReg, REG_READONLY))
if (reg_openRegistry(regName.pData, &hReg, RegAccessMode::READONLY))
{
fprintf(stderr, "open registry \"%s\" failed\n", argv[1]);
exit(1);
......
......@@ -232,7 +232,7 @@ int _cdecl main()
else
cout << "30. registry test5.rdb is closed\n";
if (reg_openRegistry(OUString("test4.rdb").pData, &hReg, REG_READWRITE))
if (reg_openRegistry(OUString("test4.rdb").pData, &hReg, RegAccessMode::READWRITE))
cout << "\t31. registry test4.rdb is opened\n";
else
cout << "31. registry test4.rdb is opened\n";
......@@ -293,13 +293,13 @@ int _cdecl main()
else
cout << "\n43. key \"/allFromTest3/reg2FirstKey/reg2FirstSubKey\" is deleted\n";
if (reg_openRegistry(OUString("test4.rdb").pData, &hReg2, REG_READONLY))
if (reg_openRegistry(OUString("test4.rdb").pData, &hReg2, RegAccessMode::READONLY))
cout << "\n\t44. registry test4.rdb is opened for read only\n";
else
cout << "\n44. registry test4.rdb is opened for read only\n";
RegHandle hReg3;
if (reg_openRegistry(OUString("test4.rdb").pData, &hReg3, REG_READONLY))
if (reg_openRegistry(OUString("test4.rdb").pData, &hReg3, RegAccessMode::READONLY))
cout << "\n\t44.a). registry test4.rdb is opened for read only\n";
else
cout << "\n44.a). registry test4.rdb is opened for read only\n";
......
......@@ -1018,7 +1018,7 @@ void SimpleRegistry::open(
osl::MutexGuard guard(mutex_);
RegError err = (rURL.isEmpty() && bCreate)
? REG_REGISTRY_NOT_EXISTS
: registry_.open(rURL, bReadOnly ? REG_READONLY : REG_READWRITE);
: registry_.open(rURL, bReadOnly ? RegAccessMode::READONLY : RegAccessMode::READWRITE);
if (err == REG_REGISTRY_NOT_EXISTS && bCreate) {
err = registry_.create(rURL);
}
......
......@@ -107,7 +107,7 @@ RegistryKey rootKey, rKey, rKey2;
OUString userReg = getExePath();
userReg += "user.rdb";
if(myRegistry->open(userReg, REG_READWRITE))
if(myRegistry->open(userReg, RegAccessMode::READWRITE))
{
OSL_VERIFY(!myRegistry->create(userReg));
}
......@@ -128,7 +128,7 @@ void setLinkInDefaultRegistry(const OUString& linkName, const OUString& linkTarg
OUString appReg = getExePath();
appReg += "stoctest.rdb";
OSL_VERIFY(!myRegistry->open(appReg, REG_READWRITE));
OSL_VERIFY(!myRegistry->open(appReg, RegAccessMode::READWRITE));
OSL_VERIFY(!myRegistry->openRootKey(rootKey));
OSL_VERIFY(!rootKey.createLink(linkName, linkTarget));
......
......@@ -63,7 +63,7 @@ void setStarUserRegistry()
OUString userReg = getExePath();
userReg += "user.rdb";
if(myRegistry->open(userReg, REG_READWRITE))
if(myRegistry->open(userReg, RegAccessMode::READWRITE))
{
OSL_VERIFY(!myRegistry->create(userReg));
}
......
......@@ -796,7 +796,7 @@ LegacyProvider::LegacyProvider(Manager & manager, OUString const & uri):
manager_(manager)
{
Registry reg;
RegError e = reg.open(uri, REG_READONLY);
RegError e = reg.open(uri, RegAccessMode::READONLY);
switch (e) {
case REG_NO_ERROR:
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment