wxConfig clean up and bug fix for record defaults
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13004 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -155,43 +155,56 @@ 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(const wxString& key, wxString *pStr) const = 0;
|
||||
virtual bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const;
|
||||
bool Read(const wxString& key, wxString *pStr) const;
|
||||
bool Read(const wxString& key, wxString *pStr, const wxString& defVal) const;
|
||||
|
||||
virtual wxString Read(const wxString& key, const wxString& defVal = wxEmptyString) const;
|
||||
// read a number (long)
|
||||
bool Read(const wxString& key, long *pl) const;
|
||||
bool Read(const wxString& key, long *pl, long defVal) const;
|
||||
|
||||
virtual bool Read(const wxString& key, long *pl) const = 0;
|
||||
virtual bool Read(const wxString& key, long *pl, long defVal) const;
|
||||
// read an int
|
||||
bool Read(const wxString& key, int *pi) const;
|
||||
bool Read(const wxString& key, int *pi, int defVal) const;
|
||||
|
||||
virtual long Read(const wxString& strKey, long defVal) const
|
||||
{ long l; Read(strKey, &l, defVal); return l; }
|
||||
// read a double
|
||||
bool Read(const wxString& key, double* val) const;
|
||||
bool Read(const wxString& key, double* val, double defVal) const;
|
||||
|
||||
// Convenience functions that are built on other forms
|
||||
// read a bool
|
||||
bool Read(const wxString& key, bool* val) const;
|
||||
bool Read(const wxString& key, bool* val, bool defVal) const;
|
||||
|
||||
// int
|
||||
virtual bool Read(const wxString& key, int *pi) const;
|
||||
virtual bool Read(const wxString& key, int *pi, int defVal) const;
|
||||
// convenience functions returning directly the value (we don't have them for
|
||||
// int/double/bool as there would be ambiguities with the long one then)
|
||||
wxString Read(const wxString& key,
|
||||
const wxString& defVal = wxEmptyString) const
|
||||
{ wxString s; (void)Read(key, &s, defVal); return s; }
|
||||
|
||||
// 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;
|
||||
long Read(const wxString& key, long defVal) const
|
||||
{ long l; (void)Read(key, &l, defVal); return l; }
|
||||
|
||||
// write the value (return true on success)
|
||||
virtual bool Write(const wxString& key, const wxString& value) = 0;
|
||||
virtual bool Write(const wxString& key, long value) = 0;
|
||||
bool Write(const wxString& key, const wxString& value)
|
||||
{ return DoWriteString(key, value); }
|
||||
|
||||
// convenience functions
|
||||
virtual bool Write(const wxString& key, double value);
|
||||
virtual bool Write(const wxString& key, bool value);
|
||||
bool Write(const wxString& key, long value)
|
||||
{ return DoWriteLong(key, value); }
|
||||
|
||||
bool Write(const wxString& key, int value)
|
||||
{ return DoWriteInt(key, value); }
|
||||
|
||||
bool Write(const wxString& key, double value)
|
||||
{ return DoWriteDouble(key, value); }
|
||||
|
||||
bool Write(const wxString& key, bool value)
|
||||
{ return DoWriteBool(key, value); }
|
||||
|
||||
// we have to provide a separate version for C strings as otherwise they
|
||||
// would be converted to bool and not to wxString as expected!
|
||||
virtual bool Write(const wxString& key, const wxChar *value);
|
||||
bool Write(const wxString& key, const wxChar *value)
|
||||
{ return Write(key, wxString(value)); }
|
||||
|
||||
// permanently writes all changes
|
||||
virtual bool Flush(bool bCurrentOnly = FALSE) = 0;
|
||||
@@ -242,6 +255,19 @@ protected:
|
||||
static bool IsImmutable(const wxString& key)
|
||||
{ return !key.IsEmpty() && key[0] == wxCONFIG_IMMUTABLE_PREFIX; }
|
||||
|
||||
// do read/write the values of different types
|
||||
virtual bool DoReadString(const wxString& key, wxString *pStr) const = 0;
|
||||
virtual bool DoReadLong(const wxString& key, long *pl) const = 0;
|
||||
virtual bool DoReadInt(const wxString& key, int *pi) const;
|
||||
virtual bool DoReadDouble(const wxString& key, double* val) const;
|
||||
virtual bool DoReadBool(const wxString& key, bool* val) const;
|
||||
|
||||
virtual bool DoWriteString(const wxString& key, const wxString& value) = 0;
|
||||
virtual bool DoWriteLong(const wxString& key, long value) = 0;
|
||||
virtual bool DoWriteInt(const wxString& key, int value);
|
||||
virtual bool DoWriteDouble(const wxString& key, double value);
|
||||
virtual bool DoWriteBool(const wxString& key, bool value);
|
||||
|
||||
private:
|
||||
// are we doing automatic environment variable expansion?
|
||||
bool m_bExpandEnvVars;
|
||||
@@ -260,27 +286,27 @@ private:
|
||||
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
|
||||
// Taken out of wxConfig since not all compilers can cope with nested classes.
|
||||
class wxConfigPathChanger
|
||||
{
|
||||
public:
|
||||
// ctor/dtor do path changing/restorin
|
||||
wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry);
|
||||
~wxConfigPathChanger();
|
||||
// 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
|
||||
// Taken out of wxConfig since not all compilers can cope with nested classes.
|
||||
class wxConfigPathChanger
|
||||
{
|
||||
public:
|
||||
// ctor/dtor do path changing/restorin
|
||||
wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry);
|
||||
~wxConfigPathChanger();
|
||||
|
||||
// get the key name
|
||||
const wxString& Name() const { return m_strName; }
|
||||
// get the key name
|
||||
const wxString& Name() const { return m_strName; }
|
||||
|
||||
private:
|
||||
wxConfigBase *m_pContainer; // object we live in
|
||||
wxString m_strName, // name of entry (i.e. name only)
|
||||
m_strOldPath; // saved path
|
||||
bool m_bChanged; // was the path changed?
|
||||
};
|
||||
private:
|
||||
wxConfigBase *m_pContainer; // object we live in
|
||||
wxString m_strName, // name of entry (i.e. name only)
|
||||
m_strOldPath; // saved path
|
||||
bool m_bChanged; // was the path changed?
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -152,39 +152,6 @@ public:
|
||||
virtual bool HasGroup(const wxString& strName) const;
|
||||
virtual bool HasEntry(const wxString& strName) const;
|
||||
|
||||
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, int *pi, int defVal) const
|
||||
{ return wxConfigBase::Read(key, pi, defVal); }
|
||||
bool Read(const wxString& key, int *pi) const
|
||||
{ return wxConfigBase::Read(key, pi); }
|
||||
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 Read(const wxString& key, bool* val) const
|
||||
{ return wxConfigBase::Read(key, val); }
|
||||
bool Read(const wxString& key, bool* val, bool 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);
|
||||
bool Write(const wxString& key, double value)
|
||||
{ return wxConfigBase::Write(key, value); }
|
||||
bool Write(const wxString& key, bool value)
|
||||
{ return wxConfigBase::Write(key, value); }
|
||||
bool Write(const wxString& key, const wxChar* value)
|
||||
{ return wxConfigBase::Write(key, value); }
|
||||
|
||||
virtual bool Flush(bool bCurrentOnly = FALSE);
|
||||
|
||||
virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
|
||||
@@ -202,6 +169,13 @@ public:
|
||||
void LineListRemove(wxFileConfigLineList *pLine);
|
||||
bool LineListIsEmpty();
|
||||
|
||||
protected:
|
||||
virtual bool DoReadString(const wxString& key, wxString *pStr) const;
|
||||
virtual bool DoReadLong(const wxString& key, long *pl) const;
|
||||
|
||||
virtual bool DoWriteString(const wxString& key, const wxString& szValue);
|
||||
virtual bool DoWriteLong(const wxString& key, long lValue);
|
||||
|
||||
private:
|
||||
// GetXXXFileName helpers: return ('/' terminated) directory names
|
||||
static wxString GetGlobalDir();
|
||||
|
@@ -65,30 +65,6 @@ public:
|
||||
// return TRUE if the current group is empty
|
||||
bool IsEmpty() const;
|
||||
|
||||
// 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, int *pi, int defVal) const
|
||||
{ return wxConfigBase::Read(key, pi, defVal); }
|
||||
bool Read(const wxString& key, int *pi) const
|
||||
{ return wxConfigBase::Read(key, pi); }
|
||||
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 RenameEntry(const wxString& oldName, const wxString& newName);
|
||||
@@ -98,6 +74,14 @@ public:
|
||||
virtual bool DeleteGroup(const wxString& szKey);
|
||||
virtual bool DeleteAll();
|
||||
|
||||
protected:
|
||||
// read/write
|
||||
bool DoReadString(const wxString& key, wxString *pStr) const;
|
||||
bool DoReadLong(const wxString& key, long *plResult) const;
|
||||
|
||||
bool DoWriteString(const wxString& key, const wxString& szValue);
|
||||
bool DoWriteLong(const wxString& key, long lValue);
|
||||
|
||||
private:
|
||||
// helpers
|
||||
wxString GetPrivateKeyName(const wxString& szKey) const;
|
||||
|
@@ -63,41 +63,6 @@ public:
|
||||
virtual size_t GetNumberOfEntries(bool bRecursive = FALSE) const;
|
||||
virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const;
|
||||
|
||||
// read/write
|
||||
bool Read(const wxString& key, wxString *pStr) const;
|
||||
bool Read(const wxString& key, wxString *pStr, const wxString& szDefault) const;
|
||||
wxString Read(const wxString& key, const wxString& defVal) const
|
||||
{ return wxConfigBase::Read(key, defVal); }
|
||||
|
||||
bool Read(const wxString& key, long *plResult) const;
|
||||
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); }
|
||||
|
||||
// The following are necessary to satisfy the compiler
|
||||
bool Read(const wxString& key, int *pi, int defVal) const
|
||||
{ return wxConfigBase::Read(key, pi, defVal); }
|
||||
bool Read(const wxString& key, int *pi) const
|
||||
{ return wxConfigBase::Read(key, pi); }
|
||||
|
||||
bool Read(const wxString& key, double* val, double defVal) const
|
||||
{ return wxConfigBase::Read(key, val, defVal); }
|
||||
bool Read(const wxString& key, double* val) const
|
||||
{ return wxConfigBase::Read(key, val); }
|
||||
|
||||
bool Read(const wxString& key, bool *pb, bool defVal) const
|
||||
{ return wxConfigBase::Read(key, pb, defVal); }
|
||||
bool Read(const wxString& key, bool *pb) const
|
||||
{ return wxConfigBase::Read(key, pb); }
|
||||
|
||||
bool Write(const wxString& key, const wxString& szValue);
|
||||
bool Write(const wxString& key, long lValue);
|
||||
bool Write(const wxString& key, double dValue)
|
||||
{ return wxConfigBase::Write(key, dValue); }
|
||||
bool Write(const wxString& key, bool bValue)
|
||||
{ return wxConfigBase::Write(key, bValue); }
|
||||
|
||||
virtual bool Flush(bool WXUNUSED(bCurrentOnly) = FALSE) { return TRUE; }
|
||||
|
||||
// rename
|
||||
@@ -124,6 +89,13 @@ protected:
|
||||
return self->m_keyLocal;
|
||||
}
|
||||
|
||||
// implement read/write methods
|
||||
virtual bool DoReadString(const wxString& key, wxString *pStr) const;
|
||||
virtual bool DoReadLong(const wxString& key, long *plResult) const;
|
||||
|
||||
virtual bool DoWriteString(const wxString& key, const wxString& szValue);
|
||||
virtual bool DoWriteLong(const wxString& key, long lValue);
|
||||
|
||||
private:
|
||||
// no copy ctor/assignment operator
|
||||
wxRegConfig(const wxRegConfig&);
|
||||
|
@@ -100,6 +100,11 @@ bool MyApp::OnInit()
|
||||
|
||||
wxConfigBase *pConfig = wxConfigBase::Get();
|
||||
|
||||
// uncomment this to force writing back of the defaults for all values
|
||||
// if they're not present in the config - this can give the user an idea
|
||||
// of all possible settings for this program
|
||||
pConfig->SetRecordDefaults();
|
||||
|
||||
// or you could also write something like this:
|
||||
// wxFileConfig *pConfig = new wxFileConfig("conftest");
|
||||
// wxConfigBase::Set(pConfig);
|
||||
@@ -209,7 +214,7 @@ void MyFrame::OnQuit(wxCommandEvent&)
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent&)
|
||||
{
|
||||
wxMessageBox(_T("wxConfig demo\n<EFBFBD> Vadim Zeitlin 1998"), _T("About"),
|
||||
wxMessageBox(_T("wxConfig demo\n<EFBFBD> 1998-2001 Vadim Zeitlin"), _T("About"),
|
||||
wxICON_INFORMATION | wxOK);
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h> // for INT_MAX
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// global and class static variables
|
||||
@@ -99,36 +100,80 @@ wxConfigBase *wxConfigBase::Create()
|
||||
return ms_pConfig;
|
||||
}
|
||||
|
||||
wxString wxConfigBase::Read(const wxString& key, const wxString& defVal) const
|
||||
{
|
||||
wxString s;
|
||||
Read(key, &s, defVal);
|
||||
return s;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase reading entries
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, wxString *str, const wxString& defVal) const
|
||||
{
|
||||
if (!Read(key, str))
|
||||
{
|
||||
*str = ExpandEnvVars(defVal);
|
||||
return FALSE;
|
||||
// implement both Read() overloads for the given type in terms of DoRead()
|
||||
#define IMPLEMENT_READ_FOR_TYPE(name, type, deftype, extra) \
|
||||
bool wxConfigBase::Read(const wxString& key, type *val) const \
|
||||
{ \
|
||||
wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); \
|
||||
\
|
||||
return DoRead##name(key, val); \
|
||||
} \
|
||||
\
|
||||
bool wxConfigBase::Read(const wxString& key, \
|
||||
type *val, \
|
||||
deftype defVal) const \
|
||||
{ \
|
||||
wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); \
|
||||
\
|
||||
if ( DoRead##name(key, val) ) \
|
||||
return TRUE; \
|
||||
\
|
||||
if ( IsRecordingDefaults() ) \
|
||||
{ \
|
||||
((wxConfigBase *)this)->DoWrite##name(key, defVal); \
|
||||
} \
|
||||
\
|
||||
*val = extra(defVal); \
|
||||
\
|
||||
return FALSE; \
|
||||
}
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, long *pl, long defVal) const
|
||||
|
||||
IMPLEMENT_READ_FOR_TYPE(String, wxString, const wxString&, ExpandEnvVars)
|
||||
IMPLEMENT_READ_FOR_TYPE(Long, long, long, long)
|
||||
IMPLEMENT_READ_FOR_TYPE(Int, int, int, int)
|
||||
IMPLEMENT_READ_FOR_TYPE(Double, double, double, double)
|
||||
IMPLEMENT_READ_FOR_TYPE(Bool, bool, bool, bool)
|
||||
|
||||
#undef IMPLEMENT_READ_FOR_TYPE
|
||||
|
||||
// the DoReadXXX() for the other types have implementation in the base class
|
||||
// but can be overridden in the derived ones
|
||||
bool wxConfigBase::DoReadInt(const wxString& key, int *pi) const
|
||||
{
|
||||
if (!Read(key, pl))
|
||||
{
|
||||
*pl = defVal;
|
||||
wxCHECK_MSG( pi, FALSE, _T("wxConfig::Read(): NULL parameter") );
|
||||
|
||||
long l;
|
||||
if ( !DoReadLong(key, &l) )
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return TRUE;
|
||||
|
||||
wxASSERT_MSG( l < INT_MAX, _T("overflow in wxConfig::DoReadInt") );
|
||||
|
||||
*pi = (int)l;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, double* val) const
|
||||
bool wxConfigBase::DoReadBool(const wxString& key, bool* val) const
|
||||
{
|
||||
wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") );
|
||||
|
||||
long l;
|
||||
if ( !DoReadLong(key, &l) )
|
||||
return FALSE;
|
||||
|
||||
wxASSERT_MSG( l == 0 || l == 1, _T("bad bool value in wxConfig::DoReadInt") );
|
||||
|
||||
*val = l != 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoReadDouble(const wxString& key, double* val) const
|
||||
{
|
||||
wxString str;
|
||||
if ( Read(key, &str) )
|
||||
@@ -139,78 +184,7 @@ bool wxConfigBase::Read(const wxString& key, double* val) const
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, double* val, double defVal) const
|
||||
{
|
||||
if (!Read(key, val))
|
||||
{
|
||||
*val = defVal;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, bool* val) const
|
||||
{
|
||||
long l;
|
||||
if (Read(key, & l))
|
||||
{
|
||||
*val = (l != 0);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, bool* val, bool defVal) const
|
||||
{
|
||||
if (!Read(key, val))
|
||||
{
|
||||
*val = defVal;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Convenience functions
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, int *pi) const
|
||||
{
|
||||
long l;
|
||||
bool ret = Read(key, &l);
|
||||
if (ret)
|
||||
*pi = (int) l;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Read(const wxString& key, int *pi, int defVal) const
|
||||
{
|
||||
long l;
|
||||
bool ret = Read(key, &l, (long) defVal);
|
||||
if (ret)
|
||||
*pi = (int) l;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wxConfigBase::Write(const wxString& key, double val)
|
||||
{
|
||||
wxString str;
|
||||
str.Printf(wxT("%g"), val);
|
||||
return Write(key, str);
|
||||
}
|
||||
|
||||
bool wxConfigBase::Write(const wxString& key, bool value)
|
||||
{
|
||||
return Write(key, value ? 1l : 0l);
|
||||
}
|
||||
|
||||
bool wxConfigBase::Write(const wxString& key, const wxChar *value)
|
||||
{
|
||||
// explicit cast needed, otherwise value would have been converted to bool
|
||||
return Write(key, wxString(value));
|
||||
}
|
||||
|
||||
// string reading helper
|
||||
wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
|
||||
{
|
||||
wxString tmp; // Required for BC++
|
||||
@@ -221,6 +195,25 @@ wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigBase writing
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxConfigBase::DoWriteDouble(const wxString& key, double val)
|
||||
{
|
||||
return DoWriteString(key, wxString::Format(_T("%g"), val));
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoWriteInt(const wxString& key, int value)
|
||||
{
|
||||
return DoWriteLong(key, (long)value);
|
||||
}
|
||||
|
||||
bool wxConfigBase::DoWriteBool(const wxString& key, bool value)
|
||||
{
|
||||
return DoWriteLong(key, value ? 1l : 0l);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxConfigPathChanger
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -819,8 +819,7 @@ bool wxFileConfig::HasEntry(const wxString& strName) const
|
||||
// read/write values
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileConfig::Read(const wxString& key,
|
||||
wxString* pStr) const
|
||||
bool wxFileConfig::DoReadString(const wxString& key, wxString* pStr) const
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
@@ -829,32 +828,12 @@ bool wxFileConfig::Read(const wxString& key,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*pStr = ExpandEnvVars(pEntry->Value());
|
||||
*pStr = pEntry->Value();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxFileConfig::Read(const wxString& key,
|
||||
wxString* pStr, const wxString& defVal) const
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
wxFileConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
|
||||
bool ok;
|
||||
if (pEntry == NULL) {
|
||||
if( IsRecordingDefaults() )
|
||||
((wxFileConfig *)this)->Write(key,defVal);
|
||||
*pStr = ExpandEnvVars(defVal);
|
||||
ok = FALSE;
|
||||
}
|
||||
else {
|
||||
*pStr = ExpandEnvVars(pEntry->Value());
|
||||
ok = TRUE;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool wxFileConfig::Read(const wxString& key, long *pl) const
|
||||
bool wxFileConfig::DoReadLong(const wxString& key, long *pl) const
|
||||
{
|
||||
wxString str;
|
||||
if ( !Read(key, & str) )
|
||||
@@ -862,11 +841,10 @@ bool wxFileConfig::Read(const wxString& key, long *pl) const
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*pl = wxAtol(str);
|
||||
return TRUE;
|
||||
return str.ToLong(pl);
|
||||
}
|
||||
|
||||
bool wxFileConfig::Write(const wxString& key, const wxString& szValue)
|
||||
bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue)
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
@@ -901,12 +879,9 @@ bool wxFileConfig::Write(const wxString& key, const wxString& szValue)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxFileConfig::Write(const wxString& key, long lValue)
|
||||
bool wxFileConfig::DoWriteLong(const wxString& key, long lValue)
|
||||
{
|
||||
// ltoa() is not ANSI :-(
|
||||
wxString buf;
|
||||
buf.Printf(wxT("%ld"), lValue);
|
||||
return Write(key, buf);
|
||||
return Write(key, wxString::Format(_T("%ld"), lValue));
|
||||
}
|
||||
|
||||
bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||
|
@@ -282,7 +282,7 @@ bool wxIniConfig::IsEmpty() const
|
||||
// read/write
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const
|
||||
bool wxIniConfig::DoReadString(const wxString& szKey, wxString *pstr) const
|
||||
{
|
||||
wxConfigPathChanger path(this, szKey);
|
||||
wxString strKey = GetPrivateKeyName(path.Name());
|
||||
@@ -309,36 +309,7 @@ bool wxIniConfig::Read(const wxString& szKey, wxString *pstr) const
|
||||
}
|
||||
}
|
||||
|
||||
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr,
|
||||
const wxString& szDefault) const
|
||||
{
|
||||
wxConfigPathChanger path(this, szKey);
|
||||
wxString strKey = GetPrivateKeyName(path.Name());
|
||||
|
||||
char szBuf[1024]; // @@ should dynamically allocate memory...
|
||||
|
||||
// first look in the private INI file
|
||||
|
||||
// NB: the lpDefault param to GetPrivateProfileString can't be NULL
|
||||
GetPrivateProfileString(m_strGroup, strKey, "",
|
||||
szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
|
||||
if ( ::IsEmpty(szBuf) ) {
|
||||
// now look in win.ini
|
||||
wxString strKey = GetKeyName(path.Name());
|
||||
GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
|
||||
}
|
||||
|
||||
if ( ::IsEmpty(szBuf) ) {
|
||||
*pstr = szDefault;
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
*pstr = szBuf ;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxIniConfig::Read(const wxString& szKey, long *pl) const
|
||||
bool wxIniConfig::DoReadLong(const wxString& szKey, long *pl) const
|
||||
{
|
||||
wxConfigPathChanger path(this, szKey);
|
||||
wxString strKey = GetPrivateKeyName(path.Name());
|
||||
@@ -375,7 +346,7 @@ bool wxIniConfig::Read(const wxString& szKey, long *pl) const
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue)
|
||||
bool wxIniConfig::DoWriteString(const wxString& szKey, const wxString& szValue)
|
||||
{
|
||||
wxConfigPathChanger path(this, szKey);
|
||||
wxString strKey = GetPrivateKeyName(path.Name());
|
||||
@@ -389,7 +360,7 @@ bool wxIniConfig::Write(const wxString& szKey, const wxString& szValue)
|
||||
return bOk;
|
||||
}
|
||||
|
||||
bool wxIniConfig::Write(const wxString& szKey, long lValue)
|
||||
bool wxIniConfig::DoWriteLong(const wxString& szKey, long lValue)
|
||||
{
|
||||
// ltoa() is not ANSI :-(
|
||||
char szBuf[40]; // should be good for sizeof(long) <= 16 (128 bits)
|
||||
|
@@ -555,44 +555,10 @@ wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const
|
||||
// reading/writing
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxRegConfig::Read(const wxString& key, wxString *pStr) const
|
||||
bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
wxCHECK_MSG( pStr, FALSE, _T("wxRegConfig::Read(): NULL param") );
|
||||
|
||||
bool bQueryGlobal = TRUE;
|
||||
|
||||
// if immutable key exists in global key we must check that it's not
|
||||
// overriden by the local key with the same name
|
||||
if ( IsImmutable(path.Name()) ) {
|
||||
if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) {
|
||||
if ( m_keyLocal.Exists() && LocalKey().HasValue(path.Name()) ) {
|
||||
wxLogWarning(wxT("User value for immutable key '%s' ignored."),
|
||||
path.Name().c_str());
|
||||
}
|
||||
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
// don't waste time - it's not there anyhow
|
||||
bQueryGlobal = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// first try local key
|
||||
if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) ||
|
||||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
|
||||
// nothing to do
|
||||
|
||||
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxRegConfig::Read(const wxString& key, wxString *pStr,
|
||||
const wxString& szDefault) const
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
bool bQueryGlobal = TRUE;
|
||||
@@ -617,25 +583,19 @@ bool wxRegConfig::Read(const wxString& key, wxString *pStr,
|
||||
// first try local key
|
||||
if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) ||
|
||||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
|
||||
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
if ( IsRecordingDefaults() ) {
|
||||
((wxRegConfig*)this)->Write(key, szDefault);
|
||||
}
|
||||
|
||||
// default value
|
||||
*pStr = szDefault;
|
||||
}
|
||||
|
||||
*pStr = wxConfigBase::ExpandEnvVars(*pStr);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxRegConfig::Read(const wxString& key, long *plResult) const
|
||||
// this exactly reproduces the string version above except for ExpandEnvVars(),
|
||||
// we really should avoid this code duplication somehow...
|
||||
|
||||
bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const
|
||||
{
|
||||
wxCHECK_MSG( plResult, FALSE, _T("wxRegConfig::Read(): NULL param") );
|
||||
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
bool bQueryGlobal = TRUE;
|
||||
@@ -662,10 +622,11 @@ bool wxRegConfig::Read(const wxString& key, long *plResult) const
|
||||
(bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxRegConfig::Write(const wxString& key, const wxString& szValue)
|
||||
bool wxRegConfig::DoWriteString(const wxString& key, const wxString& szValue)
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
@@ -677,7 +638,7 @@ bool wxRegConfig::Write(const wxString& key, const wxString& szValue)
|
||||
return LocalKey().SetValue(path.Name(), szValue);
|
||||
}
|
||||
|
||||
bool wxRegConfig::Write(const wxString& key, long lValue)
|
||||
bool wxRegConfig::DoWriteLong(const wxString& key, long lValue)
|
||||
{
|
||||
wxConfigPathChanger path(this, key);
|
||||
|
||||
|
Reference in New Issue
Block a user