From 2ba4130573b01a7427f8fdd8349093f830ddfbd9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Dec 2001 00:58:59 +0000 Subject: [PATCH] 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 --- include/wx/confbase.h | 116 +++++++++++++++---------- include/wx/fileconf.h | 40 ++------- include/wx/msw/iniconf.h | 32 ++----- include/wx/msw/regconf.h | 42 ++------- samples/config/conftest.cpp | 7 +- src/common/config.cpp | 169 +++++++++++++++++------------------- src/common/fileconf.cpp | 41 ++------- src/msw/iniconf.cpp | 37 +------- src/msw/regconf.cpp | 61 +++---------- 9 files changed, 203 insertions(+), 342 deletions(-) diff --git a/include/wx/confbase.h b/include/wx/confbase.h index 25b97678b8..fbd1e57a13 100644 --- a/include/wx/confbase.h +++ b/include/wx/confbase.h @@ -155,43 +155,56 @@ public: // 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.) - // read a string from the key - virtual bool Read(const wxString& key, wxString *pStr) const = 0; - virtual bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const; - virtual wxString Read(const wxString& key, const wxString& defVal = wxEmptyString) const; + // read a string from the key + bool Read(const wxString& key, wxString *pStr) const; + bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const; - virtual bool Read(const wxString& key, long *pl) const = 0; - virtual bool Read(const wxString& key, long *pl, long defVal) const; + // read a number (long) + bool Read(const wxString& key, long *pl) const; + bool Read(const wxString& key, long *pl, long defVal) const; - virtual long Read(const wxString& strKey, long defVal) const - { long l; Read(strKey, &l, defVal); return l; } + // read an int + bool Read(const wxString& key, int *pi) const; + bool Read(const wxString& key, int *pi, int defVal) const; - // Convenience functions that are built on other forms + // read a double + bool Read(const wxString& key, double* val) const; + bool Read(const wxString& key, double* val, double defVal) const; - // int - virtual bool Read(const wxString& key, int *pi) const; - virtual bool Read(const wxString& key, int *pi, int defVal) const; + // read a bool + bool Read(const wxString& key, bool* val) const; + bool Read(const wxString& key, bool* val, bool defVal) const; - // double - virtual bool Read(const wxString& key, double* val) const; - virtual bool Read(const wxString& key, double* val, double defVal) const; + // convenience functions returning directly the value (we don't have them for + // int/double/bool as there would be ambiguities with the long one then) + wxString Read(const wxString& key, + const wxString& defVal = wxEmptyString) const + { wxString s; (void)Read(key, &s, defVal); return s; } - // bool - virtual bool Read(const wxString& key, bool* val) const; - virtual bool Read(const wxString& key, bool* val, bool defVal) const; + long Read(const wxString& key, long defVal) const + { long l; (void)Read(key, &l, defVal); return l; } // write the value (return true on success) - virtual bool Write(const wxString& key, const wxString& value) = 0; - virtual bool Write(const wxString& key, long value) = 0; + bool Write(const wxString& key, const wxString& value) + { return DoWriteString(key, value); } + + bool Write(const wxString& key, long value) + { return DoWriteLong(key, value); } + + bool Write(const wxString& key, int value) + { return DoWriteInt(key, value); } - // convenience functions - virtual bool Write(const wxString& key, double value); - virtual bool Write(const wxString& key, bool 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 // 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 virtual bool Flush(bool bCurrentOnly = FALSE) = 0; @@ -242,6 +255,19 @@ protected: static bool IsImmutable(const wxString& key) { 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: // are we doing automatic environment variable expansion? bool m_bExpandEnvVars; @@ -260,27 +286,27 @@ private: long m_style; }; - // a handy little class which changes current path to the path of given entry - // and restores it in dtor: so if you declare a local variable of this type, - // you work in the entry directory and the path is automatically restored - // when the function returns - // Taken out of wxConfig since not all compilers can cope with nested classes. - class wxConfigPathChanger - { - public: - // ctor/dtor do path changing/restorin - wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry); - ~wxConfigPathChanger(); - - // get the key name - const wxString& Name() const { return m_strName; } - - private: - wxConfigBase *m_pContainer; // object we live in - wxString m_strName, // name of entry (i.e. name only) - m_strOldPath; // saved path - bool m_bChanged; // was the path changed? - }; +// a handy little class which changes current path to the path of given entry +// and restores it in dtor: so if you declare a local variable of this type, +// you work in the entry directory and the path is automatically restored +// when the function returns +// Taken out of wxConfig since not all compilers can cope with nested classes. +class wxConfigPathChanger +{ +public: + // ctor/dtor do path changing/restorin + wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry); + ~wxConfigPathChanger(); + + // get the key name + const wxString& Name() const { return m_strName; } + +private: + wxConfigBase *m_pContainer; // object we live in + wxString m_strName, // name of entry (i.e. name only) + m_strOldPath; // saved path + bool m_bChanged; // was the path changed? +}; // ---------------------------------------------------------------------------- diff --git a/include/wx/fileconf.h b/include/wx/fileconf.h index 819ea75cc5..2e997b65d6 100644 --- a/include/wx/fileconf.h +++ b/include/wx/fileconf.h @@ -152,39 +152,6 @@ public: virtual bool HasGroup(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 RenameEntry(const wxString& oldName, const wxString& newName); @@ -202,6 +169,13 @@ public: void LineListRemove(wxFileConfigLineList *pLine); 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: // GetXXXFileName helpers: return ('/' terminated) directory names static wxString GetGlobalDir(); diff --git a/include/wx/msw/iniconf.h b/include/wx/msw/iniconf.h index a49994978f..4fa4405a6d 100644 --- a/include/wx/msw/iniconf.h +++ b/include/wx/msw/iniconf.h @@ -65,30 +65,6 @@ public: // return TRUE if the current group is empty 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 RenameEntry(const wxString& oldName, const wxString& newName); @@ -98,6 +74,14 @@ public: virtual bool DeleteGroup(const wxString& szKey); 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: // helpers wxString GetPrivateKeyName(const wxString& szKey) const; diff --git a/include/wx/msw/regconf.h b/include/wx/msw/regconf.h index 7c33118002..dc33f73841 100644 --- a/include/wx/msw/regconf.h +++ b/include/wx/msw/regconf.h @@ -63,41 +63,6 @@ public: virtual size_t GetNumberOfEntries(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; } // rename @@ -124,6 +89,13 @@ protected: 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: // no copy ctor/assignment operator wxRegConfig(const wxRegConfig&); diff --git a/samples/config/conftest.cpp b/samples/config/conftest.cpp index 19b06638e3..a3aff05a03 100644 --- a/samples/config/conftest.cpp +++ b/samples/config/conftest.cpp @@ -100,6 +100,11 @@ bool MyApp::OnInit() 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: // wxFileConfig *pConfig = new wxFileConfig("conftest"); // wxConfigBase::Set(pConfig); @@ -209,7 +214,7 @@ void MyFrame::OnQuit(wxCommandEvent&) void MyFrame::OnAbout(wxCommandEvent&) { - wxMessageBox(_T("wxConfig demo\n© Vadim Zeitlin 1998"), _T("About"), + wxMessageBox(_T("wxConfig demo\n© 1998-2001 Vadim Zeitlin"), _T("About"), wxICON_INFORMATION | wxOK); } diff --git a/src/common/config.cpp b/src/common/config.cpp index 05ca5af209..286e2123aa 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -42,6 +42,7 @@ #include #include #include +#include // for INT_MAX // ---------------------------------------------------------------------------- // global and class static variables @@ -99,118 +100,91 @@ wxConfigBase *wxConfigBase::Create() return ms_pConfig; } -wxString wxConfigBase::Read(const wxString& key, const wxString& defVal) const -{ - wxString s; - Read(key, &s, defVal); - return s; -} +// ---------------------------------------------------------------------------- +// wxConfigBase reading entries +// ---------------------------------------------------------------------------- -bool wxConfigBase::Read(const wxString& key, wxString *str, const wxString& defVal) const -{ - if (!Read(key, str)) - { - *str = ExpandEnvVars(defVal); - return FALSE; +// 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; \ } - else - return TRUE; -} -bool wxConfigBase::Read(const wxString& key, long *pl, long defVal) const -{ - if (!Read(key, pl)) - { - *pl = defVal; - return FALSE; - } - else - return TRUE; -} -bool wxConfigBase::Read(const wxString& key, double* val) const -{ - wxString str; - if ( Read(key, &str) ) - { - return str.ToDouble(val); - } +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) - return FALSE; -} +#undef IMPLEMENT_READ_FOR_TYPE -bool wxConfigBase::Read(const wxString& key, double* val, double defVal) const +// 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, val)) - { - *val = defVal; - return FALSE; - } - else - return TRUE; -} + wxCHECK_MSG( pi, FALSE, _T("wxConfig::Read(): NULL parameter") ); -bool wxConfigBase::Read(const wxString& key, bool* val) const -{ long l; - if (Read(key, & l)) - { - *val = (l != 0); - return TRUE; - } - else + if ( !DoReadLong(key, &l) ) return FALSE; -} -bool wxConfigBase::Read(const wxString& key, bool* val, bool defVal) const -{ - if (!Read(key, val)) - { - *val = defVal; - return FALSE; - } - else - return TRUE; -} + wxASSERT_MSG( l < INT_MAX, _T("overflow in wxConfig::DoReadInt") ); -// Convenience functions + *pi = (int)l; -bool wxConfigBase::Read(const wxString& key, int *pi) const -{ - long l; - bool ret = Read(key, &l); - if (ret) - *pi = (int) l; - return ret; + return TRUE; } -bool wxConfigBase::Read(const wxString& key, int *pi, int defVal) const +bool wxConfigBase::DoReadBool(const wxString& key, bool* val) const { + wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); + long l; - bool ret = Read(key, &l, (long) defVal); - if (ret) - *pi = (int) l; - return ret; -} + if ( !DoReadLong(key, &l) ) + return FALSE; -bool wxConfigBase::Write(const wxString& key, double val) -{ - wxString str; - str.Printf(wxT("%g"), val); - return Write(key, str); -} + wxASSERT_MSG( l == 0 || l == 1, _T("bad bool value in wxConfig::DoReadInt") ); -bool wxConfigBase::Write(const wxString& key, bool value) -{ - return Write(key, value ? 1l : 0l); + *val = l != 0; + + return TRUE; } -bool wxConfigBase::Write(const wxString& key, const wxChar *value) +bool wxConfigBase::DoReadDouble(const wxString& key, double* val) const { - // explicit cast needed, otherwise value would have been converted to bool - return Write(key, wxString(value)); + wxString str; + if ( Read(key, &str) ) + { + return str.ToDouble(val); + } + + return FALSE; } +// string reading helper wxString wxConfigBase::ExpandEnvVars(const wxString& str) const { wxString tmp; // Required for BC++ @@ -221,6 +195,25 @@ wxString wxConfigBase::ExpandEnvVars(const wxString& str) const 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 // ---------------------------------------------------------------------------- diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 5c7c706d6e..a6107188c9 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -819,8 +819,7 @@ bool wxFileConfig::HasEntry(const wxString& strName) const // read/write values // ---------------------------------------------------------------------------- -bool wxFileConfig::Read(const wxString& key, - wxString* pStr) const +bool wxFileConfig::DoReadString(const wxString& key, wxString* pStr) const { wxConfigPathChanger path(this, key); @@ -829,32 +828,12 @@ bool wxFileConfig::Read(const wxString& key, return FALSE; } - *pStr = ExpandEnvVars(pEntry->Value()); - return TRUE; -} + *pStr = pEntry->Value(); -bool wxFileConfig::Read(const wxString& key, - 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; + return TRUE; } -bool wxFileConfig::Read(const wxString& key, long *pl) const +bool wxFileConfig::DoReadLong(const wxString& key, long *pl) const { wxString str; if ( !Read(key, & str) ) @@ -862,11 +841,10 @@ bool wxFileConfig::Read(const wxString& key, long *pl) const return FALSE; } - *pl = wxAtol(str); - return TRUE; + return str.ToLong(pl); } -bool wxFileConfig::Write(const wxString& key, const wxString& szValue) +bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue) { wxConfigPathChanger path(this, key); @@ -901,12 +879,9 @@ bool wxFileConfig::Write(const wxString& key, const wxString& szValue) return TRUE; } -bool wxFileConfig::Write(const wxString& key, long lValue) +bool wxFileConfig::DoWriteLong(const wxString& key, long lValue) { - // ltoa() is not ANSI :-( - wxString buf; - buf.Printf(wxT("%ld"), lValue); - return Write(key, buf); + return Write(key, wxString::Format(_T("%ld"), lValue)); } bool wxFileConfig::Flush(bool /* bCurrentOnly */) diff --git a/src/msw/iniconf.cpp b/src/msw/iniconf.cpp index eca894e0db..1c91682df3 100644 --- a/src/msw/iniconf.cpp +++ b/src/msw/iniconf.cpp @@ -282,7 +282,7 @@ bool wxIniConfig::IsEmpty() const // read/write // ---------------------------------------------------------------------------- -bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const +bool wxIniConfig::DoReadString(const wxString& szKey, wxString *pstr) const { wxConfigPathChanger path(this, szKey); 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, - 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 +bool wxIniConfig::DoReadLong(const wxString& szKey, long *pl) const { wxConfigPathChanger path(this, szKey); wxString strKey = GetPrivateKeyName(path.Name()); @@ -375,7 +346,7 @@ bool wxIniConfig::Read(const wxString& szKey, long *pl) const return FALSE ; } -bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue) +bool wxIniConfig::DoWriteString(const wxString& szKey, const wxString& szValue) { wxConfigPathChanger path(this, szKey); wxString strKey = GetPrivateKeyName(path.Name()); @@ -389,7 +360,7 @@ bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue) return bOk; } -bool wxIniConfig::Write(const wxString& szKey, long lValue) +bool wxIniConfig::DoWriteLong(const wxString& szKey, long lValue) { // ltoa() is not ANSI :-( char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits) diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 07fcf8201b..c63a563d6a 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -555,44 +555,10 @@ wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const // reading/writing // ---------------------------------------------------------------------------- -bool wxRegConfig::Read(const wxString& key, wxString *pStr) const +bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const { - wxConfigPathChanger path(this, key); - - 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; - } - } + wxCHECK_MSG( pStr, FALSE, _T("wxRegConfig::Read(): NULL param") ); - // 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); bool bQueryGlobal = TRUE; @@ -617,25 +583,19 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr, // first try local key if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) || (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) { - *pStr = wxConfigBase::ExpandEnvVars(*pStr); return TRUE; } - else { - if ( IsRecordingDefaults() ) { - ((wxRegConfig*)this)->Write(key, szDefault); - } - - // default value - *pStr = szDefault; - } - - *pStr = wxConfigBase::ExpandEnvVars(*pStr); 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); bool bQueryGlobal = TRUE; @@ -662,10 +622,11 @@ bool wxRegConfig::Read(const wxString& key, long *plResult) const (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) { return TRUE; } + return FALSE; } -bool wxRegConfig::Write(const wxString& key, const wxString& szValue) +bool wxRegConfig::DoWriteString(const wxString& key, const wxString& szValue) { wxConfigPathChanger path(this, key); @@ -677,7 +638,7 @@ bool wxRegConfig::Write(const wxString& key, const wxString& 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); -- 2.45.2