wxConfig clean up and bug fix for record defaults

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13004 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-12-14 00:58:59 +00:00
parent 4a0f7f3f17
commit 2ba4130573
9 changed files with 208 additions and 347 deletions

View File

@@ -155,43 +155,56 @@ public:
// key access: returns TRUE if value was really read, FALSE if default used // key access: returns TRUE if value was really read, FALSE if default used
// (and if the key is not found the default value is returned.) // (and if the key is not found the default value is returned.)
// read a string from the key // read a string from the key
virtual bool Read(const wxString& key, wxString *pStr) const = 0; bool Read(const wxString& key, wxString *pStr) const;
virtual bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const; bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const;
virtual wxString Read(const wxString& key, const wxString& defVal = wxEmptyString) const; // read a number (long)
bool Read(const wxString& key, long *pl) const;
bool Read(const wxString& key, long *pl, long defVal) const;
virtual bool Read(const wxString& key, long *pl) const = 0; // read an int
virtual bool Read(const wxString& key, long *pl, long defVal) const; bool Read(const wxString& key, int *pi) const;
bool Read(const wxString& key, int *pi, int defVal) const;
virtual long Read(const wxString& strKey, long defVal) const // read a double
{ long l; Read(strKey, &l, defVal); return l; } bool Read(const wxString& key, double* val) const;
bool Read(const wxString& key, double* val, double defVal) const;
// Convenience functions that are built on other forms // read a bool
bool Read(const wxString& key, bool* val) const;
bool Read(const wxString& key, bool* val, bool defVal) const;
// int // convenience functions returning directly the value (we don't have them for
virtual bool Read(const wxString& key, int *pi) const; // int/double/bool as there would be ambiguities with the long one then)
virtual bool Read(const wxString& key, int *pi, int defVal) const; wxString Read(const wxString& key,
const wxString& defVal = wxEmptyString) const
{ wxString s; (void)Read(key, &s, defVal); return s; }
// double long Read(const wxString& key, long defVal) const
virtual bool Read(const wxString& key, double* val) const; { long l; (void)Read(key, &l, defVal); return l; }
virtual bool Read(const wxString& key, double* val, double defVal) const;
// bool
virtual bool Read(const wxString& key, bool* val) const;
virtual bool Read(const wxString& key, bool* val, bool defVal) const;
// write the value (return true on success) // write the value (return true on success)
virtual bool Write(const wxString& key, const wxString& value) = 0; bool Write(const wxString& key, const wxString& value)
virtual bool Write(const wxString& key, long value) = 0; { return DoWriteString(key, value); }
// convenience functions bool Write(const wxString& key, long value)
virtual bool Write(const wxString& key, double value); { return DoWriteLong(key, value); }
virtual bool Write(const wxString& key, bool value);
bool Write(const wxString& key, int value)
{ return DoWriteInt(key, value); }
bool Write(const wxString& key, double value)
{ return DoWriteDouble(key, value); }
bool Write(const wxString& key, bool value)
{ return DoWriteBool(key, value); }
// we have to provide a separate version for C strings as otherwise they // we have to provide a separate version for C strings as otherwise they
// would be converted to bool and not to wxString as expected! // would be converted to bool and not to wxString as expected!
virtual bool Write(const wxString& key, const wxChar *value); bool Write(const wxString& key, const wxChar *value)
{ return Write(key, wxString(value)); }
// permanently writes all changes // permanently writes all changes
virtual bool Flush(bool bCurrentOnly = FALSE) = 0; virtual bool Flush(bool bCurrentOnly = FALSE) = 0;
@@ -242,6 +255,19 @@ protected:
static bool IsImmutable(const wxString& key) static bool IsImmutable(const wxString& key)
{ return !key.IsEmpty() && key[0] == wxCONFIG_IMMUTABLE_PREFIX; } { return !key.IsEmpty() && key[0] == wxCONFIG_IMMUTABLE_PREFIX; }
// do read/write the values of different types
virtual bool DoReadString(const wxString& key, wxString *pStr) const = 0;
virtual bool DoReadLong(const wxString& key, long *pl) const = 0;
virtual bool DoReadInt(const wxString& key, int *pi) const;
virtual bool DoReadDouble(const wxString& key, double* val) const;
virtual bool DoReadBool(const wxString& key, bool* val) const;
virtual bool DoWriteString(const wxString& key, const wxString& value) = 0;
virtual bool DoWriteLong(const wxString& key, long value) = 0;
virtual bool DoWriteInt(const wxString& key, int value);
virtual bool DoWriteDouble(const wxString& key, double value);
virtual bool DoWriteBool(const wxString& key, bool value);
private: private:
// are we doing automatic environment variable expansion? // are we doing automatic environment variable expansion?
bool m_bExpandEnvVars; bool m_bExpandEnvVars;

