inline bool IsValid(char c) { return isalnum(c) || strchr("@_/-!.*%", c); }
// compare functions for sorting the arrays
-static int CompareEntries(wxFileConfig::ConfigEntry *p1,
- wxFileConfig::ConfigEntry *p2);
-static int CompareGroups(wxFileConfig::ConfigGroup *p1,
- wxFileConfig::ConfigGroup *p2);
+static int CompareEntries(ConfigEntry *p1,
+ ConfigEntry *p2);
+static int CompareGroups(ConfigGroup *p1,
+ ConfigGroup *p2);
// filter strings
static wxString FilterIn(const wxString& str);
wxString wxFileConfig::GetLocalDir()
{
wxString strDir;
-
+
wxGetHomeDir(&strDir);
-
+
#ifdef __UNIX__
if (strDir.Last() != '/') strDir << '/';
#else
if ( strchr(szFile, '.') == NULL )
str << ".ini";
#endif
-
+
return str;
}
bool wxFileConfig::Write(const wxString& key, long lValue)
{
// ltoa() is not ANSI :-(
- char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits)
- sprintf(szBuf, "%ld", lValue);
- return Write(key, szBuf);
+ wxString buf;
+ buf.Printf("%ld", lValue);
+ return Write(key, buf);
}
bool wxFileConfig::Flush(bool /* bCurrentOnly */)
// ----------------------------------------------------------------------------
// append a new line to the end of the list
-wxFileConfig::LineList *wxFileConfig::LineListAppend(const wxString& str)
+LineList *wxFileConfig::LineListAppend(const wxString& str)
{
LineList *pLine = new LineList(str);
}
// insert a new line after the given one or in the very beginning if !pLine
-wxFileConfig::LineList *wxFileConfig::LineListInsert(const wxString& str,
+LineList *wxFileConfig::LineListInsert(const wxString& str,
LineList *pLine)
{
if ( pLine == m_linesTail )
// last entry?
if ( pNext == NULL )
m_linesTail = pPrev;
- else
+ else
pNext->SetPrev(pPrev);
delete pLine;
// ----------------------------------------------------------------------------
// ctor
-wxFileConfig::ConfigGroup::ConfigGroup(wxFileConfig::ConfigGroup *pParent,
+ConfigGroup::ConfigGroup(ConfigGroup *pParent,
const wxString& strName,
wxFileConfig *pConfig)
: m_aEntries(CompareEntries),
}
// dtor deletes all children
-wxFileConfig::ConfigGroup::~ConfigGroup()
+ConfigGroup::~ConfigGroup()
{
// entries
size_t n, nCount = m_aEntries.Count();
// line
// ----------------------------------------------------------------------------
-void wxFileConfig::ConfigGroup::SetLine(LineList *pLine)
+void ConfigGroup::SetLine(LineList *pLine)
{
wxASSERT( m_pLine == NULL ); // shouldn't be called twice
// Return the line which contains "[our name]". If we're still not in the list,
// add our line to it immediately after the last line of our parent group if we
// have it or in the very beginning if we're the root group.
-wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetGroupLine()
+LineList *ConfigGroup::GetGroupLine()
{
if ( m_pLine == NULL ) {
ConfigGroup *pParent = Parent();
// Return the last line belonging to the subgroups of this group (after which
// we can add a new subgroup), if we don't have any subgroups or entries our
// last line is the group line (m_pLine) itself.
-wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastGroupLine()
+LineList *ConfigGroup::GetLastGroupLine()
{
// if we have any subgroups, our last line is the last line of the last
// subgroup
if ( m_pLastGroup != NULL ) {
- wxFileConfig::LineList *pLine = m_pLastGroup->GetLastGroupLine();
+ LineList *pLine = m_pLastGroup->GetLastGroupLine();
wxASSERT( pLine != NULL ); // last group must have !NULL associated line
return pLine;
// return the last line belonging to the entries of this group (after which
// we can add a new entry), if we don't have any entries we will add the new
// one immediately after the group line itself.
-wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastEntryLine()
+LineList *ConfigGroup::GetLastEntryLine()
{
if ( m_pLastEntry != NULL ) {
- wxFileConfig::LineList *pLine = m_pLastEntry->GetLine();
+ LineList *pLine = m_pLastEntry->GetLine();
wxASSERT( pLine != NULL ); // last entry must have !NULL associated line
return pLine;
// group name
// ----------------------------------------------------------------------------
-wxString wxFileConfig::ConfigGroup::GetFullName() const
+wxString ConfigGroup::GetFullName() const
{
if ( Parent() )
return Parent()->GetFullName() + wxCONFIG_PATH_SEPARATOR + Name();
// ----------------------------------------------------------------------------
// use binary search because the array is sorted
-wxFileConfig::ConfigEntry *
-wxFileConfig::ConfigGroup::FindEntry(const char *szName) const
+ConfigEntry *
+ConfigGroup::FindEntry(const char *szName) const
{
size_t i,
lo = 0,
hi = m_aEntries.Count();
int res;
- wxFileConfig::ConfigEntry *pEntry;
+ ConfigEntry *pEntry;
while ( lo < hi ) {
i = (lo + hi)/2;
return NULL;
}
-wxFileConfig::ConfigGroup *
-wxFileConfig::ConfigGroup::FindSubgroup(const char *szName) const
+ConfigGroup *
+ConfigGroup::FindSubgroup(const char *szName) const
{
size_t i,
lo = 0,
hi = m_aSubgroups.Count();
int res;
- wxFileConfig::ConfigGroup *pGroup;
+ ConfigGroup *pGroup;
while ( lo < hi ) {
i = (lo + hi)/2;
// ----------------------------------------------------------------------------
// create a new entry and add it to the current group
-wxFileConfig::ConfigEntry *
-wxFileConfig::ConfigGroup::AddEntry(const wxString& strName, int nLine)
+ConfigEntry *
+ConfigGroup::AddEntry(const wxString& strName, int nLine)
{
wxASSERT( FindEntry(strName) == NULL );
}
// create a new group and add it to the current group
-wxFileConfig::ConfigGroup *
-wxFileConfig::ConfigGroup::AddSubgroup(const wxString& strName)
+ConfigGroup *
+ConfigGroup::AddSubgroup(const wxString& strName)
{
wxASSERT( FindSubgroup(strName) == NULL );
delete several of them.
*/
-bool wxFileConfig::ConfigGroup::DeleteSubgroupByName(const char *szName)
+bool ConfigGroup::DeleteSubgroupByName(const char *szName)
{
return DeleteSubgroup(FindSubgroup(szName));
}
// doesn't delete the subgroup itself, but does remove references to it from
// all other data structures (and normally the returned pointer should be
// deleted a.s.a.p. because there is nothing much to be done with it anyhow)
-bool wxFileConfig::ConfigGroup::DeleteSubgroup(ConfigGroup *pGroup)
+bool ConfigGroup::DeleteSubgroup(ConfigGroup *pGroup)
{
wxCHECK( pGroup != NULL, FALSE ); // deleting non existing group?
return TRUE;
}
-bool wxFileConfig::ConfigGroup::DeleteEntry(const char *szName)
+bool ConfigGroup::DeleteEntry(const char *szName)
{
ConfigEntry *pEntry = FindEntry(szName);
wxCHECK( pEntry != NULL, FALSE ); // deleting non existing item?
// ----------------------------------------------------------------------------
//
// ----------------------------------------------------------------------------
-void wxFileConfig::ConfigGroup::SetDirty()
+void ConfigGroup::SetDirty()
{
m_bDirty = TRUE;
if ( Parent() != NULL ) // propagate upwards
// ----------------------------------------------------------------------------
// ctor
// ----------------------------------------------------------------------------
-wxFileConfig::ConfigEntry::ConfigEntry(wxFileConfig::ConfigGroup *pParent,
+ConfigEntry::ConfigEntry(ConfigGroup *pParent,
const wxString& strName,
int nLine)
: m_strName(strName)
// set value
// ----------------------------------------------------------------------------
-void wxFileConfig::ConfigEntry::SetLine(LineList *pLine)
+void ConfigEntry::SetLine(LineList *pLine)
{
if ( m_pLine != NULL ) {
wxLogWarning(_("entry '%s' appears more than once in group '%s'"),
// second parameter is FALSE if we read the value from file and prevents the
// entry from being marked as 'dirty'
-void wxFileConfig::ConfigEntry::SetValue(const wxString& strValue, bool bUser)
+void ConfigEntry::SetValue(const wxString& strValue, bool bUser)
{
if ( bUser && IsImmutable() ) {
wxLogWarning(_("attempt to change immutable key '%s' ignored."),
}
else {
// add a new line to the file
- wxASSERT( m_nLine == NOT_FOUND ); // consistency check
+ wxASSERT( m_nLine == wxNOT_FOUND ); // consistency check
m_pLine = Group()->Config()->LineListInsert(strLine,
Group()->GetLastEntryLine());
}
}
-void wxFileConfig::ConfigEntry::SetDirty()
+void ConfigEntry::SetDirty()
{
m_bDirty = TRUE;
Group()->SetDirty();
// compare functions for array sorting
// ----------------------------------------------------------------------------
-int CompareEntries(wxFileConfig::ConfigEntry *p1,
- wxFileConfig::ConfigEntry *p2)
+int CompareEntries(ConfigEntry *p1,
+ ConfigEntry *p2)
{
#if wxCONFIG_CASE_SENSITIVE
return strcmp(p1->Name(), p2->Name());
#endif
}
-int CompareGroups(wxFileConfig::ConfigGroup *p1,
- wxFileConfig::ConfigGroup *p2)
+int CompareGroups(ConfigGroup *p1,
+ ConfigGroup *p2)
{
#if wxCONFIG_CASE_SENSITIVE
return strcmp(p1->Name(), p2->Name());
{
if(str.IsEmpty())
return str;
-
+
wxString strResult;
strResult.Alloc(str.Len());
return strResult;
}
+
+
+
+
+
+
+