STYLE: Minor style

This commit is contained in:
Mathieu Malaterre 2006-03-09 16:40:00 -05:00
parent 3ba5d52d1b
commit 7ca1c6d2d8
2 changed files with 39 additions and 39 deletions

View File

@ -59,14 +59,13 @@ public:
virtual bool DeleteValue(const char *key); virtual bool DeleteValue(const char *key);
// Set value in a given key. // Set value in a given key.
virtual bool SetValue(const char *key, virtual bool SetValue(const char *key, const char *value);
const char *value);
// Open the registry at toplevel/subkey. // Open the registry at toplevel/subkey.
virtual bool Open(const char *toplevel, const char *subkey, virtual bool Open(const char *toplevel, const char *subkey,
int readonly); int readonly);
// Close the registry. // Close the registry.
virtual bool Close(); virtual bool Close();
// Set the value of changed // Set the value of changed
@ -75,7 +74,7 @@ public:
const char* GetTopLevel() { return m_TopLevel.c_str(); } const char* GetTopLevel() { return m_TopLevel.c_str(); }
//! Read from local or global scope. On Windows this mean from local machine //! Read from local or global scope. On Windows this mean from local machine
// or local user. On unix this will read from $HOME/.Projectrc or // or local user. On unix this will read from $HOME/.Projectrc or
// /etc/Project // /etc/Project
void SetGlobalScope(bool b); void SetGlobalScope(bool b);
bool GetGlobalScope(); bool GetGlobalScope();
@ -86,7 +85,7 @@ public:
protected: protected:
bool m_Changed; bool m_Changed;
kwsys_stl::string m_TopLevel; kwsys_stl::string m_TopLevel;
bool m_GlobalScope; bool m_GlobalScope;
#ifdef _WIN32 #ifdef _WIN32
@ -161,11 +160,12 @@ bool Registry::Open(const char *toplevel,
} }
if ( !toplevel || !*toplevel ) if ( !toplevel || !*toplevel )
{ {
kwsys_ios::cerr << "Registry::Opened() Toplevel not defined" << kwsys_ios::endl; kwsys_ios::cerr << "Registry::Opened() Toplevel not defined"
<< kwsys_ios::endl;
return res; return res;
} }
if ( isspace(toplevel[0]) || if ( isspace(toplevel[0]) ||
isspace(toplevel[strlen(toplevel)-1]) ) isspace(toplevel[strlen(toplevel)-1]) )
{ {
kwsys_ios::cerr << "Toplevel has to start with letter or number and end" kwsys_ios::cerr << "Toplevel has to start with letter or number and end"
@ -178,7 +178,7 @@ bool Registry::Open(const char *toplevel,
{ {
m_Locked = true; m_Locked = true;
} }
if ( res ) if ( res )
{ {
m_Opened = true; m_Opened = true;
@ -206,20 +206,20 @@ bool Registry::Close()
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool Registry::ReadValue(const char *subkey, bool Registry::ReadValue(const char *subkey,
const char *key, const char *key,
const char **value) const char **value)
{ {
*value = 0; *value = 0;
bool res = true; bool res = true;
bool open = false; bool open = false;
if ( ! value ) if ( ! value )
{ {
return res; return res;
} }
if ( !m_Opened ) if ( !m_Opened )
{ {
if ( !this->Open(this->GetTopLevel(), subkey, if ( !this->Open(this->GetTopLevel(), subkey,
Registry::READONLY) ) Registry::READONLY) )
{ {
return res; return res;
@ -245,7 +245,7 @@ bool Registry::DeleteKey(const char *subkey, const char *key)
bool open = false; bool open = false;
if ( !m_Opened ) if ( !m_Opened )
{ {
if ( !this->Open(this->GetTopLevel(), subkey, if ( !this->Open(this->GetTopLevel(), subkey,
Registry::READWRITE) ) Registry::READWRITE) )
{ {
return res; return res;
@ -276,7 +276,7 @@ bool Registry::DeleteValue(const char *subkey, const char *key)
bool open = false; bool open = false;
if ( !m_Opened ) if ( !m_Opened )
{ {
if ( !this->Open(this->GetTopLevel(), subkey, if ( !this->Open(this->GetTopLevel(), subkey,
Registry::READWRITE) ) Registry::READWRITE) )
{ {
return res; return res;
@ -301,14 +301,14 @@ bool Registry::DeleteValue(const char *subkey, const char *key)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool Registry::SetValue(const char *subkey, const char *key, bool Registry::SetValue(const char *subkey, const char *key,
const char *value) const char *value)
{ {
bool res = false; bool res = false;
bool open = false; bool open = false;
if ( !m_Opened ) if ( !m_Opened )
{ {
if ( !this->Open(this->GetTopLevel(), subkey, if ( !this->Open(this->GetTopLevel(), subkey,
Registry::READWRITE) ) Registry::READWRITE) )
{ {
return res; return res;
@ -378,7 +378,7 @@ RegistryHelper::~RegistryHelper()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::Open(const char *toplevel, const char *subkey, bool RegistryHelper::Open(const char *toplevel, const char *subkey,
int readonly) int readonly)
{ {
this->EntriesMap.clear(); this->EntriesMap.clear();
m_Empty = 1; m_Empty = 1;
@ -396,14 +396,14 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey,
str << "Software\\Kitware\\" << toplevel << "\\" << subkey; str << "Software\\Kitware\\" << toplevel << "\\" << subkey;
if ( readonly == Registry::READONLY ) if ( readonly == Registry::READONLY )
{ {
res = ( RegOpenKeyEx(scope, str.str().c_str(), res = ( RegOpenKeyEx(scope, str.str().c_str(),
0, KEY_READ, &this->HKey) == ERROR_SUCCESS ); 0, KEY_READ, &this->HKey) == ERROR_SUCCESS );
} }
else else
{ {
res = ( RegCreateKeyEx(scope, str.str().c_str(), res = ( RegCreateKeyEx(scope, str.str().c_str(),
0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
NULL, &this->HKey, &dwDummy) == ERROR_SUCCESS ); NULL, &this->HKey, &dwDummy) == ERROR_SUCCESS );
} }
if ( res != 0 ) if ( res != 0 )
{ {
@ -422,7 +422,7 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey,
{ {
if ( (homeDirectory = getenv("USERPROFILE")) == 0 ) if ( (homeDirectory = getenv("USERPROFILE")) == 0 )
{ {
return false; return false;
} }
} }
m_HomeDirectory = homeDirectory; m_HomeDirectory = homeDirectory;
@ -466,7 +466,7 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey,
{ {
// Comment // Comment
continue; continue;
} }
int linelen = static_cast<int>(strlen(line)); int linelen = static_cast<int>(strlen(line));
for ( cc = 0; cc < linelen; cc++ ) for ( cc = 0; cc < linelen; cc++ )
{ {
@ -500,7 +500,7 @@ bool RegistryHelper::Close()
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
int res; int res;
res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS ); res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
#endif #endif
@ -563,11 +563,11 @@ bool RegistryHelper::ReadValue(const char *skey, const char **value)
{ {
return false; return false;
} }
DWORD dwType, dwSize; DWORD dwType, dwSize;
dwType = REG_SZ; dwType = REG_SZ;
char buffer[1024]; // Replace with RegQueryInfoKey char buffer[1024]; // Replace with RegQueryInfoKey
dwSize = sizeof(buffer); dwSize = sizeof(buffer);
int res = ( RegQueryValueEx(this->HKey, skey, NULL, &dwType, int res = ( RegQueryValueEx(this->HKey, skey, NULL, &dwType,
(BYTE *)buffer, &dwSize) == ERROR_SUCCESS ); (BYTE *)buffer, &dwSize) == ERROR_SUCCESS );
if ( !res ) if ( !res )
{ {
@ -654,8 +654,8 @@ bool RegistryHelper::SetValue(const char *skey, const char *value)
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
DWORD len = (DWORD)(value ? strlen(value) : 0); DWORD len = (DWORD)(value ? strlen(value) : 0);
int res = ( RegSetValueEx(this->HKey, skey, 0, REG_SZ, int res = ( RegSetValueEx(this->HKey, skey, 0, REG_SZ,
(CONST BYTE *)(const char *)value, (CONST BYTE *)(const char *)value,
len+1) == ERROR_SUCCESS ); len+1) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
@ -710,7 +710,7 @@ char *RegistryHelper::Strip(char *str)
if ( !str ) if ( !str )
{ {
return NULL; return NULL;
} }
len = strlen(str); len = strlen(str);
nstr = str; nstr = str;
for( cc=0; cc<len; cc++ ) for( cc=0; cc<len; cc++ )
@ -773,7 +773,7 @@ kwsys_stl::string RegistryHelper::EncodeValue(const char* str)
{ {
switch ( *str ) switch ( *str )
{ {
case '%': case '=': case '\n': case '\r': case '\t': case '%': case '=': case '\n': case '\r': case '\t':
char buffer[4]; char buffer[4];
sprintf(buffer, "%%%02X", *str); sprintf(buffer, "%%%02X", *str);
ostr << buffer; ostr << buffer;

View File

@ -27,7 +27,7 @@ class RegistryHelper;
* \brief Portable registry class * \brief Portable registry class
* *
* This class abstracts the storing of data that can be restored * This class abstracts the storing of data that can be restored
* when the program executes again. On Win32 platform it is * when the program executes again. On Win32 platform it is
* implemented using the registry and on unix as a file in * implemented using the registry and on unix as a file in
* the user's home directory. * the user's home directory.
*/ */
@ -60,24 +60,24 @@ public:
bool DeleteValue(const char *subkey, const char *key); bool DeleteValue(const char *subkey, const char *key);
//! Set value in a given key. //! Set value in a given key.
bool SetValue(const char *subkey, const char *key, bool SetValue(const char *subkey, const char *key,
const char *value); const char *value);
//! Open the registry at toplevel/subkey. //! Open the registry at toplevel/subkey.
bool Open(const char *toplevel, const char *subkey, bool Open(const char *toplevel, const char *subkey,
int readonly); int readonly);
//! Close the registry. //! Close the registry.
bool Close(); bool Close();
//! Read from local or global scope. On Windows this mean from local machine //! Read from local or global scope. On Windows this mean from local machine
// or local user. On unix this will read from $HOME/.Projectrc or // or local user. On unix this will read from $HOME/.Projectrc or
// /etc/Project // /etc/Project
void GlobalScopeOn() { this->SetGlobalScope(1); } void GlobalScopeOn() { this->SetGlobalScope(1); }
void GlobalScopeOff() { this->SetGlobalScope(0); } void GlobalScopeOff() { this->SetGlobalScope(0); }
void SetGlobalScope(bool b); void SetGlobalScope(bool b);
bool GetGlobalScope(); bool GetGlobalScope();
// Set or get the toplevel registry key. // Set or get the toplevel registry key.
void SetTopLevel(const char* tl); void SetTopLevel(const char* tl);
const char* GetTopLevel(); const char* GetTopLevel();
@ -100,7 +100,7 @@ private:
RegistryHelper* Helper; RegistryHelper* Helper;
bool m_Opened; bool m_Opened;
bool m_Locked; bool m_Locked;
}; // End Class: Registry }; // End Class: Registry