fixed bug with HasGroup() creating groups as side effect

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34794 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-07-01 18:05:10 +00:00
parent 993896f180
commit 6c99cd3d8c
2 changed files with 33 additions and 5 deletions

View File

@@ -209,6 +209,10 @@ private:
// the same as SetPath("/")
void SetRootPath();
// real SetPath() implementation, returns true if path could be set or false
// if path doesn't exist and createMissingComponents == false
bool DoSetPath(const wxString& strPath, bool createMissingComponents);
// set/test the dirty flag
void SetDirty() { m_isDirty = true; }
void ResetDirty() { m_isDirty = false; }

View File

@@ -746,13 +746,14 @@ void wxFileConfig::SetRootPath()
m_pCurrentGroup = m_pRootGroup;
}
void wxFileConfig::SetPath(const wxString& strPath)
bool
wxFileConfig::DoSetPath(const wxString& strPath, bool createMissingComponents)
{
wxArrayString aParts;
if ( strPath.empty() ) {
SetRootPath();
return;
return true;
}
if ( strPath[0] == wxCONFIG_PATH_SEPARATOR ) {
@@ -772,7 +773,13 @@ void wxFileConfig::SetPath(const wxString& strPath)
for ( n = 0; n < aParts.Count(); n++ ) {
wxFileConfigGroup *pNextGroup = m_pCurrentGroup->FindSubgroup(aParts[n]);
if ( pNextGroup == NULL )
{
if ( !createMissingComponents )
return false;
pNextGroup = m_pCurrentGroup->AddSubgroup(aParts[n]);
}
m_pCurrentGroup = pNextGroup;
}
@@ -781,6 +788,13 @@ void wxFileConfig::SetPath(const wxString& strPath)
for ( n = 0; n < aParts.Count(); n++ ) {
m_strPath << wxCONFIG_PATH_SEPARATOR << aParts[n];
}
return true;
}
void wxFileConfig::SetPath(const wxString& strPath)
{
DoSetPath(strPath, true /* create missing path components */);
}
// ----------------------------------------------------------------------------
@@ -857,10 +871,20 @@ size_t wxFileConfig::GetNumberOfGroups(bool bRecursive) const
bool wxFileConfig::HasGroup(const wxString& strName) const
{
wxConfigPathChanger path(this, strName);
// special case: DoSetPath("") does work as it's equivalent to DoSetPath("/")
// but there is no group with empty name so treat this separately
if ( strName.empty() )
return false;
wxFileConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name());
return pGroup != NULL;
const wxString pathOld = GetPath();
wxFileConfig *self = wx_const_cast(wxFileConfig *, this);
const bool
rc = self->DoSetPath(strName, false /* don't create missing components */);
self->SetPath(pathOld);
return rc;
}
bool wxFileConfig::HasEntry(const wxString& strName) const