View File

@@ -152,39 +152,6 @@ public:
virtual bool HasGroup(const wxString& strName) const; virtual bool HasGroup(const wxString& strName) const;
virtual bool HasEntry(const wxString& strName) const; virtual bool HasEntry(const wxString& strName) const;
virtual bool Read(const wxString& key, wxString *pStr) const;
virtual bool Read(const wxString& key, wxString *pStr, const wxString& defValue) const;
virtual bool Read(const wxString& key, long *pl) const;
// The following are necessary to satisfy the compiler
wxString Read(const wxString& key, const wxString& defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, long *pl, long defVal) const
{ return wxConfigBase::Read(key, pl, defVal); }
long Read(const wxString& key, long defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, int *pi, int defVal) const
{ return wxConfigBase::Read(key, pi, defVal); }
bool Read(const wxString& key, int *pi) const
{ return wxConfigBase::Read(key, pi); }
bool Read(const wxString& key, double* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, double* val, double defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
bool Read(const wxString& key, bool* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, bool* val, bool defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
virtual bool Write(const wxString& key, const wxString& szValue);
virtual bool Write(const wxString& key, long lValue);
bool Write(const wxString& key, double value)
{ return wxConfigBase::Write(key, value); }
bool Write(const wxString& key, bool value)
{ return wxConfigBase::Write(key, value); }
bool Write(const wxString& key, const wxChar* value)
{ return wxConfigBase::Write(key, value); }
virtual bool Flush(bool bCurrentOnly = FALSE); virtual bool Flush(bool bCurrentOnly = FALSE);
virtual bool RenameEntry(const wxString& oldName, const wxString& newName); virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
@@ -202,6 +169,13 @@ public:
void LineListRemove(wxFileConfigLineList *pLine); void LineListRemove(wxFileConfigLineList *pLine);
bool LineListIsEmpty(); bool LineListIsEmpty();
protected:
virtual bool DoReadString(const wxString& key, wxString *pStr) const;
virtual bool DoReadLong(const wxString& key, long *pl) const;
virtual bool DoWriteString(const wxString& key, const wxString& szValue);
virtual bool DoWriteLong(const wxString& key, long lValue);
private: private:
// GetXXXFileName helpers: return ('/' terminated) directory names // GetXXXFileName helpers: return ('/' terminated) directory names
static wxString GetGlobalDir(); static wxString GetGlobalDir();

View File

@@ -65,30 +65,6 @@ public:
// return TRUE if the current group is empty // return TRUE if the current group is empty
bool IsEmpty() const; bool IsEmpty() const;
// read/write
bool Read(const wxString& key, wxString *pStr) const;
bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
bool Read(const wxString& key, long *plResult) const;
// The following are necessary to satisfy the compiler
wxString Read(const wxString& key, const wxString& defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, long *pl, long defVal) const
{ return wxConfigBase::Read(key, pl, defVal); }
long Read(const wxString& key, long defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, int *pi, int defVal) const
{ return wxConfigBase::Read(key, pi, defVal); }
bool Read(const wxString& key, int *pi) const
{ return wxConfigBase::Read(key, pi); }
bool Read(const wxString& key, double* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, double* val, double defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
bool Write(const wxString& key, const wxString& szValue);
bool Write(const wxString& key, long lValue);
virtual bool Flush(bool bCurrentOnly = FALSE); virtual bool Flush(bool bCurrentOnly = FALSE);
virtual bool RenameEntry(const wxString& oldName, const wxString& newName); virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
@@ -98,6 +74,14 @@ public:
virtual bool DeleteGroup(const wxString& szKey); virtual bool DeleteGroup(const wxString& szKey);
virtual bool DeleteAll(); virtual bool DeleteAll();
protected:
// read/write
bool DoReadString(const wxString& key, wxString *pStr) const;
bool DoReadLong(const wxString& key, long *plResult) const;
bool DoWriteString(const wxString& key, const wxString& szValue);
bool DoWriteLong(const wxString& key, long lValue);
private: private:
// helpers // helpers
wxString GetPrivateKeyName(const wxString& szKey) const; wxString GetPrivateKeyName(const wxString& szKey) const;

View File

@@ -63,41 +63,6 @@ public:
virtual size_t GetNumberOfEntries(bool bRecursive = FALSE) const; virtual size_t GetNumberOfEntries(bool bRecursive = FALSE) const;
virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const; virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const;
// read/write
bool Read(const wxString& key, wxString *pStr) const;
bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
wxString Read(const wxString& key, const wxString& defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, long *plResult) const;
bool Read(const wxString& key, long *pl, long defVal) const
{ return wxConfigBase::Read(key, pl, defVal); }
long Read(const wxString& key, long defVal) const
{ return wxConfigBase::Read(key, defVal); }
// The following are necessary to satisfy the compiler
bool Read(const wxString& key, int *pi, int defVal) const
{ return wxConfigBase::Read(key, pi, defVal); }
bool Read(const wxString& key, int *pi) const
{ return wxConfigBase::Read(key, pi); }
bool Read(const wxString& key, double* val, double defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
bool Read(const wxString& key, double* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, bool *pb, bool defVal) const
{ return wxConfigBase::Read(key, pb, defVal); }
bool Read(const wxString& key, bool *pb) const
{ return wxConfigBase::Read(key, pb); }
bool Write(const wxString& key, const wxString& szValue);
bool Write(const wxString& key, long lValue);
bool Write(const wxString& key, double dValue)
{ return wxConfigBase::Write(key, dValue); }
bool Write(const wxString& key, bool bValue)
{ return wxConfigBase::Write(key, bValue); }
virtual bool Flush(bool WXUNUSED(bCurrentOnly) = FALSE) { return TRUE; } virtual bool Flush(bool WXUNUSED(bCurrentOnly) = FALSE) { return TRUE; }
// rename // rename
@@ -124,6 +89,13 @@ protected:
return self->m_keyLocal; return self->m_keyLocal;
} }
// implement read/write methods
virtual bool DoReadString(const wxString& key, wxString *pStr) const;
virtual bool DoReadLong(const wxString& key, long *plResult) const;
virtual bool DoWriteString(const wxString& key, const wxString& szValue);
virtual bool DoWriteLong(const wxString& key, long lValue);
private: private:
// no copy ctor/assignment operator // no copy ctor/assignment operator
wxRegConfig(const wxRegConfig&); wxRegConfig(const wxRegConfig&);

View File

@@ -100,6 +100,11 @@ bool MyApp::OnInit()
wxConfigBase *pConfig = wxConfigBase::Get(); wxConfigBase *pConfig = wxConfigBase::Get();
// uncomment this to force writing back of the defaults for all values
// if they're not present in the config - this can give the user an idea
// of all possible settings for this program
pConfig->SetRecordDefaults();
// or you could also write something like this: // or you could also write something like this:
// wxFileConfig *pConfig = new wxFileConfig("conftest"); // wxFileConfig *pConfig = new wxFileConfig("conftest");
// wxConfigBase::Set(pConfig); // wxConfigBase::Set(pConfig);
@@ -209,7 +214,7 @@ void MyFrame::OnQuit(wxCommandEvent&)
void MyFrame::OnAbout(wxCommandEvent&) void MyFrame::OnAbout(wxCommandEvent&)
{ {
wxMessageBox(_T("wxConfig demo\n<EFBFBD> Vadim Zeitlin 1998"), _T("About"), wxMessageBox(_T("wxConfig demo\n<EFBFBD> 1998-2001 Vadim Zeitlin"), _T("About"),
wxICON_INFORMATION | wxOK); wxICON_INFORMATION | wxOK);
} }

View File

@@ -42,6 +42,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> // for INT_MAX
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// global and class static variables // global and class static variables
@@ -99,36 +100,80 @@ wxConfigBase *wxConfigBase::Create()
return ms_pConfig; return ms_pConfig;
} }
wxString wxConfigBase::Read(const wxString& key, const wxString& defVal) const // ----------------------------------------------------------------------------
{ // wxConfigBase reading entries
wxString s; // ----------------------------------------------------------------------------
Read(key, &s, defVal);
return s; // implement both Read() overloads for the given type in terms of DoRead()
#define IMPLEMENT_READ_FOR_TYPE(name, type, deftype, extra) \
bool wxConfigBase::Read(const wxString& key, type *val) const \
{ \
wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); \
\
return DoRead##name(key, val); \
} \
\
bool wxConfigBase::Read(const wxString& key, \
type *val, \
deftype defVal) const \
{ \
wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); \
\
if ( DoRead##name(key, val) ) \
return TRUE; \
\
if ( IsRecordingDefaults() ) \
{ \
((wxConfigBase *)this)->DoWrite##name(key, defVal); \
} \
\
*val = extra(defVal); \
\
return FALSE; \
} }
bool wxConfigBase::Read(const wxString& key, wxString *str, const wxString& defVal) const
IMPLEMENT_READ_FOR_TYPE(String, wxString, const wxString&, ExpandEnvVars)
IMPLEMENT_READ_FOR_TYPE(Long, long, long, long)
IMPLEMENT_READ_FOR_TYPE(Int, int, int, int)
IMPLEMENT_READ_FOR_TYPE(Double, double, double, double)
IMPLEMENT_READ_FOR_TYPE(Bool, bool, bool, bool)
#undef IMPLEMENT_READ_FOR_TYPE
// the DoReadXXX() for the other types have implementation in the base class
// but can be overridden in the derived ones
bool wxConfigBase::DoReadInt(const wxString& key, int *pi) const
{ {
if (!Read(key, str)) wxCHECK_MSG( pi, FALSE, _T("wxConfig::Read(): NULL parameter") );
{
*str = ExpandEnvVars(defVal); long l;
if ( !DoReadLong(key, &l) )
return FALSE; return FALSE;
}
else wxASSERT_MSG( l < INT_MAX, _T("overflow in wxConfig::DoReadInt") );
*pi = (int)l;
return TRUE; return TRUE;
} }
bool wxConfigBase::Read(const wxString& key, long *pl, long defVal) const bool wxConfigBase::DoReadBool(const wxString& key, bool* val) const
{ {
if (!Read(key, pl)) wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") );
{
*pl = defVal; long l;
if ( !DoReadLong(key, &l) )
return FALSE; return FALSE;
}
else wxASSERT_MSG( l == 0 || l == 1, _T("bad bool value in wxConfig::DoReadInt") );
*val = l != 0;
return TRUE; return TRUE;
} }
bool wxConfigBase::Read(const wxString& key, double* val) const bool wxConfigBase::DoReadDouble(const wxString& key, double* val) const
{ {
wxString str; wxString str;
if ( Read(key, &str) ) if ( Read(key, &str) )
@@ -139,78 +184,7 @@ bool wxConfigBase::Read(const wxString& key, double* val) const
return FALSE; return FALSE;
} }
bool wxConfigBase::Read(const wxString& key, double* val, double defVal) const // string reading helper
{
if (!Read(key, val))
{
*val = defVal;
return FALSE;
}
else
return TRUE;
}
bool wxConfigBase::Read(const wxString& key, bool* val) const
{
long l;
if (Read(key, & l))
{
*val = (l != 0);
return TRUE;
}
else
return FALSE;
}
bool wxConfigBase::Read(const wxString& key, bool* val, bool defVal) const
{
if (!Read(key, val))
{
*val = defVal;
return FALSE;
}
else
return TRUE;
}
// Convenience functions
bool wxConfigBase::Read(const wxString& key, int *pi) const
{
long l;
bool ret = Read(key, &l);
if (ret)
*pi = (int) l;
return ret;
}
bool wxConfigBase::Read(const wxString& key, int *pi, int defVal) const
{
long l;
bool ret = Read(key, &l, (long) defVal);
if (ret)
*pi = (int) l;
return ret;
}
bool wxConfigBase::Write(const wxString& key, double val)
{
wxString str;
str.Printf(wxT("%g"), val);
return Write(key, str);
}
bool wxConfigBase::Write(const wxString& key, bool value)
{
return Write(key, value ? 1l : 0l);
}
bool wxConfigBase::Write(const wxString& key, const wxChar *value)
{
// explicit cast needed, otherwise value would have been converted to bool
return Write(key, wxString(value));
}
wxString wxConfigBase::ExpandEnvVars(const wxString& str) const wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
{ {
wxString tmp; // Required for BC++ wxString tmp; // Required for BC++
@@ -221,6 +195,25 @@ wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
return tmp; return tmp;
} }
// ----------------------------------------------------------------------------
// wxConfigBase writing
// ----------------------------------------------------------------------------
bool wxConfigBase::DoWriteDouble(const wxString& key, double val)
{
return DoWriteString(key, wxString::Format(_T("%g"), val));
}
bool wxConfigBase::DoWriteInt(const wxString& key, int value)
{
return DoWriteLong(key, (long)value);
}
bool wxConfigBase::DoWriteBool(const wxString& key, bool value)
{
return DoWriteLong(key, value ? 1l : 0l);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxConfigPathChanger // wxConfigPathChanger
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -819,8 +819,7 @@ bool wxFileConfig::HasEntry(const wxString& strName) const
// read/write values // read/write values
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxFileConfig::Read(const wxString& key, bool wxFileConfig::DoReadString(const wxString& key, wxString* pStr) const
wxString* pStr) const
{ {
wxConfigPathChanger path(this, key); wxConfigPathChanger path(this, key);
@@ -829,32 +828,12 @@ bool wxFileConfig::Read(const wxString& key,
return FALSE; return FALSE;
} }
*pStr = ExpandEnvVars(pEntry->Value()); *pStr = pEntry->Value();
return TRUE; return TRUE;
} }
bool wxFileConfig::Read(const wxString& key, bool wxFileConfig::DoReadLong(const wxString& key, long *pl) const
wxString* pStr, const wxString& defVal) const
{
wxConfigPathChanger path(this, key);
wxFileConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
bool ok;
if (pEntry == NULL) {
if( IsRecordingDefaults() )
((wxFileConfig *)this)->Write(key,defVal);
*pStr = ExpandEnvVars(defVal);
ok = FALSE;
}
else {
*pStr = ExpandEnvVars(pEntry->Value());
ok = TRUE;
}
return ok;
}
bool wxFileConfig::Read(const wxString& key, long *pl) const
{ {
wxString str; wxString str;
if ( !Read(key, & str) ) if ( !Read(key, & str) )
@@ -862,11 +841,10 @@ bool wxFileConfig::Read(const wxString& key, long *pl) const
return FALSE; return FALSE;
} }
*pl = wxAtol(str); return str.ToLong(pl);
return TRUE;
} }
bool wxFileConfig::Write(const wxString& key, const wxString& szValue) bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue)
{ {
wxConfigPathChanger path(this, key); wxConfigPathChanger path(this, key);
@@ -901,12 +879,9 @@ bool wxFileConfig::Write(const wxString& key, const wxString& szValue)
return TRUE; return TRUE;
} }
bool wxFileConfig::Write(const wxString& key, long lValue) bool wxFileConfig::DoWriteLong(const wxString& key, long lValue)
{ {
// ltoa() is not ANSI :-( return Write(key, wxString::Format(_T("%ld"), lValue));
wxString buf;
buf.Printf(wxT("%ld"), lValue);
return Write(key, buf);
} }
bool wxFileConfig::Flush(bool /* bCurrentOnly */) bool wxFileConfig::Flush(bool /* bCurrentOnly */)

