wxConfig changes to be more logical.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@636 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-08-27 21:06:02 +00:00
parent 73fb82f3f3
commit 1824493628
14 changed files with 570 additions and 190 deletions

View File

@@ -55,6 +55,10 @@
#define wxCONFIG_WIN32_NATIVE TRUE
#endif
// Style flags for constructor style parameter
#define wxCONFIG_USE_LOCAL_FILE 1
#define wxCONFIG_USE_GLOBAL_FILE 2
// ----------------------------------------------------------------------------
// various helper global functions
// ----------------------------------------------------------------------------
@@ -101,7 +105,17 @@ public:
// ctor & virtual dtor
// environment variable expansion is on by default
wxConfigBase() { m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE; }
// wxConfigBase() { m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE; }
// ctor
// Not all args will always be used by derived classes, but
// including them all in each class ensures compatibility.
// If appName is empty, uses wxApp name
wxConfigBase(const wxString& appName = wxEmptyString, const wxString& vendorName = wxEmptyString,
const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString,
long style = 0);
// empty but ensures that dtor of all derived classes is virtual
virtual ~wxConfigBase() { }
@@ -138,31 +152,44 @@ public:
// key access: returns TRUE if value was really read, FALSE if default used
// (and if the key is not found the default value is returned.)
// read a string from the key
virtual bool Read(wxString *pStr, const char *szKey,
const char *szDefault = (const char *) NULL) const = 0;
// another version using statis buffer - it means it will be overwritten
// after each call to this function!
virtual const char *Read(const char *szKey,
const char *szDefault = (const char *) NULL) const;
// the same for longs
virtual long Read(const char *szKey, long lDefault) const
{ long l; Read(&l, szKey, lDefault); return l; }
// and another version: returns true if default value is returned
virtual bool Read(long *pl, const char *szKey, long lDefault = 0) const = 0;
virtual bool Read(const wxString& key, wxString *pStr) const = 0;
virtual bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const;
virtual wxString Read(const wxString& key, const wxString& defVal) const;
virtual bool Read(const wxString& key, long *pl) const = 0;
virtual bool Read(const wxString& key, long *pl, long defVal) const;
virtual long Read(const wxString& strKey, long defVal) const
{ long l; Read(strKey, &l, defVal); return l; }
// Convenience functions that are built on other forms
// double
virtual bool Read(const wxString& key, double* val) const;
virtual bool Read(const wxString& key, double* val, double defVal) const;
// bool
virtual bool Read(const wxString& key, bool* val) const;
virtual bool Read(const wxString& key, bool* val, bool defVal) const;
// write the value (return true on success)
virtual bool Write(const char *szKey, const char *szValue) = 0;
virtual bool Write(const char *szKey, long lValue) = 0;
virtual bool Write(const wxString& key, const wxString& value) = 0;
virtual bool Write(const wxString& key, long value) = 0;
// Convenience functions
virtual bool Write(const wxString& key, double value);
virtual bool Write(const wxString& key, bool value);
// permanently writes all changes
virtual bool Flush(bool bCurrentOnly = FALSE) = 0;
// delete entries/groups
// deletes the specified entry and the group it belongs to if
// it was the last key in it and the second parameter is true
virtual bool DeleteEntry(const char *szKey,
virtual bool DeleteEntry(const wxString& key,
bool bDeleteGroupIfEmpty = TRUE) = 0;
// delete the group (with all subgroups)
virtual bool DeleteGroup(const char *szKey) = 0;
virtual bool DeleteGroup(const wxString& key) = 0;
// delete the whole underlying object (disk file, registry key, ...)
// primarly for use by desinstallation routine.
virtual bool DeleteAll() = 0;
@@ -186,20 +213,49 @@ public:
return tmp;
}
// misc accessors
inline wxString GetAppName() const { return m_appName; }
inline wxString GetVendorName() const { return m_vendorName; }
inline void SetAppName(const wxString& appName) { m_appName = appName; }
inline void SetVendorName(const wxString& vendorName) { m_vendorName = vendorName; }
inline void SetStyle(long style) { m_style; }
inline long GetStyle() const { return m_style; }
protected:
static bool IsImmutable(const char *szKey)
{ return *szKey == wxCONFIG_IMMUTABLE_PREFIX; }
static bool IsImmutable(const wxString& key)
{ return key[0] == wxCONFIG_IMMUTABLE_PREFIX; }
private:
// are we doing automatic environment variable expansion?
bool m_bExpandEnvVars;
// do we record default values?
bool m_bRecordDefaults;
// static variables
static wxConfigBase *ms_pConfig;
static bool ms_bAutoCreate;
// Application name and organisation name
wxString m_appName;
wxString m_vendorName;
// Style flag
long m_style;
};
// a handy little class which changes current path to the path of given entry
// and restores it in dtor: so if you declare a local variable of this type,
// you work in the entry directory and the path is automatically restored
// when the function returns
class PathChanger
// Taken out of wxConfig since not all compilers can cope with nested classes.
class wxConfigPathChanger
{
public:
// ctor/dtor do path changing/restorin
PathChanger(const wxConfigBase *pContainer, const wxString& strEntry);
~PathChanger();
wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry);
~wxConfigPathChanger();
// get the key name
const wxString& Name() const { return m_strName; }
@@ -211,16 +267,6 @@ protected:
bool m_bChanged; // was the path changed?
};
private:
// are we doing automatic environment variable expansion?
bool m_bExpandEnvVars;
// do we record default values?
bool m_bRecordDefaults;
// static variables
static wxConfigBase *ms_pConfig;
static bool ms_bAutoCreate;
};
// ----------------------------------------------------------------------------
// the native wxConfigBase implementation
@@ -240,5 +286,7 @@ private:
#define classwxConfig classwxFileConfig
#endif
#endif // _WX_CONFIG_H_

