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 ) {
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;
}
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 */);
}
// ----------------------------------------------------------------------------
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;
+
+ const wxString pathOld = GetPath();
- wxFileConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name());
- return pGroup != NULL;
+ 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
if ( !m_pCurrentGroup->DeleteEntry(path.Name()) )
return false;
+ SetDirty();
+
if ( bGroupIfEmptyAlso && m_pCurrentGroup->IsEmpty() ) {
if ( m_pCurrentGroup != m_pRootGroup ) {
wxFileConfigGroup *pGroup = m_pCurrentGroup;
SetPath(wxT("..")); // changes m_pCurrentGroup!
- if ( m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()) )
- SetDirty();
+ m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name());
}
//else: never delete the root group
}
void wxFileConfigGroup::SetLine(wxFileConfigLineList *pLine)
{
- // shouldn't be called twice unless we are resetting the line
- wxASSERT( m_pLine == 0 || pLine == 0 );
+ // for a normal (i.e. not root) group this method shouldn't be called twice
+ // unless we are resetting the line
+ wxASSERT_MSG( !m_pParent || !m_pLine || !pLine,
+ _T("changing line for a non-root group?") );
+
m_pLine = pLine;
}