View File

@@ -282,7 +282,7 @@ bool wxIniConfig::IsEmpty() const
// read/write // read/write
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const bool wxIniConfig::DoReadString(const wxString& szKey, wxString *pstr) const
{ {
wxConfigPathChanger path(this, szKey); wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name()); wxString strKey = GetPrivateKeyName(path.Name());
@@ -309,36 +309,7 @@ bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const
} }
} }
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr, bool wxIniConfig::DoReadLong(const wxString& szKey, long *pl) const
const wxString& szDefault) const
{
wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name());
char szBuf[1024]; // @@ should dynamically allocate memory...
// first look in the private INI file
// NB: the lpDefault param to GetPrivateProfileString can't be NULL
GetPrivateProfileString(m_strGroup, strKey, "",
szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
if ( ::IsEmpty(szBuf) ) {
// now look in win.ini
wxString strKey = GetKeyName(path.Name());
GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
}
if ( ::IsEmpty(szBuf) ) {
*pstr = szDefault;
return FALSE;
}
else {
*pstr = szBuf ;
return TRUE;
}
}
bool wxIniConfig::Read(const wxString& szKey, long *pl) const
{ {
wxConfigPathChanger path(this, szKey); wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name()); wxString strKey = GetPrivateKeyName(path.Name());
@@ -375,7 +346,7 @@ bool wxIniConfig::Read(const wxString& szKey, long *pl) const
return FALSE ; return FALSE ;
} }
bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue) bool wxIniConfig::DoWriteString(const wxString& szKey, const wxString& szValue)
{ {
wxConfigPathChanger path(this, szKey); wxConfigPathChanger path(this, szKey);
wxString strKey = GetPrivateKeyName(path.Name()); wxString strKey = GetPrivateKeyName(path.Name());
@@ -389,7 +360,7 @@ bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue)
return bOk; return bOk;
} }
bool wxIniConfig::Write(const wxString& szKey, long lValue) bool wxIniConfig::DoWriteLong(const wxString& szKey, long lValue)
{ {
// ltoa() is not ANSI :-( // ltoa() is not ANSI :-(
char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits) char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits)