View File

@@ -112,6 +112,8 @@ public:
static wxString GetLocalFileName(const char *szFile);
// ctor & dtor
#if 0
// the names of local and global (if not disabled) config files are
// constructed using Get{Local|Global}FileName functions described above
// (szAppName is just the (short) name of your application)
@@ -123,6 +125,14 @@ public:
// directory). If either of strings is empty, the corresponding file is not
// used.
wxFileConfig(const wxString& strLocal, const wxString& strGlobal);
#endif
// New constructor: one size fits all. Specify wxCONFIG_USE_LOCAL_FILE
// or wxCONFIG_USE_GLOBAL_FILE to say which files should be used.
wxFileConfig(const wxString& appName, const wxString& vendorName = wxEmptyString,
const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString,
long style = wxCONFIG_USE_LOCAL_FILE);
// dtor will save unsaved data
virtual ~wxFileConfig();
@@ -141,6 +151,7 @@ public:
virtual bool HasGroup(const wxString& strName) const;
virtual bool HasEntry(const wxString& strName) const;
#if 0
virtual bool Read(wxString *pstr, const char *szKey,
const char *szDefault = 0) const;
virtual const char *Read(const char *szKey,
@@ -150,10 +161,31 @@ public:
{ return wxConfigBase::Read(szKey, lDefault); }
virtual bool Write(const char *szKey, const char *szValue);
virtual bool Write(const char *szKey, long lValue);
#endif
virtual bool Read(const wxString& key, wxString *pStr) const;
virtual bool Read(const wxString& key, wxString *pStr, const wxString& defValue) const;
virtual bool Read(const wxString& key, long *pl) const;
// The following are necessary to satisfy the compiler
wxString Read(const wxString& key, const wxString& defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, long *pl, long defVal) const
{ return wxConfigBase::Read(key, pl, defVal); }
long Read(const wxString& key, long defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, double* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, double* val, double defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
virtual bool Write(const wxString& key, const wxString& szValue);
virtual bool Write(const wxString& key, long lValue);
virtual bool Flush(bool bCurrentOnly = FALSE);
virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
virtual bool DeleteGroup(const char *szKey);
virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso);
virtual bool DeleteGroup(const wxString& szKey);
virtual bool DeleteAll();
public:

View File

@@ -43,7 +43,8 @@ public:
// if strAppName doesn't contain the extension and is not an absolute path,
// ".ini" is appended to it. if strVendor is empty, it's taken to be the
// same as strAppName.
wxIniConfig(const wxString& strAppName, const wxString& strVendor = "");
wxIniConfig(const wxString& strAppName = wxEmptyString, const wxString& strVendor = wxEmptyString,
const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString, long style = wxCONFIG_USE_LOCAL_FILE);
virtual ~wxIniConfig();
// implement inherited pure virtual functions
@@ -64,14 +65,26 @@ public:
// return TRUE if the current group is empty
bool IsEmpty() 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;
virtual bool Write(const char *szKey, const char *szValue);
virtual bool Write(const char *szKey, long lValue);
// read/write
bool Read(const wxString& key, wxString *pStr) const;
bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
bool Read(const wxString& key, long *plResult) const;
// The following are necessary to satisfy the compiler
wxString Read(const wxString& key, const wxString& defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, long *pl, long defVal) const
{ return wxConfigBase::Read(key, pl, defVal); }
long Read(const wxString& key, long defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, double* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, double* val, double defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
bool Write(const wxString& key, const wxString& szValue);
bool Write(const wxString& key, long lValue);
virtual bool Flush(bool bCurrentOnly = FALSE);
virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
@@ -80,11 +93,10 @@ public:
private:
// helpers
wxString GetPrivateKeyName(const char *szKey) const;
wxString GetKeyName(const char *szKey) const;
wxString GetPrivateKeyName(const wxString& szKey) const;
wxString GetKeyName(const wxString& szKey) const;
wxString m_strAppName, // name of the private INI file
m_strVendor; // name of our section in WIN.INI
wxString m_strLocalFilename; // name of the private INI file
wxString m_strGroup, // current group in appname.ini file
m_strPath; // the rest of the path (no trailing '_'!)
};

View File

@@ -28,8 +28,11 @@ class wxRegConfig : public wxConfigBase
{
public:
// ctor & dtor
// will store data in HKLM\strRegHive and HKCU\strRegHive
wxRegConfig(const wxString& strRegHive);
// will store data in HKLM\appName and HKCU\appName
wxRegConfig(const wxString& appName = wxEmptyString, const wxString& vendorName = wxEmptyString,
const wxString& localFilename = wxEmptyString, const wxString& globalFilename = wxEmptyString,
long style = 0);
// dtor will save unsaved data
virtual ~wxRegConfig();
@@ -57,16 +60,30 @@ public:
virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const;
// read/write
virtual bool Read(wxString *pStr, const char *szKey,
const char *szDefault = 0) const;
virtual bool Read(long *result, const char *szKey, long lDefault = 0) const;
virtual bool Write(const char *szKey, const char *szValue);
virtual bool Write(const char *szKey, long Value);
bool Read(const wxString& key, wxString *pStr) const;
bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
bool Read(const wxString& key, long *plResult) const;
// The following are necessary to satisfy the compiler
wxString Read(const wxString& key, const wxString& defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, long *pl, long defVal) const
{ return wxConfigBase::Read(key, pl, defVal); }
long Read(const wxString& key, long defVal) const
{ return wxConfigBase::Read(key, defVal); }
bool Read(const wxString& key, double* val) const
{ return wxConfigBase::Read(key, val); }
bool Read(const wxString& key, double* val, double defVal) const
{ return wxConfigBase::Read(key, val, defVal); }
bool Write(const wxString& key, const wxString& szValue);
bool Write(const wxString& key, long lValue);
virtual bool Flush(bool /* bCurrentOnly = FALSE */ ) { return TRUE; }
// delete
virtual bool DeleteEntry(const char *szKey, bool bGroupIfEmptyAlso);
virtual bool DeleteGroup(const char *szKey);
virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso);
virtual bool DeleteGroup(const wxString& key);
virtual bool DeleteAll();
private: