git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@107
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
wxString m_strName; // group's name
bool m_bDirty; // if FALSE => all subgroups are not dirty
LineList *m_pLine; // pointer to our line in the linked list
wxString m_strName; // group's name
bool m_bDirty; // if FALSE => all subgroups are not dirty
LineList *m_pLine; // pointer to our line in the linked list
- int m_nLastEntry, // last here means "last added"
- m_nLastGroup; //
+ ConfigEntry *m_pLastEntry; // last entry of this group in the local file
+ ConfigGroup *m_pLastGroup; // last subgroup
// will also recursively set parent's dirty flag
void SetDirty();
void SetLine(LineList *pLine);
// will also recursively set parent's dirty flag
void SetDirty();
void SetLine(LineList *pLine);
+
+ // the new entries in this subgroup will be inserted after the last subgroup
+ // or, if there is none, after the last entry
+ void SetLastEntry(ConfigEntry *pLastEntry) { m_pLastEntry = pLastEntry; }
+ void SetLastGroup(ConfigGroup *pLastGroup) { m_pLastGroup = pLastGroup; }
wxString GetFullName() const;
wxString GetFullName() const;
-// insert a new line after the given one
+// insert a new line after the given one or in the very beginning if !pLine
wxFileConfig::LineList *wxFileConfig::LineListInsert(const wxString& str,
LineList *pLine)
{
wxFileConfig::LineList *wxFileConfig::LineListInsert(const wxString& str,
LineList *pLine)
{
+ if ( pLine == m_linesTail )
return LineListAppend(str);
return LineListAppend(str);
- LineList *pNewLine = new LineList(str, pLine->Next());
- pLine->SetNext(pNewLine);
+ LineList *pNewLine;
+
+ if ( pLine == NULL ) {
+ pNewLine = new LineList(str, m_linesHead);
+ m_linesHead = pNewLine;
+ }
+ else {
+ pNewLine = new LineList(str, pLine->Next());
+ pLine->SetNext(pNewLine);
+ }
m_pParent = pParent;
m_pLine = NULL;
m_bDirty = FALSE;
m_pParent = pParent;
m_pLine = NULL;
m_bDirty = FALSE;
-
- m_nLastEntry =
- m_nLastGroup = NOT_FOUND;
+ m_pLastEntry = NULL;
+ m_pLastGroup = NULL;
}
// dtor deletes all children
}
// dtor deletes all children
strFullName << "[" << GetFullName().c_str() + 1 << "]"; // +1: no '/'
m_pLine = m_pConfig->LineListInsert(strFullName,
Parent()->GetLastGroupLine());
strFullName << "[" << GetFullName().c_str() + 1 << "]"; // +1: no '/'
m_pLine = m_pConfig->LineListInsert(strFullName,
Parent()->GetLastGroupLine());
+ Parent()->SetLastGroup(this);
- // we're the root group, yet we were not in the local file => there were
- // only comments and blank lines in config file or nothing at all
- // we return NULL, so that LineListInsert() will do Append()
+ // we return NULL, so that LineListInsert() will insert us in the
+ // very beginning
{
// if we have any subgroups, our last line is the last line of the last
// subgroup
{
// if we have any subgroups, our last line is the last line of the last
// subgroup
- if ( m_nLastGroup != NOT_FOUND ) {
- return m_aSubgroups[m_nLastGroup]->GetLastGroupLine();
- }
+ if ( m_pLastGroup != NULL )
+ return m_pLastGroup->GetLastGroupLine();
// if we have any entries, our last line is the last entry
// if we have any entries, our last line is the last entry
- if ( m_nLastEntry != NOT_FOUND ) {
- return m_aEntries[m_nLastEntry]->GetLine();
- }
+ if ( m_pLastEntry != NULL )
+ return m_pLastEntry->GetLine();
// nothing at all: last line is the first one
return GetGroupLine();
// nothing at all: last line is the first one
return GetGroupLine();
// (after which we can add a new entry)
wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastEntryLine()
{
// (after which we can add a new entry)
wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastEntryLine()
{
- if ( m_nLastEntry != NOT_FOUND )
- return m_aEntries[m_nLastEntry]->GetLine();
- else
- return GetGroupLine();
+ if ( m_pLastEntry != NULL ) {
+ wxFileConfig::LineList *pLine = m_pLastEntry->GetLine();
+
+ wxASSERT( pLine != NULL ); // last entry must have !NULL associated line
+ return pLine;
+ }
+
+ // no entrues: insert after the group header
+ return GetGroupLine();
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
+ Group()->SetLastEntry(this);
}
// second parameter is FALSE if we read the value from file and prevents the
}
// second parameter is FALSE if we read the value from file and prevents the
// add a new line to the file
wxASSERT( m_nLine == NOT_FOUND ); // consistency check
// add a new line to the file
wxASSERT( m_nLine == NOT_FOUND ); // consistency check
- Group()->Config()->LineListInsert(strLine, Group()->GetLastEntryLine());
+ m_pLine = Group()->Config()->LineListInsert(strLine,
+ Group()->GetLastEntryLine());
+ Group()->SetLastEntry(this);