View File

@@ -555,44 +555,10 @@ wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const
// reading/writing // reading/writing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxRegConfig::Read(const wxString& key, wxString *pStr) const bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const
{ {
wxConfigPathChanger path(this, key); wxCHECK_MSG( pStr, FALSE, _T("wxRegConfig::Read(): NULL param") );
bool bQueryGlobal = TRUE;
// if immutable key exists in global key we must check that it's not
// overriden by the local key with the same name
if ( IsImmutable(path.Name()) ) {
if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) {
if ( m_keyLocal.Exists() && LocalKey().HasValue(path.Name()) ) {
wxLogWarning(wxT("User value for immutable key '%s' ignored."),
path.Name().c_str());
}
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return TRUE;
}
else {
// don't waste time - it's not there anyhow
bQueryGlobal = FALSE;
}
}
// first try local key
if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) ||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
// nothing to do
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return TRUE;
}
return FALSE;
}
bool wxRegConfig::Read(const wxString& key, wxString *pStr,
const wxString& szDefault) const
{
wxConfigPathChanger path(this, key); wxConfigPathChanger path(this, key);
bool bQueryGlobal = TRUE; bool bQueryGlobal = TRUE;
@@ -617,25 +583,19 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr,
// first try local key // first try local key
if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) || if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) ||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) { (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return TRUE; return TRUE;
} }
else {
if ( IsRecordingDefaults() ) {
((wxRegConfig*)this)->Write(key, szDefault);
}
// default value
*pStr = szDefault;
}
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
return FALSE; return FALSE;
} }
bool wxRegConfig::Read(const wxString& key, long *plResult) const // this exactly reproduces the string version above except for ExpandEnvVars(),
// we really should avoid this code duplication somehow...
bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const
{ {
wxCHECK_MSG( plResult, FALSE, _T("wxRegConfig::Read(): NULL param") );
wxConfigPathChanger path(this, key); wxConfigPathChanger path(this, key);
bool bQueryGlobal = TRUE; bool bQueryGlobal = TRUE;
@@ -662,10 +622,11 @@ bool wxRegConfig::Read(const wxString& key, long *plResult) const
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) { (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
bool wxRegConfig::Write(const wxString& key, const wxString& szValue) bool wxRegConfig::DoWriteString(const wxString& key, const wxString& szValue)
{ {
wxConfigPathChanger path(this, key); wxConfigPathChanger path(this, key);
@@ -677,7 +638,7 @@ bool wxRegConfig::Write(const wxString& key, const wxString& szValue)
return LocalKey().SetValue(path.Name(), szValue); return LocalKey().SetValue(path.Name(), szValue);
} }
bool wxRegConfig::Write(const wxString& key, long lValue) bool wxRegConfig::DoWriteLong(const wxString& key, long lValue)
{ {
wxConfigPathChanger path(this, key); wxConfigPathChanger path(this, key);