#ifndef _FILECONF_H
#define _FILECONF_H
+#ifdef __GNUG__
+#pragma interface "fileconf.h"
+#endif
+
+// ----------------------------------------------------------------------------
+// compile options
+// ----------------------------------------------------------------------------
+
+// it won't compile without it anyhow
+#ifndef USE_WXCONFIG
+ #error "Please define USE_WXCONFIG or remove fileconf.cpp from your makefile"
+#endif // USE_WXCONFIG
+
// ----------------------------------------------------------------------------
// wxFileConfig
// ----------------------------------------------------------------------------
/*
- wxFileConfig derives from base Config and implements file based config class,
+ wxFileConfig derives from base Config and implements file based config class,
i.e. it uses ASCII disk files to store the information. These files are
- alternatively called INI, .conf or .rc in the documentation. They are
+ alternatively called INI, .conf or .rc in the documentation. They are
organized in groups or sections, which can nest (i.e. a group contains
subgroups, which contain their own subgroups &c). Each group has some
- number of entries, which are "key = value" pairs. More precisely, the format
+ number of entries, which are "key = value" pairs. More precisely, the format
is:
# comments are allowed after either ';' or '#' (Win/UNIX standard)
virtual bool GetFirstEntry(wxString& str, long& lIndex);
virtual bool GetNextEntry (wxString& str, long& lIndex);
+ virtual uint GetNumberOfEntries(bool bRecursive = FALSE) const;
+ virtual uint GetNumberOfGroups(bool bRecursive = FALSE) const;
+
+ virtual bool HasGroup(const wxString& strName) const;
+ virtual bool HasEntry(const wxString& strName) const;
+
virtual bool Read(wxString *pstr, const char *szKey,
const char *szDefault = 0) const;
virtual const char *Read(const char *szKey,
const char *szDefault = 0) const;
virtual bool Read(long *pl, const char *szKey, long lDefault) const;
+ virtual long Read(const char *szKey, long lDefault) const
+ { return wxConfig::Read(szKey, lDefault); }
virtual bool Write(const char *szKey, const char *szValue);
virtual bool Write(const char *szKey, long lValue);
virtual bool Flush(bool bCurrentOnly = FALSE);
{
public:
// ctor
- LineList(const wxString& str, LineList *pNext = NULL) : m_strLine(str)
- { SetNext(pNext); }
-
- //
+ LineList(const wxString& str, LineList *pNext = NULL) : m_strLine(str)
+ { SetNext(pNext); SetPrev(NULL); }
+
+ //
LineList *Next() const { return m_pNext; }
+ LineList *Prev() const { return m_pPrev; }
void SetNext(LineList *pNext) { m_pNext = pNext; }
+ void SetPrev(LineList *pPrev) { m_pPrev = pPrev; }
//
void SetText(const wxString& str) { m_strLine = str; }
private:
wxString m_strLine; // line contents
- LineList *m_pNext; // next node
+ LineList *m_pNext, // next node
+ *m_pPrev; // previous one
};
-
+
// functions to work with this list
LineList *LineListAppend(const wxString& str);
- LineList *LineListInsert(const wxString& str,
- LineList *pLine); // NULL => Append()
+ LineList *LineListInsert(const wxString& str,
+ LineList *pLine); // NULL => Prepend()
+ void LineListRemove(LineList *pLine);
bool LineListIsEmpty();
private:
//protected: --- if wxFileConfig::ConfigEntry is not public, functions in
// ConfigGroup such as Find/AddEntry can't return "ConfigEntry *"
public:
- WX_DEFINE_ARRAY(ConfigEntry *, ArrayEntries);
- WX_DEFINE_ARRAY(ConfigGroup *, ArrayGroups);
+ WX_DEFINE_SORTED_ARRAY(ConfigEntry *, ArrayEntries);
+ WX_DEFINE_SORTED_ARRAY(ConfigGroup *, ArrayGroups);
class ConfigEntry
{
void SetLine(LineList *pLine);
};
-protected:
class ConfigGroup
{
private:
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
public:
// ctor
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;
// get the last line belonging to an entry/subgroup of this group